public class ApiFactory : WebApplicationFactory<Program>, IAsyncLifetime
{
private readonly RabbitMqTestContainer _rabbitMqTestContainer = new();
private readonly PostgreSqlTestContainer _postgreSqlTestContainer = new();
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.ConfigureAppConfiguration(config =>
{
var rabbitMqTestConfiguration = new Dictionary<string, string>
{
["RabbitMqConnectionOptions:HostName"] = _rabbitMqTestContainer.Hostname,
["RabbitMqConnectionOptions:Port"] = _rabbitMqTestContainer.HostPort.ToString(),
["RabbitMqConnectionOptions:UserName"] = RabbitMqTestContainer.UserName,
["RabbitMqConnectionOptions:Password"] = RabbitMqTestContainer.Password
};
config.AddInMemoryCollection(rabbitMqTestConfiguration!);
var postgreSqlTestConfiguration = new Dictionary<string, string>
{
["PostgreSqlConnectionOptions:Host"] = _postgreSqlTestContainer.Hostname,
["PostgreSqlConnectionOptions:Database"] = PostgreSqlTestContainer.Database,
["PostgreSqlConnectionOptions:Username"] = PostgreSqlTestContainer.Username,
["PostgreSqlConnectionOptions:Password"] = PostgreSqlTestContainer.Password,
["PostgreSqlConnectionOptions:Port"] = _postgreSqlTestContainer.HostPort.ToString()
};
config.AddInMemoryCollection(postgreSqlTestConfiguration!);
});
}
}