Encina uses Docker containers for integration testing against real database engines. This ensures high-quality, production-like testing without requiring local database installations.
- Docker Desktop installed and running
- .NET 10 SDK
- Approximately 5 GB disk space for database images
dotnet run --file .github/scripts/run-integration-tests.csThis command will:
- Start SQL Server, PostgreSQL, and MySQL containers
- Wait for databases to become healthy
- Execute all integration tests
- Stop containers upon completion
# SQL Server only
dotnet run --file .github/scripts/run-integration-tests.cs -- --database sqlserver
# PostgreSQL only
dotnet run --file .github/scripts/run-integration-tests.cs -- --database postgres
# MySQL only
dotnet run --file .github/scripts/run-integration-tests.cs -- --database mysqlFor faster iteration during development:
# Start core services (PostgreSQL, Redis, RabbitMQ)
docker compose --profile core up -d
# Start all databases
docker compose --profile databases up -d
# Start databases + messaging
docker compose --profile databases --profile messaging up -d
# Start everything
docker compose --profile full up -d
# Run tests against running containers
dotnet run --file .github/scripts/run-integration-tests.cs -- --skip-docker
# Stop databases
docker compose --profile databases down
# Clean slate (remove volumes)
docker compose --profile full down -vAvailable Profiles:
core,databases,messaging,caching,cloud,observability,fullSee Docker Infrastructure Guide for complete details.
Connection strings are defined in tests/appsettings.Testing.json:
| Database | Host | Port | User | Password |
|---|---|---|---|---|
| SQL Server | localhost | 1433 | sa | Encina123! |
| PostgreSQL | localhost | 5432 | Encina | Encina123! |
| MySQL | localhost | 3306 | Encina | Encina123! |
| Database | Image | Startup Time |
|---|---|---|
| SQL Server | mcr.microsoft.com/mssql/server:2022-latest |
~15 seconds |
| PostgreSQL | postgres:16-alpine |
~5 seconds |
| MySQL | mysql:8.4 |
~10 seconds |
| MongoDB | mongo:7 |
~5 seconds |
| Broker | Image | Startup Time |
|---|---|---|
| RabbitMQ | rabbitmq:3-management-alpine |
~10 seconds |
| Kafka | apache/kafka:3.7.0 |
~30 seconds |
| NATS | nats:2-alpine |
~2 seconds |
| Mosquitto | eclipse-mosquitto:2 |
~2 seconds |
| Cache | Image | Startup Time |
|---|---|---|
| Redis | redis:7-alpine |
~2 seconds |
| Garnet | ghcr.io/microsoft/garnet:latest |
~3 seconds |
| Valkey | valkey/valkey:8-alpine |
~2 seconds |
| Dragonfly | docker.dragonflydb.io/dragonflydb/dragonfly:latest |
~3 seconds |
| KeyDB | eqalpha/keydb:latest |
~3 seconds |
| Service | Image | Startup Time |
|---|---|---|
| LocalStack | localstack/localstack:latest |
~30 seconds |
| Azurite | mcr.microsoft.com/azure-storage/azurite:3.37.0 |
~5 seconds |
The Azure Service Bus emulator and its SQL Server sidecar are listed, with their terms, in the next section.
This section is for contributors who run the Azure emulator integration tests and want to know which terms they accept and why the images are pinned.
Encina's cloud features are tested only locally, against emulators, never against the real cloud. Using those features in production is your responsibility.
| Emulator | Fixture and collection | Image | Terms |
|---|---|---|---|
| Azure Service Bus emulator | ServiceBusEmulatorFixture in tests/Encina.TestInfrastructure/Fixtures/ServiceBusEmulatorFixture.cs, collection Cloud-ServiceBusEmulator |
mcr.microsoft.com/azure-messaging/servicebus-emulator:2.0.1 |
Microsoft Azure Service Bus Emulator Software License Terms |
| SQL Server (sidecar of the Service Bus emulator) | started by ServiceBusEmulatorFixture |
mcr.microsoft.com/mssql/server:2022-CU14-ubuntu-22.04 |
SQL Server Developer edition |
| Azurite | AzuriteFixture in tests/Encina.TestInfrastructure/Fixtures/AzuriteFixture.cs, collection Cloud-Azurite |
mcr.microsoft.com/azure-storage/azurite:3.37.0 |
MIT licence, Copyright (c) Microsoft Corporation |
Pinned tags keep the tests reproducible; none of these fixtures uses a :latest tag.
- Service Bus emulator licence. Running the Service Bus emulator tests accepts the Microsoft terms linked in the table: development and testing use only, not production, and no reverse engineering or redistribution. The fixture accepts them explicitly with
WithAcceptLicenseAgreement(true)(issue #2699). - SQL Server Developer edition. The emulator needs a SQL Server container, which runs with
ACCEPT_EULA=Y(set by theTestcontainers.MsSqlbuilder) andMSSQL_PID=Developer(set explicitly by the fixture). Developer edition is free for non-production use only. Read the SQL Server terms, the Docker Hub page and the environment variable documentation. - Azurite flag. Azurite starts with
--skipApiVersionCheckbecause the Azure Storage SDKs request a newer API version than Azurite implements. - Known limitation.
servicebus-emulator2.0.1 acceptsCancelScheduledMessagebut still delivers the message, so that integration test is skipped. Issue #2967 tracks re-enabling the test once the emulator honours the cancel.
Without shared fixtures, each test class creates its own Docker container instance. With many database integration test classes running in parallel, this means dozens of simultaneous containers, causing:
- Docker resource exhaustion (
io_setup() failed with EAGAIN) TimeoutExceptionduring container startup- SQL Server login failures under heavy parallel load
- Intermittent test failures that pass when run in isolation
xUnit [CollectionDefinition] + ICollectionFixture<T> shares ONE fixture instance (and thus one Docker container) across ALL test classes in the same collection.
Collections are defined in Collections.cs files at the root of each provider directory:
| File | Collections Defined |
|---|---|
tests/Encina.IntegrationTests/ADO/Collections.cs |
ADO-SqlServer, ADO-PostgreSQL, ADO-MySQL |
tests/Encina.IntegrationTests/Dapper/Collections.cs |
Dapper-SqlServer, Dapper-PostgreSQL, Dapper-MySQL |
tests/Encina.IntegrationTests/Infrastructure/EntityFrameworkCore/Collections.cs |
EFCore-SqlServer, EFCore-PostgreSQL, EFCore-MySQL |
| Database | ADO | Dapper | EFCore | Other | Total |
|---|---|---|---|---|---|
| SqlServer | 1 | 1 | 1 | 2 (Concurrency) | 5 |
| PostgreSQL | 1 | 1 | 1 | 1 (Marten) | 4 |
| MySQL | 1 | 1 | 1 | - | 3 |
| MongoDB | - | - | - | 2 | 2 |
| Redis | - | - | - | 1 | 1 |
| Messaging | - | - | - | ~5 | ~5 |
| Total | 3 | 3 | 3 | ~11 | ~20-23 |
Step 1: Choose the correct collection for your provider + database combination.
Step 2: Add [Collection("...")] and inject the fixture via constructor.
Step 3: Use IAsyncLifetime for per-test setup/teardown.
[Collection("ADO-PostgreSQL")] // Shares the PostgreSQL container with all other ADO PostgreSQL tests
[Trait("Category", "Integration")]
[Trait("Database", "PostgreSQL")]
public class MyNewStoreTests : IAsyncLifetime
{
private readonly PostgreSqlFixture _fixture;
private MyStore _store = null!;
public MyNewStoreTests(PostgreSqlFixture fixture)
{
_fixture = fixture;
}
public async Task InitializeAsync()
{
// Clean data from previous test class (shared fixture = shared DB)
await _fixture.ClearAllDataAsync();
// Create your store using the fixture's connection
_store = new MyStore(_fixture.CreateConnection());
}
public Task DisposeAsync() => Task.CompletedTask;
[Fact]
public async Task MyTest()
{
// Use _store...
}
}-
Always use
[Collection]: Never useIClassFixture<T>ornew()for database fixtures. The collection manages the fixture lifecycle. -
Never dispose the fixture: Do not call
_fixture.DisposeAsync()from tests. The xUnit collection runner calls it once after ALL test classes in the collection have finished. -
Clean data, not schema: Use
_fixture.ClearAllDataAsync()inInitializeAsync()to remove data from previous tests. The schema (tables) persists for the lifetime of the collection. -
Use the correct traits: Always include both
[Trait("Category", "Integration")]and[Trait("Database", "...")]for filtering.
If you need a new collection (e.g., for a new database provider or a specialized fixture):
- Add the
[CollectionDefinition]class to the appropriateCollections.csfile - Use a descriptive name following the pattern:
{Provider}-{Database}(e.g.,ADO-PostgreSQL) - For in-memory databases, add
DisableParallelization = true - Update this document's container count table
// In the appropriate Collections.cs file
[CollectionDefinition("ADO-PostgreSQL")]
[SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix",
Justification = "xUnit requires collection types to end with 'Collection'")]
public class ADOPostgreSqlCollection : ICollectionFixture<PostgreSqlFixture>
{
}For clean results without Docker contention, run tests by database group:
# These groups run independently with zero failures
dotnet test tests/Encina.IntegrationTests --filter "Database=PostgreSQL"
dotnet test tests/Encina.IntegrationTests --filter "Database=MySQL"
dotnet test tests/Encina.IntegrationTests --filter "Database=SqlServer"Note: Running ALL groups simultaneously may cause intermittent SqlServer fixture initialization failures due to Docker container startup contention. This is a known Docker limitation, not a code issue. All tests pass when run by database group.
Integration tests use xUnit traits and collections for categorization:
[Collection("ADO-SqlServer")]
[Trait("Category", "Integration")]
[Trait("Database", "SqlServer")]
public class OutboxStoreSqlServerIntegrationTests : IAsyncLifetime
{
// Tests share a single SQL Server Docker container via the collection fixture
}# Run only integration tests
dotnet test --filter "Category=Integration"
# Run specific database provider tests
dotnet test --filter "Category=Integration&Database=SqlServer"
# Exclude integration tests (unit tests only)
dotnet test --filter "Category!=Integration"Integration tests cover:
- Outbox Pattern: Message persistence, retrieval, and processing
- Inbox Pattern: Idempotency guarantees and deduplication
- Saga Pattern: State persistence and compensation logic
- Scheduling Pattern: Delayed and recurring message execution
- Transaction Pattern: Commit/rollback behavior with Railway Oriented Programming
- name: Start database containers
run: docker-compose up -d sqlserver postgres mysql
- name: Wait for databases to be healthy
run: sleep 30
- name: Run integration tests
run: dotnet test --filter "Category=Integration"
- name: Stop database containers
run: docker-compose downMorning Setup:
docker-compose up -dDevelopment Loop:
# Make changes
dotnet test --filter "Category=Integration"End of Day:
docker-compose downIf local databases are already running on standard ports:
# Windows: Check port usage
netstat -ano | findstr :1433
# Linux/macOS: Check port usage
lsof -i :1433
# Solution: Stop local service or modify docker-compose.yml ports# View container logs
docker-compose logs sqlserver
# Clean start
docker-compose down -v
docker-compose up -d# Verify container health
docker ps
# Check specific container health status
docker inspect Encina-sqlserver --format='{{.State.Health.Status}}'
# If unhealthy, examine logs
docker-compose logs sqlserverThe following table shows which providers are supported by each testing approach. Oracle (ADR-009) and SQLite (ADR-024) were removed and are not listed.
| Provider | Testcontainers | Aspire.Hosting | Recommended Approach | Notes |
|---|---|---|---|---|
| PostgreSQL | PostgreSqlContainer |
AddPostgres() |
Testcontainers | Established fixtures, simpler API |
| SQL Server | MsSqlContainer |
AddSqlServer() |
Testcontainers | Established fixtures, simpler API |
| MySQL | MySqlContainer |
AddMySql() |
Testcontainers | Established fixtures, simpler API |
| MongoDB | MongoDbContainer |
AddMongoDB() |
Testcontainers | Established fixtures |
| Redis | RedisContainer |
AddRedis() |
Testcontainers | Established fixtures |
| RabbitMQ | RabbitMqContainer |
AddRabbitMQ() |
Testcontainers | Established fixtures |
| Kafka | KafkaContainer |
AddKafka() |
Testcontainers | Established fixtures |
| NATS | GenericContainer |
AddNats() |
Testcontainers | Limited Aspire support |
| MQTT | GenericContainer |
Limited | Testcontainers Only | No dedicated Aspire resource |
Use Testcontainers when:
- Component-level database/service tests
- Fine-grained container control needed
- Leveraging existing
Encina.TestInfrastructurefixtures
Use Aspire.Hosting.Testing when:
- Testing full Aspire AppHost configurations
- Multi-service orchestration scenarios
- Production parity validation
See ADR-008: Aspire vs Testcontainers Testing Strategy for detailed guidance.
The Encina.TestInfrastructure project provides:
- Database Fixtures: Per-provider fixtures implementing
IAsyncLifetime - Schema Builders: Database-specific DDL for Outbox, Inbox, Sagas, Scheduling
- Test Data Builders: Fluent builders for test entities
- Testcontainers Integration: Programmatic container lifecycle management
| Provider | Integration | Contract | Property | Load |
|---|---|---|---|---|
| Dapper.SqlServer | ✅ | ✅ | ✅ | ✅ |
| Dapper.PostgreSQL | ✅ | ✅ | ✅ | ✅ |
| Dapper.MySQL | ✅ | ✅ | ✅ | ✅ |
| ADO.SqlServer | ✅ | ✅ | ✅ | ✅ |
| ADO.PostgreSQL | ✅ | ✅ | ✅ | ✅ |
| ADO.MySQL | ❌ | ✅ | ✅ | ✅ |
Note: ADO MySQL uses Testcontainers-based integration tests in Contract/Property/Load projects instead of separate Integration projects.