Rig.TUnit.Databases.Sql.Postgresql
0.1.0-beta.2
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
<PackageReference Include="Rig.TUnit.Databases.Sql.Postgresql" Version="0.1.0-beta.2" />
<PackageVersion Include="Rig.TUnit.Databases.Sql.Postgresql" Version="0.1.0-beta.2" />
<PackageReference Include="Rig.TUnit.Databases.Sql.Postgresql" />
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"
#:package Rig.TUnit.Databases.Sql.Postgresql@0.1.0-beta.2
#addin nuget:?package=Rig.TUnit.Databases.Sql.Postgresql&version=0.1.0-beta.2&prerelease
#tool nuget:?package=Rig.TUnit.Databases.Sql.Postgresql&version=0.1.0-beta.2&prerelease
Rig.TUnit.Databases.Sql.Postgresql
Testcontainers-backed PostgreSQL fixture with Npgsql EF Core integration, ephemeral-database-per-test helpers, and the family
SqlContractsuite.
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,GINindexes, 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.PostgresFixtureRig.TUnit.Databases.Sql.Postgresql.Options.PostgresFixtureOptionsRig.TUnit.Databases.Sql.Postgresql.Builder.PostgresRigBuilderUsePostgres(RigBuilder, …)extensionUsePostgres(DbContextOptionsBuilder, string)— EF wiringPostgresDbContextHelper.CreateEphemeralDatabaseAsync+EphemeralDatabase
Per-test isolation
Ephemeral database per test — CreateEphemeralDatabaseAsync() 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 (
ParallelIsolationContractIterations=8).
Troubleshooting
database "test_abcd" is being accessed by other users— anEphemeralDatabaseteardown raced with a lingeringDbContext. Alwaysawait usingthe context before disposing the fixture; the helper'spg_terminate_backendcall backstops this but the race window is narrow.- Npgsql timestamp behaviour changed (EF Core 6→7) —
legacy_timestamp_behavioris OFF by default now; columns typedtimestampmust useDateTime.Kind.Unspecified, notUtc. Tests asserting onDateTime.Utcagainsttimestampwill 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.Idfails. serialvsidentity: EF Core 7+ defaults toGENERATED BY DEFAULT AS IDENTITY; older migrations may still useserial. Cross-cutting tests must not assume one style.jsonbcolumns round-trip viaSystem.Text.Json.JsonDocumentby default; useHasColumnType("jsonb")to opt in.
Benchmarks
See PostgresUseBenchmarks.cs;
baseline in benchmarks/baseline-005.json. Ephemeral-DB create/drop is
the main tracked hot path.
Related docs
License
MIT. See LICENSE.
| Product | Versions 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. |
-
net10.0
- Bogus (>= 35.6.1)
- Microsoft.EntityFrameworkCore (>= 10.0.0)
- Microsoft.EntityFrameworkCore.InMemory (>= 10.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.0)
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Caching.Memory (>= 10.0.0)
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.0)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 10.0.0)
- Rig.TUnit.Databases.Sql (>= 0.1.0-beta.2)
- Testcontainers (>= 4.11.0)
- Testcontainers.PostgreSql (>= 4.11.0)
- TUnit.Core (>= 1.34.5)
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 |