Repositories tested on real PostgreSQL

The problem it solves

A repository's correctness depends on the database: SQL translation, constraints, collations, sequences, JSON columns, transactions. EF Core's in-memory provider has none of those, and a test that passes on it can fail on PostgreSQL — or the other way round.

The database adapter's tests (Blouppy.Infrastructure.Database.IntegrationTests) start a real PostgreSQL in a container with Testcontainers, apply the real migrations, and run each test with three separate DbContexts — one to arrange, one to act, one to assert — so that nothing passes because the change tracker still holds an entity that was never saved.

The same goes for the other adapters with a real dependency: file storage runs against a disk and an S3-compatible store in a container, the messaging tests hold the outbox's guarantees down against PostgreSQL.

What it costs

  • Docker wherever the tests run, CI included.
  • Time: a container per test project, and slower tests than an in-memory fake.
  • Writing the data: each test builds the rows it asserts against, through Given_a_*() helpers, rather than relying on sample data.

What you can relax

  • Unit tests stay fast. Services, validators and handlers are tested with mocked ports; only the adapters touch a container.

  • Run one class while iterating:

    cd back
    dotnet test --project Blouppy.Infrastructure.Database.IntegrationTests/Blouppy.Infrastructure.Database.IntegrationTests.csproj \
      --filter-class "*WorkspacesRepositoryTests"