Skip to content

Commit a70e66f

Browse files
committed
Make QueryTestBase extend NonSharedModelTestBase
1 parent ff4e452 commit a70e66f

113 files changed

Lines changed: 1024 additions & 1078 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

test/EFCore.Cosmos.FunctionalTests/AdHocVectorSearchCosmosTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ namespace Microsoft.EntityFrameworkCore;
99
[CosmosCondition(CosmosCondition.DoesNotUseTokenCredential)]
1010
public class AdHocVectorSearchCosmosTest(NonSharedFixture fixture) : NonSharedModelTestBase(fixture), IClassFixture<NonSharedFixture>
1111
{
12-
protected override string StoreName
12+
protected override string NonSharedStoreName
1313
=> "AdHocVectorSearchTests";
1414

15-
protected override ITestStoreFactory TestStoreFactory
15+
protected override ITestStoreFactory NonSharedTestStoreFactory
1616
=> CosmosTestStoreFactory.Instance;
1717

1818
#region CompositeVectorIndex
1919

2020
[ConditionalFact]
2121
public async Task Validate_composite_vector_index_throws()
2222
{
23-
var message = (await Assert.ThrowsAsync<InvalidOperationException>(() => InitializeAsync<ContextCompositeVectorIndex>())).Message;
23+
var message = (await Assert.ThrowsAsync<InvalidOperationException>(() => InitializeNonSharedTest<ContextCompositeVectorIndex>())).Message;
2424

2525
Assert.Equal(
2626
CosmosStrings.CompositeVectorIndex(
@@ -60,7 +60,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
6060
public async Task Validate_vector_property_on_collection_navigation_container_creation()
6161
{
6262
var message =
63-
(await Assert.ThrowsAsync<NotSupportedException>(() => InitializeAsync<ContextVectorPropertyOnCollectionNavigation>())).Message;
63+
(await Assert.ThrowsAsync<NotSupportedException>(() => InitializeNonSharedTest<ContextVectorPropertyOnCollectionNavigation>())).Message;
6464

6565
Assert.Equal(
6666
CosmosStrings.CreatingContainerWithFullTextOrVectorOnCollectionNotSupported("/Collection"),

test/EFCore.Cosmos.FunctionalTests/AddHocFullTextSearchCosmosTest.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ namespace Microsoft.EntityFrameworkCore;
99
[CosmosCondition(CosmosCondition.DoesNotUseTokenCredential)]
1010
public class AdHocFullTextSearchCosmosTest(NonSharedFixture fixture) : NonSharedModelTestBase(fixture), IClassFixture<NonSharedFixture>
1111
{
12-
protected override string StoreName
12+
protected override string NonSharedStoreName
1313
=> "AdHocFullTextSearchTests";
1414

15-
protected override ITestStoreFactory TestStoreFactory
15+
protected override ITestStoreFactory NonSharedTestStoreFactory
1616
=> CosmosTestStoreFactory.Instance;
1717

1818
#region CompositeFullTextIndex
1919

2020
[ConditionalFact]
2121
public async Task Validate_composite_full_text_index_throws()
2222
{
23-
var message = (await Assert.ThrowsAsync<InvalidOperationException>(() => InitializeAsync<ContextCompositeFullTextIndex>())).Message;
23+
var message = (await Assert.ThrowsAsync<InvalidOperationException>(() => InitializeNonSharedTest<ContextCompositeFullTextIndex>())).Message;
2424

2525
Assert.Equal(
2626
CosmosStrings.CompositeFullTextIndex(
@@ -60,7 +60,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
6060
public async Task Validate_full_text_property_on_collection_navigation_container_creation()
6161
{
6262
var message = (await Assert.ThrowsAsync<NotSupportedException>(()
63-
=> InitializeAsync<ContextFullTextPropertyOnCollectionNavigation>())).Message;
63+
=> InitializeNonSharedTest<ContextFullTextPropertyOnCollectionNavigation>())).Message;
6464

6565
Assert.Equal(
6666
CosmosStrings.CreatingContainerWithFullTextOrVectorOnCollectionNotSupported("/Collection"),
@@ -104,7 +104,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
104104
[ConditionalFact]
105105
public async Task Validate_full_text_on_non_string_property()
106106
{
107-
var message = (await Assert.ThrowsAsync<InvalidOperationException>(() => InitializeAsync<ContextFullTextOnNonStringProperty>()))
107+
var message = (await Assert.ThrowsAsync<InvalidOperationException>(() => InitializeNonSharedTest<ContextFullTextOnNonStringProperty>()))
108108
.Message;
109109

110110
Assert.Equal(
@@ -143,7 +143,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
143143
[ConditionalFact]
144144
public async Task Set_unsupported_full_text_search_default_language()
145145
{
146-
var exception = (await Assert.ThrowsAsync<CosmosException>(() => InitializeAsync<ContextSettingDefaultFullTextSearchLanguage>()));
146+
var exception = (await Assert.ThrowsAsync<CosmosException>(() => InitializeNonSharedTest<ContextSettingDefaultFullTextSearchLanguage>()));
147147

148148
Assert.Contains("The Full Text Policy contains an unsupported language xx-YY.", exception.Message);
149149
}
@@ -229,7 +229,7 @@ public async Task
229229
{
230230
var exception =
231231
(await Assert.ThrowsAsync<CosmosException>(()
232-
=> InitializeAsync<ContextDefaultFullTextSearchLanguageNoMismatchWhenNotSpecified>()));
232+
=> InitializeNonSharedTest<ContextDefaultFullTextSearchLanguageNoMismatchWhenNotSpecified>()));
233233

234234
Assert.Contains("The Full Text Policy contains an unsupported language xx-YY.", exception.Message);
235235
}
@@ -301,7 +301,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
301301
public async Task Default_full_text_language_is_used_for_full_text_properties_if_they_dont_specify_language_themselves()
302302
{
303303
var exception = (await Assert.ThrowsAsync<CosmosException>(()
304-
=> InitializeAsync<ContextDefaultFullTextSearchLanguageUsedWhenPropertyDoesntSpecifyOneExplicitly>()));
304+
=> InitializeNonSharedTest<ContextDefaultFullTextSearchLanguageUsedWhenPropertyDoesntSpecifyOneExplicitly>()));
305305

306306
Assert.Contains("The Full Text Policy contains an unsupported language xx-YY.", exception.Message);
307307
}
@@ -340,7 +340,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
340340
public async Task Explicitly_setting_full_text_language_overrides_default()
341341
{
342342
var exception =
343-
(await Assert.ThrowsAsync<CosmosException>(() => InitializeAsync<ContextExplicitFullTextLanguageOverridesTheDefault>()));
343+
await Assert.ThrowsAsync<CosmosException>(() => InitializeNonSharedTest<ContextExplicitFullTextLanguageOverridesTheDefault>());
344344

345345
Assert.Contains("The Full Text Policy contains an unsupported language xx-YY.", exception.Message);
346346
}
@@ -377,7 +377,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
377377
[ConditionalFact]
378378
public async Task Enable_full_text_search_for_property_then_disable_it()
379379
{
380-
var message = (await Assert.ThrowsAsync<InvalidOperationException>(() => InitializeAsync<ContextEnableThenDisable>())).Message;
380+
var message = (await Assert.ThrowsAsync<InvalidOperationException>(() => InitializeNonSharedTest<ContextEnableThenDisable>())).Message;
381381

382382
Assert.Equal(
383383
CosmosStrings.FullTextIndexOnNonFullTextProperty(

test/EFCore.Cosmos.FunctionalTests/CosmosSessionTokensTest.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -603,18 +603,18 @@ protected Test2Context()
603603

604604
public class CosmosNonSharedSessionTokenTests(NonSharedFixture fixture) : NonSharedModelTestBase(fixture), IClassFixture<NonSharedFixture>
605605
{
606-
protected override ITestStoreFactory TestStoreFactory
606+
protected override ITestStoreFactory NonSharedTestStoreFactory
607607
=> CosmosTestStoreFactory.Instance;
608608

609-
protected override string StoreName => nameof(CosmosSessionTokensTest);
609+
protected override string NonSharedStoreName => nameof(CosmosSessionTokensTest);
610610

611-
protected override TestStore CreateTestStore() => CosmosTestStore.Create(StoreName, (cfg) => cfg.SessionTokenManagementMode(Cosmos.Infrastructure.SessionTokenManagementMode.SemiAutomatic));
611+
protected override TestStore CreateTestStore() => CosmosTestStore.Create(NonSharedStoreName, (cfg) => cfg.SessionTokenManagementMode(Cosmos.Infrastructure.SessionTokenManagementMode.SemiAutomatic));
612612

613613
[ConditionalFact]
614614
public virtual async Task UseSessionTokens_uses_session_tokens()
615615
{
616-
var contextFactory = await InitializeAsync<CosmosSessionTokenContext>();
617-
using var context = contextFactory.CreateContext();
616+
var contextFactory = await InitializeNonSharedTest<CosmosSessionTokenContext>();
617+
using var context = contextFactory.CreateDbContext();
618618

619619
context.Customers.Add(new Customer { Id = "1", PartitionKey = "1" });
620620
context.OtherContainerCustomers.Add(new OtherContainerCustomer { Id = "1", PartitionKey = "1" });
@@ -646,8 +646,8 @@ await Assert.ThrowsAsync<CosmosException>(() => context.OtherContainerCustomers.
646646
[ConditionalFact]
647647
public virtual async Task ReadItem_does_not_exist_returns_null()
648648
{
649-
var contextFactory = await InitializeAsync<CosmosSessionTokenContext>();
650-
using var context = contextFactory.CreateContext();
649+
var contextFactory = await InitializeNonSharedTest<CosmosSessionTokenContext>();
650+
using var context = contextFactory.CreateDbContext();
651651

652652
var result = await context.Customers.FirstOrDefaultAsync(x => x.Id == "nonexistent" && x.PartitionKey == "nonexistent");
653653

@@ -657,8 +657,8 @@ public virtual async Task ReadItem_does_not_exist_returns_null()
657657
[ConditionalFact]
658658
public virtual async Task Read_item_session_not_found_throws_CosmosException()
659659
{
660-
var contextFactory = await InitializeAsync<CosmosSessionTokenContext>();
661-
using var context = contextFactory.CreateContext();
660+
var contextFactory = await InitializeNonSharedTest<CosmosSessionTokenContext>();
661+
using var context = contextFactory.CreateDbContext();
662662

663663
context.Customers.Add(new Customer { Id = "1", PartitionKey = "1" });
664664
context.OtherContainerCustomers.Add(new OtherContainerCustomer { Id = "1", PartitionKey = "1" });
@@ -690,11 +690,11 @@ await Assert.ThrowsAsync<CosmosException>(() => context.OtherContainerCustomers.
690690
[ConditionalFact]
691691
public virtual async Task New_context_does_not_use_same_SessionTokenStorage()
692692
{
693-
var contextFactory = await InitializeAsync<CosmosSessionTokenContext>();
694-
using var context = contextFactory.CreateContext();
693+
var contextFactory = await InitializeNonSharedTest<CosmosSessionTokenContext>();
694+
using var context = contextFactory.CreateDbContext();
695695
context.Database.UseSessionToken("A");
696696

697-
using var newContext = contextFactory.CreateContext();
697+
using var newContext = contextFactory.CreateDbContext();
698698
Assert.NotSame(context, newContext);
699699
Assert.Null(newContext.Database.GetSessionToken());
700700
Assert.Equal("A", context.Database.GetSessionToken());
@@ -704,17 +704,17 @@ public virtual async Task New_context_does_not_use_same_SessionTokenStorage()
704704
[ConditionalFact]
705705
public virtual async Task Pooled_context_uses_same_SessionTokenStorage()
706706
{
707-
var contextFactory = await InitializeAsync<CosmosSessionTokenContext>();
707+
var contextFactory = await InitializeNonSharedTest<CosmosSessionTokenContext>();
708708
DbContext contextCopy;
709709
ISessionTokenStorage sessionTokenStorageCopy;
710-
using (var context = contextFactory.CreateContext())
710+
using (var context = contextFactory.CreateDbContext())
711711
{
712712
contextCopy = context;
713713
context.Database.UseSessionToken("A");
714714
sessionTokenStorageCopy = ((CosmosDatabaseWrapper)context.GetService<IDatabase>()).SessionTokenStorage;
715715
}
716716

717-
using var newContext = contextFactory.CreateContext();
717+
using var newContext = contextFactory.CreateDbContext();
718718

719719
Assert.Same(newContext, contextCopy);
720720
Assert.Same(sessionTokenStorageCopy, ((CosmosDatabaseWrapper)newContext.GetService<IDatabase>()).SessionTokenStorage);
@@ -724,17 +724,17 @@ public virtual async Task Pooled_context_uses_same_SessionTokenStorage()
724724
[ConditionalFact]
725725
public virtual async Task Pooled_context_clears_SessionTokenStorage()
726726
{
727-
var contextFactory = await InitializeAsync<CosmosSessionTokenContext>(addServices: services => services.Replace(ServiceDescriptor.Singleton<ISessionTokenStorageFactory, TestSessionTokenStorageFactory>()));
727+
var contextFactory = await InitializeNonSharedTest<CosmosSessionTokenContext>(addServices: services => services.Replace(ServiceDescriptor.Singleton<ISessionTokenStorageFactory, TestSessionTokenStorageFactory>()));
728728
DbContext contextCopy;
729729
ISessionTokenStorage sessionTokenStorageCopy;
730-
using (var context = contextFactory.CreateContext())
730+
using (var context = contextFactory.CreateDbContext())
731731
{
732732
contextCopy = context;
733733
sessionTokenStorageCopy = ((CosmosDatabaseWrapper)context.GetService<IDatabase>()).SessionTokenStorage;
734734
_sessionTokenStorage.ClearCalled = false;
735735
}
736736

737-
using var newContext = contextFactory.CreateContext();
737+
using var newContext = contextFactory.CreateDbContext();
738738

739739
Assert.Same(newContext, contextCopy);
740740
Assert.Same(sessionTokenStorageCopy, ((CosmosDatabaseWrapper)newContext.GetService<IDatabase>()).SessionTokenStorage);

test/EFCore.Cosmos.FunctionalTests/CosmosTriggersTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ namespace Microsoft.EntityFrameworkCore;
99

1010
public class CosmosTriggersTest(NonSharedFixture fixture) : NonSharedModelTestBase(fixture), IClassFixture<NonSharedFixture>
1111
{
12-
protected override string StoreName
12+
protected override string NonSharedStoreName
1313
=> "CosmosTriggersTest";
1414

15-
protected override ITestStoreFactory TestStoreFactory
15+
protected override ITestStoreFactory NonSharedTestStoreFactory
1616
=> CosmosTestStoreFactory.Instance;
1717

1818
[ConditionalFact]
1919
public async Task Triggers_are_executed_on_SaveChanges()
2020
{
21-
var contextFactory = await InitializeAsync<TriggersContext>(shouldLogCategory: _ => true);
21+
var contextFactory = await InitializeNonSharedTest<TriggersContext>(shouldLogCategory: _ => true);
2222

23-
using (var context = contextFactory.CreateContext())
23+
using (var context = contextFactory.CreateDbContext())
2424
{
2525
await CreateTriggersInCosmosAsync(context);
2626

@@ -41,7 +41,7 @@ public async Task Triggers_are_executed_on_SaveChanges()
4141
Assert.Contains(logs, l => l.TriggerName == "PreInsertTrigger" && l.Operation == "INSERT");
4242
}
4343

44-
using (var context = contextFactory.CreateContext())
44+
using (var context = contextFactory.CreateDbContext())
4545
{
4646
var product = await context.Products.SingleAsync();
4747
product.Name = "Updated Product";
@@ -53,7 +53,7 @@ public async Task Triggers_are_executed_on_SaveChanges()
5353
Assert.Contains(logs, l => l.TriggerName == "UpdateTrigger" && l.Operation == "UPDATE");
5454
}
5555

56-
using (var context = contextFactory.CreateContext())
56+
using (var context = contextFactory.CreateDbContext())
5757
{
5858
var product = await context.Products.SingleAsync();
5959
context.Products.Remove(product);

0 commit comments

Comments
 (0)