Part of Anarchy I/O Toolkit, a .NET developer platform · Pillar: Infrastructure · Layer: Testing kit · Package catalog

Provider-agnostic relational database helpers for integration tests.

dotnet add package Anarchy.Toolkit.Testing.Db
  • Use DbTestHelper.RegisterEnumTypeHandler<TEnum>() to register enum type handlers.
  • Use TruncateTableAsync<TConnection, TDialect> or ClearTableAsync for table cleanup and DbOptionsMapper for options mapping.
  • Provider-specific fixtures are available in Testing.Db.Postgres, Testing.Db.Oracle and Testing.Db.Mysql.

When to use it

Use this package in database integration tests or when building a new provider’s test kit. It contains common cleanup and mapping helpers, not a database server, schema migration tool or provider-specific connection setup.

How to use it

Create a real test database and a provider-specific storage policy, then register any enum handlers before testing Dapper mappings. For cleanup, choose truncation through the dialect or a DELETE through ClearTableAsync:

using Anarchy.Toolkit.Testing.Db.Helper;

DbTestHelper.RegisterEnumTypeHandler<UserStatus>();
await DbTestHelper.ClearTableAsync<MyConnection>(policy, "users", cancellationToken);

Replace UserStatus, MyConnection and policy with your own enum, database connection type and configured policy. Table names are inserted into SQL, so use trusted fixed identifiers, never user input. Cleanup is destructive; use a dedicated test schema and account for foreign keys, identity behavior and tests running concurrently.

See the testing conventions and toolkit overview.

Releases

See the release notes for the complete release history.