test: remplace InMemory par Testcontainers PostgreSQL
- 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)
This commit is contained in:
1 parent
e309611f80
commit
ee7894646f
13 files changed
+145
-66
No files matched your search
@@ -0,0 +1,31 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user