- 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)
32 lines
1.0 KiB
C#
32 lines
1.0 KiB
C#
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();
|
|
}
|
|
}
|