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)
34 lines
959 B
C#
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).
|