Rig.TUnit.Databases.Sql.Postgresql 0.1.0-beta.2

This is a prerelease version of Rig.TUnit.Databases.Sql.Postgresql.
dotnet add package Rig.TUnit.Databases.Sql.Postgresql --version 0.1.0-beta.2
                    
NuGet\Install-Package Rig.TUnit.Databases.Sql.Postgresql -Version 0.1.0-beta.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Rig.TUnit.Databases.Sql.Postgresql" Version="0.1.0-beta.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Rig.TUnit.Databases.Sql.Postgresql" Version="0.1.0-beta.2" />
                    
Directory.Packages.props
<PackageReference Include="Rig.TUnit.Databases.Sql.Postgresql" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Rig.TUnit.Databases.Sql.Postgresql --version 0.1.0-beta.2
                    
#r "nuget: Rig.TUnit.Databases.Sql.Postgresql, 0.1.0-beta.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Rig.TUnit.Databases.Sql.Postgresql@0.1.0-beta.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Rig.TUnit.Databases.Sql.Postgresql&version=0.1.0-beta.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Rig.TUnit.Databases.Sql.Postgresql&version=0.1.0-beta.2&prerelease
                    
Install as a Cake Tool

Rig.TUnit.Databases.Sql.Postgresql

Testcontainers-backed PostgreSQL fixture with Npgsql EF Core integration, ephemeral-database-per-test helpers, and the family SqlContract suite.

What this package is

The Rig.TUnit PostgreSQL provider. PostgresFixture spins a container from the official postgres:16 image, waits for readiness, and exposes the connection string. PostgresDbContextHelper adds CreateEphemeralDatabaseAsync / EphemeralDatabase : IAsyncDisposable which give every test its own isolated database (dropped via pg_terminate_backend + DROP DATABASE on teardown). Npgsql EF Core 10 is wired via UsePostgres(…) extension.

When to use it

  • Integration tests targeting Postgres-specific features (jsonb, GIN indexes, partial indexes, COPY).
  • Multi-engine tests where Postgres is a required cell.
  • Any scenario where you want per-test DB isolation without the session overhead of schema-per-test.
  • Not for: unit tests — use SQLite in-memory.

Prerequisites

  • .NET 10 SDK
  • Docker Desktop / Colima (first pull ~300 MB)
  • Npgsql.EntityFrameworkCore.PostgreSQL (transitive)

Quick start

using Microsoft.EntityFrameworkCore;
using Rig.TUnit.Databases.Sql.Postgresql.Extensions;
using Rig.TUnit.Databases.Sql.Postgresql.Fixtures;

await using var fx = new PostgresFixture();
await fx.InitializeAsync();

var opts = new DbContextOptionsBuilder<TestDb>()
    .UsePostgres(fx.ConnectionString)
    .Options;

Options

Property Type Default Description
Image string "postgres:16" Container image
StartupTimeoutSeconds int 60 Postgres boots fast
Username string "rigtunit" Superuser created on init
Password string "rigtunit" Superuser password
Database string "rigtunit" Default database

Fixture + helper APIs

  • Rig.TUnit.Databases.Sql.Postgresql.Fixtures.PostgresFixture
  • Rig.TUnit.Databases.Sql.Postgresql.Options.PostgresFixtureOptions
  • Rig.TUnit.Databases.Sql.Postgresql.Builder.PostgresRigBuilder
  • UsePostgres(RigBuilder, …) extension
  • UsePostgres(DbContextOptionsBuilder, string) — EF wiring
  • PostgresDbContextHelper.CreateEphemeralDatabaseAsync + EphemeralDatabase

Per-test isolation

Ephemeral database per testCreateEphemeralDatabaseAsync() returns an EphemeralDatabase : IAsyncDisposable that owns a fresh DB named test_{IsolationKey}. On dispose it calls pg_terminate_backend on every open session against that database, then DROP DATABASE. Per-test, not per-class — enables full parallelism.

Parallelism + performance

  • First-run pull: ~30 s.
  • Warm startup: ~2 s.
  • Ephemeral DB create + drop: ~80 ms per test.
  • Safe under full parallelism (ParallelIsolationContract Iterations=8).

Troubleshooting

  • database "test_abcd" is being accessed by other users — an EphemeralDatabase teardown raced with a lingering DbContext. Always await using the context before disposing the fixture; the helper's pg_terminate_backend call backstops this but the race window is narrow.
  • Npgsql timestamp behaviour changed (EF Core 6→7)legacy_timestamp_behavior is OFF by default now; columns typed timestamp must use DateTime.Kind.Unspecified, not Utc. Tests asserting on DateTime.Utc against timestamp will fail with 400-class errors.

See docs/troubleshooting.md#postgresql.

Provider quirks + edge cases

  • Identifier case folding: Postgres lowercases unquoted identifiers. SELECT "Orders".Id FROM "Orders" works, SELECT Orders.Id fails.
  • serial vs identity: EF Core 7+ defaults to GENERATED BY DEFAULT AS IDENTITY; older migrations may still use serial. Cross-cutting tests must not assume one style.
  • jsonb columns round-trip via System.Text.Json.JsonDocument by default; use HasColumnType("jsonb") to opt in.

Benchmarks

See PostgresUseBenchmarks.cs; baseline in benchmarks/baseline-005.json. Ephemeral-DB create/drop is the main tracked hot path.

License

MIT. See LICENSE.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Rig.TUnit.Databases.Sql.Postgresql:

Package Downloads
Rig.TUnit.All

Meta-package containing every Rig.TUnit.* package. DISCOURAGED — prefer per-feature or per-stack meta-packages (Rig.TUnit, Rig.TUnit.Microservices).

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-beta.2 43 4/27/2026
0.0.0-alpha.0.14 44 4/26/2026