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
24 changes: 20 additions & 4 deletions test/EFCore.Cosmos.FunctionalTests/ConfigPatternsCosmosTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ public class ConfigPatternsCosmosTest(ConfigPatternsCosmosTest.CosmosFixture fix
{
private const string DatabaseName = "ConfigPatternsCosmos";

private IServiceProvider _serviceProvider;

protected CosmosFixture Fixture { get; } = fixture;

[ConditionalFact]
public async Task Cosmos_client_instance_is_shared_between_contexts()
{
await using var testDatabase = await CosmosTestStore.CreateInitializedAsync(DatabaseName);
var options = CreateOptions(testDatabase);
var options = CreateOptions(testDatabase, useExternalServiceProvider: false);

CosmosClient client;
using (var context = new CustomerContext(options))
Expand All @@ -39,7 +41,8 @@ public async Task Cosmos_client_instance_is_shared_between_contexts()
}

await using var testDatabase2 = await CosmosTestStore.CreateInitializedAsync(DatabaseName, o => o.Region(Regions.AustraliaCentral));
options = CreateOptions(testDatabase2);

options = CreateOptions(testDatabase2, useExternalServiceProvider: false);

using (var context = new CustomerContext(options))
{
Expand Down Expand Up @@ -164,11 +167,20 @@ public async Task Cosmos_client_instance_is_thread_safe()
Assert.Single(uniqueClients); // Should only have one unique client instance
}

private DbContextOptions CreateOptions(CosmosTestStore testDatabase, Action<DbContextOptionsBuilder> configure = null)
private DbContextOptions CreateOptions(
CosmosTestStore testDatabase,
Action<DbContextOptionsBuilder> configure = null,
bool useExternalServiceProvider = true)
{
var builder = Fixture.AddOptions(testDatabase.AddProviderOptions(new DbContextOptionsBuilder()))
.ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))
.EnableDetailedErrors();

if (useExternalServiceProvider)
{
_serviceProvider ??= Fixture.CreateServiceProvider();
builder.UseInternalServiceProvider(_serviceProvider);
}
Comment thread
AndriySvyryd marked this conversation as resolved.

configure?.Invoke(builder);
return builder.Options;
}
Expand All @@ -191,6 +203,10 @@ public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder build
=> base.AddOptions(builder).ConfigureWarnings(w =>
w.Ignore(CosmosEventId.NoPartitionKeyDefined));

public IServiceProvider CreateServiceProvider()
=> AddServices(TestStoreFactory.AddProviderServices(new ServiceCollection()))
.BuildServiceProvider(validateScopes: true);
Comment thread
AndriySvyryd marked this conversation as resolved.

protected override ITestStoreFactory TestStoreFactory
=> CosmosTestStoreFactory.Instance;
}
Expand Down
9 changes: 6 additions & 3 deletions test/EFCore.Cosmos.FunctionalTests/EmbeddedDocumentsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -776,10 +776,13 @@ public async Task<EmbeddedTransportationContextOptions> CreateOptions(
Action<ModelBuilder> onModelCreating = null,
bool seed = true)
{
var options = CreateOptions(TestStore);
var embeddedOptions = new EmbeddedTransportationContextOptions(options, onModelCreating);
EmbeddedTransportationContextOptions embeddedOptions = null;

await TestStore.InitializeAsync(
ServiceProvider, () => new EmbeddedTransportationContext(embeddedOptions), async c =>
ServiceProvider,
() => new EmbeddedTransportationContext(
embeddedOptions ??= new EmbeddedTransportationContextOptions(CreateOptions(TestStore), onModelCreating)),
async c =>
{
if (seed)
{
Expand Down
Loading