Files
Heimdall/tests/Heimdall.IntegrationTests/Controllers/PostgresTestBase.cs
T

31 lines
1.0 KiB
C#
Raw Normal View History

using Heimdall.IntegrationTests.Factories;
namespace Heimdall.IntegrationTests.Controllers;
/// <summary>
/// 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.
/// </summary>
[Collection("Postgres")]
public abstract class PostgresTestBase : IAsyncLifetime
{
private readonly Lazy<HeimdallWebApplicationFactory> _factoryLazy;
protected PostgresTestBase(PostgreSqlContainerFixture postgres)
{
_factoryLazy = new Lazy<HeimdallWebApplicationFactory>(
() => new HeimdallWebApplicationFactory(postgres.ConnectionString));
}
/// <summary>HTTP client factory connected to the real PostgreSQL Testcontainer.</summary>
protected HeimdallWebApplicationFactory Factory => _factoryLazy.Value;
public Task InitializeAsync() => Task.CompletedTask;
public async Task DisposeAsync()
{
if (_factoryLazy.IsValueCreated)
await _factoryLazy.Value.DisposeAsync();
}
}