Files
Heimdall/tests/Heimdall.TestCommon/PostgreSqlContainerFixture.cs
T
Arnaud Dartois b167c2afcf fix: share one PostgreSQL Testcontainer across all test projects
Create Heimdall.TestCommon project with a single PostgreSqlContainerFixture
shared by both Infrastructure and Integration tests. This prevents Docker
resource conflicts from starting two PostgreSQL containers and ensures
both test suites connect to the same database instance.

- Move shared fixture to tests/Heimdall.TestCommon
- Remove duplicate fixtures from each test project
- Keep test isolation (truncation) and FK fix from previous commit
- Revert DATABASE_URL env var check (Testcontainers works in CI)
2026-07-21 18:48:39 +00:00

34 lines
959 B
C#

using Testcontainers.PostgreSql;
using Xunit;
namespace Heimdall.TestCommon;
/// <summary>
/// xUnit collection fixture that manages ONE PostgreSQL Testcontainer
/// for ALL database-dependent tests across test projects.
/// </summary>
public sealed class PostgreSqlContainerFixture : IAsyncLifetime
{
private readonly PostgreSqlContainer _container = new PostgreSqlBuilder("postgres:17-alpine")
.WithDatabase("heimdall_test")
.WithUsername("heimdall")
.WithPassword("heimdall_test_pwd")
.WithCleanUp(true)
.Build();
public string ConnectionString => _container.GetConnectionString();
public async Task InitializeAsync()
{
await _container.StartAsync();
}
public async Task DisposeAsync()
{
await _container.DisposeAsync();
}
}
// Collection definitions are in each test project assembly
// (xUnit requires [CollectionDefinition] in the same assembly as the test).