- Ajoute Testcontainers.PostgreSql v4.13.0\n- PostgreSqlContainerFixture: collection fixture xUnit avec postgres:17-alpine\n- HeimdallWebApplicationFactory: accepte connectionString pour vrai PostgreSQL\n- PostgresTestBase: classe de base pour tous les tests integration\n- Ajoute [Collection("Postgres")] aux 9 classes de test\n- Database:MigrateOnStartup active quand PostgreSQL est utilise\n- Programme le Hangfire (skip en test via isTesting)\n\nAvant: InMemory (pas de contraintes, comportement different)\nApres: Vrai PostgreSQL dans un container temporaire\n\nTests: 226/226 passed (61 integration avec vrai PostgreSQL)
41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
using Testcontainers.PostgreSql;
|
|
|
|
namespace Heimdall.IntegrationTests.Factories;
|
|
|
|
/// <summary>
|
|
/// xUnit collection fixture that manages a PostgreSQL Testcontainer
|
|
/// for integration tests. One container per test collection (shared
|
|
/// across all test classes in the same collection).
|
|
/// </summary>
|
|
public class PostgreSqlContainerFixture : IAsyncLifetime
|
|
{
|
|
private readonly PostgreSqlContainer _container = new PostgreSqlBuilder("postgres:17-alpine")
|
|
.WithDatabase("heimdall_test")
|
|
.WithUsername("heimdall")
|
|
.WithPassword("heimdall_test_pwd")
|
|
.WithCleanUp(true)
|
|
.Build();
|
|
|
|
/// <summary>Connection string for the running PostgreSQL container.</summary>
|
|
public string ConnectionString => _container.GetConnectionString();
|
|
|
|
public async Task InitializeAsync()
|
|
{
|
|
await _container.StartAsync();
|
|
}
|
|
|
|
public async Task DisposeAsync()
|
|
{
|
|
await _container.DisposeAsync();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Defines the "Postgres" test collection. All test classes in this
|
|
/// collection share the same PostgreSQL container via the fixture.
|
|
/// </summary>
|
|
[CollectionDefinition("Postgres")]
|
|
public class PostgresCollectionFixture : ICollectionFixture<PostgreSqlContainerFixture>
|
|
{
|
|
}
|