2026-02-08 18:00:24 +01:00
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
2026-02-15 19:06:09 +01:00
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Testcontainers.PostgreSql;
|
2026-02-08 18:00:24 +01:00
|
|
|
|
|
|
|
|
namespace IdentityShroud.Core.Tests.Fixtures;
|
|
|
|
|
|
2026-02-15 19:06:09 +01:00
|
|
|
public class ApplicationFactory : WebApplicationFactory<Program>, IAsyncLifetime
|
2026-02-08 18:00:24 +01:00
|
|
|
{
|
2026-02-15 19:06:09 +01:00
|
|
|
private readonly PostgreSqlContainer _postgresqlServer;
|
2026-02-08 18:00:24 +01:00
|
|
|
|
2026-02-15 19:06:09 +01:00
|
|
|
// public IRealmService RealmService { get; } = Substitute.For<IRealmService>();
|
|
|
|
|
|
|
|
|
|
public ApplicationFactory()
|
|
|
|
|
{
|
|
|
|
|
_postgresqlServer = new PostgreSqlBuilder("postgres:18.1")
|
|
|
|
|
.WithName($"is-applicationFactory-{Guid.NewGuid():N}")
|
|
|
|
|
.Build();
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-08 18:00:24 +01:00
|
|
|
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
base.ConfigureWebHost(builder);
|
|
|
|
|
|
2026-02-15 19:06:09 +01:00
|
|
|
builder.ConfigureAppConfiguration((context, configBuilder) =>
|
2026-02-08 18:00:24 +01:00
|
|
|
{
|
2026-02-15 19:06:09 +01:00
|
|
|
configBuilder.AddInMemoryCollection(
|
|
|
|
|
new Dictionary<string, string?>
|
|
|
|
|
{
|
|
|
|
|
["Db:ConnectionString"] = _postgresqlServer.GetConnectionString(),
|
2026-02-27 17:57:42 +00:00
|
|
|
["secrets:master:0:Id"] = "94970f27-3d88-4223-9940-7dd57548f5b5",
|
|
|
|
|
["secrets:master:0:Active"] = "true",
|
|
|
|
|
["secrets:master:0:Algorithm"] = "AES",
|
|
|
|
|
["secrets:master:0:Key"] = "GVd07qW0frRX9quPX/X62L88BeRR7+IzgRJHtG7ZzHw=",
|
2026-02-15 19:06:09 +01:00
|
|
|
});
|
2026-02-08 18:00:24 +01:00
|
|
|
});
|
|
|
|
|
|
2026-02-15 19:06:09 +01:00
|
|
|
// builder.ConfigureServices(services =>
|
|
|
|
|
// {
|
|
|
|
|
// services.AddScoped<IRealmService>(c => RealmService);
|
|
|
|
|
// });
|
|
|
|
|
|
2026-02-08 18:00:24 +01:00
|
|
|
builder.UseEnvironment("Development");
|
|
|
|
|
}
|
2026-02-15 19:06:09 +01:00
|
|
|
|
|
|
|
|
public async ValueTask InitializeAsync()
|
|
|
|
|
{
|
|
|
|
|
await _postgresqlServer.StartAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override async ValueTask DisposeAsync()
|
|
|
|
|
{
|
|
|
|
|
await _postgresqlServer.StopAsync();
|
|
|
|
|
await base.DisposeAsync();
|
|
|
|
|
}
|
2026-02-08 18:00:24 +01:00
|
|
|
}
|