MagicCSharp.Testing.Database 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package MagicCSharp.Testing.Database --version 1.0.0
                    
NuGet\Install-Package MagicCSharp.Testing.Database -Version 1.0.0
                    
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="MagicCSharp.Testing.Database" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MagicCSharp.Testing.Database" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="MagicCSharp.Testing.Database" />
                    
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 MagicCSharp.Testing.Database --version 1.0.0
                    
#r "nuget: MagicCSharp.Testing.Database, 1.0.0"
                    
#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 MagicCSharp.Testing.Database@1.0.0
                    
#: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=MagicCSharp.Testing.Database&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=MagicCSharp.Testing.Database&version=1.0.0
                    
Install as a Cake Tool

MagicCSharp.Testing.Database

Repository integration testing against a real PostgreSQL, via Testcontainers. Requires Docker.

Split out from MagicCSharp.Testing on purpose: the fakes there have no heavy dependencies, and a project that only wants FakeClock should not pull in Testcontainers, xUnit and Npgsql.

Why a real database

A repository is mostly translation — a filter into SQL, a row into an entity. The in-memory and SQLite providers translate differently from Postgres, so a test that passes against them proves the C# and not the query, which is the half that breaks. Enum-as-string columns, jsonb round-trips and timestamptz offset rules have no equivalent anywhere else.

MagicCSharp's own repository bases are tested this way — tests/MagicCSharp.Data.EntityFramework.Tests is fifty tests over a real Postgres, covering create, filter, update, delete, pagination, soft delete and the search column. It is the worked example of everything below.

Cost control

One container for the whole suite. One logical database per test class, so classes run in parallel without seeing each other's rows. Schema created once per database. Tables truncated between tests rather than recreated.

Use

[Trait("Category", "Integration")]
public class OrderRepositoryTests : TestRepositoryBase<ShopContext>
{
    private OrderEfRepository Repository => new OrderEfRepository(DbContextFactory, Clock, KeyGen, NullLoggerFactory.Instance);

    [Fact]
    public async Task Create_assigns_created_and_updated_from_the_clock()
    {
        Clock.SetTime(2026, 3, 1);

        var order = await Repository.Create(new OrderEdit { UserId = 1 });

        Assert.Equal(Clock.Now(), order.Created);
    }
}

Override ContainerImage to match production, or to get an extension — a context with a vector column needs pgvector/pgvector:pg17. Override InitializeDatabase to Database.MigrateAsync() when you want the test to prove the migrations produce a working schema, rather than building it from the model.

Run without Docker by filtering: dotnet test --filter "Category!=Integration".

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 84 9/24/2026
1.0.1 97 9/24/2026
1.0.0 85 9/23/2026