-
-
Notifications
You must be signed in to change notification settings - Fork 108
Closed
Description
Problem Description
Starting from version 1.5.6, the "Complex Test Infrastructure Orchestration" sample no longer works due to the database container not being initialized before calling ConfigureWebHost.
Code Example
public class InMemoryPostgreSqlDatabase : IAsyncInitializer, IAsyncDisposable
{
public readonly PostgreSqlContainer Container = new PostgreSqlBuilder()
.WithUsername("User")
.WithPassword("Password")
.WithDatabase("TestDatabase")
.Build();
public async Task InitializeAsync() => await Container.StartAsync();
public async ValueTask DisposeAsync() => await Container.DisposeAsync();
}
public class WebApplicationFactory : WebApplicationFactory<Program>, IAsyncInitializer
{
[ClassDataSource<InMemoryPostgreSqlDatabase>(Shared = SharedType.PerTestSession)]
public required InMemoryPostgreSqlDatabase PostgreSql { get; init; }
public Task InitializeAsync()
{
_ = Server;
return Task.CompletedTask;
}
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.ConfigureAppConfiguration((context, configBuilder) =>
{
configBuilder.AddInMemoryCollection(new Dictionary<string, string?>
{
{ "PostgreSql:ConnectionString", PostgreSql.Container.GetConnectionString() },
});
});
}
}Copilot
Metadata
Metadata
Assignees
Labels
No labels