using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Extensions.Configuration; using Testcontainers.PostgreSql; namespace IdentityShroud.Core.Tests.Fixtures; public class ApplicationFactory : WebApplicationFactory, IAsyncLifetime { private readonly PostgreSqlContainer _postgresqlServer; // public IRealmService RealmService { get; } = Substitute.For(); public ApplicationFactory() { _postgresqlServer = new PostgreSqlBuilder("postgres:18.1") .WithName($"is-applicationFactory-{Guid.NewGuid():N}") .Build(); } protected override void ConfigureWebHost(IWebHostBuilder builder) { base.ConfigureWebHost(builder); builder.ConfigureAppConfiguration((context, configBuilder) => { configBuilder.AddInMemoryCollection( new Dictionary { ["Db:ConnectionString"] = _postgresqlServer.GetConnectionString(), ["Encryption:Master"] = "GVd07qW0frRX9quPX/X62L88BeRR7+IzgRJHtG7ZzHw=", }); }); // builder.ConfigureServices(services => // { // services.AddScoped(c => RealmService); // }); builder.UseEnvironment("Development"); } public async ValueTask InitializeAsync() { await _postgresqlServer.StartAsync(); } public override async ValueTask DisposeAsync() { await _postgresqlServer.StopAsync(); await base.DisposeAsync(); } }