using Heimdall.IntegrationTests.Factories;
namespace Heimdall.IntegrationTests.Controllers;
///
/// Base class for integration tests that need a real PostgreSQL database
/// via Testcontainers. All test classes in the "Postgres" collection share
/// the same PostgreSQL container.
///
[Collection("Postgres")]
public abstract class PostgresTestBase : IAsyncLifetime
{
private readonly Lazy _factoryLazy;
protected PostgresTestBase(PostgreSqlContainerFixture postgres)
{
_factoryLazy = new Lazy(
() => new HeimdallWebApplicationFactory(postgres.ConnectionString));
}
/// HTTP client factory connected to the real PostgreSQL Testcontainer.
protected HeimdallWebApplicationFactory Factory => _factoryLazy.Value;
public Task InitializeAsync() => Task.CompletedTask;
public async Task DisposeAsync()
{
if (_factoryLazy.IsValueCreated)
await _factoryLazy.Value.DisposeAsync();
}
}