TESTCONTAINERS_IMPLEMENTATION.md
Successfully migrated functional tests from in-memory database to Testcontainers with SQL Server 2022. This provides a more realistic testing environment that matches production database behavior.
Added to Directory.Packages.props:
<PackageVersion Include="Testcontainers" Version="4.3.0" />
<PackageVersion Include="Testcontainers.MsSql" Version="4.3.0" />
Updated tests\Clean.Architecture.FunctionalTests\Clean.Architecture.FunctionalTests.csproj:
Microsoft.EntityFrameworkCore.InMemoryTestcontainers and Testcontainers.MsSqlFile: tests\Clean.Architecture.FunctionalTests\CustomWebApplicationFactory.cs
Key changes:
IAsyncLifetime for proper async initialization/cleanupMsSqlBuildermcr.microsoft.com/mssql/server:2022-latestEnsureCreated()private readonly MsSqlContainer _dbContainer = new MsSqlBuilder()
.WithImage("mcr.microsoft.com/mssql/server:2022-latest")
.WithPassword("Your_password123!")
.Build();
Tests now:
? Realistic Testing: Tests run against actual SQL Server, not in-memory provider
? Migration Testing: Validates that migrations work correctly
? Production Parity: Database behavior matches production environment
? Isolation: Each test class gets its own containerized database
? Automatic Cleanup: Containers are disposed after tests complete
All 18 tests passing:
Run tests normally:
dotnet test
Or specifically for functional tests:
dotnet test tests\Clean.Architecture.FunctionalTests\Clean.Architecture.FunctionalTests.csproj
Your_password123! (only for test containers)IAsyncLifetime