Anarchy.Toolkit.Testing.Db.Postgres
Part of Anarchy I/O Toolkit, a .NET developer platform · Pillar: Infrastructure · Layer: Testing kit · Package catalog
PostgreSQL integration-test helpers for the toolkit’s Npgsql persistence adapter.
dotnet add package Anarchy.Toolkit.Testing.Db.Postgres
- Use
PostgresHelperorSingletonPostgresHelperfor connection, pool, resilience and unit-of-work fixtures. PostgresOptionsMappermaps options; helpers include generic enum type-handler registration and table cleanup.- Tests need a PostgreSQL instance and a schema appropriate to the consuming application.
When to use it
Use this package for integration tests that need to verify PostgreSQL queries, Dapper mappings or unit-of-work behavior against a real database. It creates fixtures using the toolkit provider; it does not launch PostgreSQL or migrate your schema.
How to use it
- Start an isolated PostgreSQL instance and prepare the test schema. Implement
IPostgresAppSettingson your settings type; policy fixtures additionally requireIResilienceAppSettings. - Create the required fixture from embedded test settings, or pass a settings instance directly:
using Anarchy.Toolkit.Testing.Db.Postgres.Helper;
var policy = PostgresHelper.DbPolicyFixture<TestAppSettings>();
var unitOfWork = PostgresHelper.DbUnitOfWorkFixture<TestAppSettings>();
Here TestAppSettings is your own type and its declaring assembly contains the embedded test settings. Register enum handlers as needed, use the fixtures in repository tests, and clean up only dedicated test tables. SingletonPostgresHelper shares a policy; coordinate access and cleanup when tests run in parallel.
See Infrastructure.Persistence.Db.Postgres, the testing conventions and the toolkit overview.
Releases
See the release notes for the complete release history.