Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ namespace Microsoft.EntityFrameworkCore;
[CosmosCondition(CosmosCondition.DoesNotUseTokenCredential)]
public class AdHocVectorSearchCosmosTest(NonSharedFixture fixture) : NonSharedModelTestBase(fixture), IClassFixture<NonSharedFixture>
{
protected override string StoreName
protected override string NonSharedStoreName
=> "AdHocVectorSearchTests";

protected override ITestStoreFactory TestStoreFactory
protected override ITestStoreFactory NonSharedTestStoreFactory
=> CosmosTestStoreFactory.Instance;

#region CompositeVectorIndex

[ConditionalFact]
public async Task Validate_composite_vector_index_throws()
{
var message = (await Assert.ThrowsAsync<InvalidOperationException>(() => InitializeAsync<ContextCompositeVectorIndex>())).Message;
var message = (await Assert.ThrowsAsync<InvalidOperationException>(() => InitializeNonSharedTest<ContextCompositeVectorIndex>())).Message;

Assert.Equal(
CosmosStrings.CompositeVectorIndex(
Expand Down Expand Up @@ -60,7 +60,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
public async Task Validate_vector_property_on_collection_navigation_container_creation()
{
var message =
(await Assert.ThrowsAsync<NotSupportedException>(() => InitializeAsync<ContextVectorPropertyOnCollectionNavigation>())).Message;
(await Assert.ThrowsAsync<NotSupportedException>(() => InitializeNonSharedTest<ContextVectorPropertyOnCollectionNavigation>())).Message;

Assert.Equal(
CosmosStrings.CreatingContainerWithFullTextOrVectorOnCollectionNotSupported("/Collection"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ namespace Microsoft.EntityFrameworkCore;
[CosmosCondition(CosmosCondition.DoesNotUseTokenCredential)]
public class AdHocFullTextSearchCosmosTest(NonSharedFixture fixture) : NonSharedModelTestBase(fixture), IClassFixture<NonSharedFixture>
{
protected override string StoreName
protected override string NonSharedStoreName
=> "AdHocFullTextSearchTests";

protected override ITestStoreFactory TestStoreFactory
protected override ITestStoreFactory NonSharedTestStoreFactory
=> CosmosTestStoreFactory.Instance;

#region CompositeFullTextIndex

[ConditionalFact]
public async Task Validate_composite_full_text_index_throws()
{
var message = (await Assert.ThrowsAsync<InvalidOperationException>(() => InitializeAsync<ContextCompositeFullTextIndex>())).Message;
var message = (await Assert.ThrowsAsync<InvalidOperationException>(() => InitializeNonSharedTest<ContextCompositeFullTextIndex>())).Message;

Assert.Equal(
CosmosStrings.CompositeFullTextIndex(
Expand Down Expand Up @@ -60,7 +60,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
public async Task Validate_full_text_property_on_collection_navigation_container_creation()
{
var message = (await Assert.ThrowsAsync<NotSupportedException>(()
=> InitializeAsync<ContextFullTextPropertyOnCollectionNavigation>())).Message;
=> InitializeNonSharedTest<ContextFullTextPropertyOnCollectionNavigation>())).Message;

Assert.Equal(
CosmosStrings.CreatingContainerWithFullTextOrVectorOnCollectionNotSupported("/Collection"),
Expand Down Expand Up @@ -104,7 +104,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
[ConditionalFact]
public async Task Validate_full_text_on_non_string_property()
{
var message = (await Assert.ThrowsAsync<InvalidOperationException>(() => InitializeAsync<ContextFullTextOnNonStringProperty>()))
var message = (await Assert.ThrowsAsync<InvalidOperationException>(() => InitializeNonSharedTest<ContextFullTextOnNonStringProperty>()))
.Message;

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

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

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

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

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

Assert.Equal(
CosmosStrings.FullTextIndexOnNonFullTextProperty(
Expand Down
36 changes: 18 additions & 18 deletions test/EFCore.Cosmos.FunctionalTests/CosmosSessionTokensTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -603,18 +603,18 @@ protected Test2Context()

public class CosmosNonSharedSessionTokenTests(NonSharedFixture fixture) : NonSharedModelTestBase(fixture), IClassFixture<NonSharedFixture>
{
protected override ITestStoreFactory TestStoreFactory
protected override ITestStoreFactory NonSharedTestStoreFactory
=> CosmosTestStoreFactory.Instance;

protected override string StoreName => nameof(CosmosSessionTokensTest);
protected override string NonSharedStoreName => nameof(CosmosSessionTokensTest);

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

[ConditionalFact]
public virtual async Task UseSessionTokens_uses_session_tokens()
{
var contextFactory = await InitializeAsync<CosmosSessionTokenContext>();
using var context = contextFactory.CreateContext();
var contextFactory = await InitializeNonSharedTest<CosmosSessionTokenContext>();
using var context = contextFactory.CreateDbContext();

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

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

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

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

using var newContext = contextFactory.CreateContext();
using var newContext = contextFactory.CreateDbContext();
Assert.NotSame(context, newContext);
Assert.Null(newContext.Database.GetSessionToken());
Assert.Equal("A", context.Database.GetSessionToken());
Expand All @@ -704,17 +704,17 @@ public virtual async Task New_context_does_not_use_same_SessionTokenStorage()
[ConditionalFact]
public virtual async Task Pooled_context_uses_same_SessionTokenStorage()
{
var contextFactory = await InitializeAsync<CosmosSessionTokenContext>();
var contextFactory = await InitializeNonSharedTest<CosmosSessionTokenContext>();
DbContext contextCopy;
ISessionTokenStorage sessionTokenStorageCopy;
using (var context = contextFactory.CreateContext())
using (var context = contextFactory.CreateDbContext())
{
contextCopy = context;
context.Database.UseSessionToken("A");
sessionTokenStorageCopy = ((CosmosDatabaseWrapper)context.GetService<IDatabase>()).SessionTokenStorage;
}

using var newContext = contextFactory.CreateContext();
using var newContext = contextFactory.CreateDbContext();

Assert.Same(newContext, contextCopy);
Assert.Same(sessionTokenStorageCopy, ((CosmosDatabaseWrapper)newContext.GetService<IDatabase>()).SessionTokenStorage);
Expand All @@ -724,17 +724,17 @@ public virtual async Task Pooled_context_uses_same_SessionTokenStorage()
[ConditionalFact]
public virtual async Task Pooled_context_clears_SessionTokenStorage()
{
var contextFactory = await InitializeAsync<CosmosSessionTokenContext>(addServices: services => services.Replace(ServiceDescriptor.Singleton<ISessionTokenStorageFactory, TestSessionTokenStorageFactory>()));
var contextFactory = await InitializeNonSharedTest<CosmosSessionTokenContext>(addServices: services => services.Replace(ServiceDescriptor.Singleton<ISessionTokenStorageFactory, TestSessionTokenStorageFactory>()));
DbContext contextCopy;
ISessionTokenStorage sessionTokenStorageCopy;
using (var context = contextFactory.CreateContext())
using (var context = contextFactory.CreateDbContext())
{
contextCopy = context;
sessionTokenStorageCopy = ((CosmosDatabaseWrapper)context.GetService<IDatabase>()).SessionTokenStorage;
_sessionTokenStorage.ClearCalled = false;
}

using var newContext = contextFactory.CreateContext();
using var newContext = contextFactory.CreateDbContext();

Assert.Same(newContext, contextCopy);
Assert.Same(sessionTokenStorageCopy, ((CosmosDatabaseWrapper)newContext.GetService<IDatabase>()).SessionTokenStorage);
Expand Down
12 changes: 6 additions & 6 deletions test/EFCore.Cosmos.FunctionalTests/CosmosTriggersTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ namespace Microsoft.EntityFrameworkCore;

public class CosmosTriggersTest(NonSharedFixture fixture) : NonSharedModelTestBase(fixture), IClassFixture<NonSharedFixture>
{
protected override string StoreName
protected override string NonSharedStoreName
=> "CosmosTriggersTest";

protected override ITestStoreFactory TestStoreFactory
protected override ITestStoreFactory NonSharedTestStoreFactory
=> CosmosTestStoreFactory.Instance;

[ConditionalFact]
public async Task Triggers_are_executed_on_SaveChanges()
{
var contextFactory = await InitializeAsync<TriggersContext>(shouldLogCategory: _ => true);
var contextFactory = await InitializeNonSharedTest<TriggersContext>(shouldLogCategory: _ => true);

using (var context = contextFactory.CreateContext())
using (var context = contextFactory.CreateDbContext())
{
await CreateTriggersInCosmosAsync(context);

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

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

using (var context = contextFactory.CreateContext())
using (var context = contextFactory.CreateDbContext())
{
var product = await context.Products.SingleAsync();
context.Products.Remove(product);
Expand Down
Loading
Loading