Database Integration Tests
Generate integration tests using Testcontainers for real database validation.
For .NET (Testcontainers)
dotnet add package Testcontainers.CosmosDb
public class CandidateRepositoryTests : IAsyncLifetime
{
private readonly CosmosDbContainer _container = new CosmosDbBuilder().Build();
public async Task InitializeAsync() => await _container.StartAsync();
public async Task DisposeAsync() => await _container.DisposeAsync();
[Fact]
public async Task Create_ValidCandidate_Persists()
{
var client = new CosmosClient(_container.GetConnectionString());
var repo = new CandidateRepository(client, Options.Create(settings));
var candidate = CreateTestCandidate();
await repo.CreateAsync(candidate);
var result = await repo.GetByIdAsync(candidate.Id);
result.Should().BeEquivalentTo(candidate);
}
}
Arguments
<repository-name>: Repository class to test--provider=<cosmosdb|postgres|mongodb>: Database provider