Rig.TUnit.Databases.NoSql.Mongo 0.1.0-beta.2

This is a prerelease version of Rig.TUnit.Databases.NoSql.Mongo.
dotnet add package Rig.TUnit.Databases.NoSql.Mongo --version 0.1.0-beta.2
                    
NuGet\Install-Package Rig.TUnit.Databases.NoSql.Mongo -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.NoSql.Mongo" 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.NoSql.Mongo" Version="0.1.0-beta.2" />
                    
Directory.Packages.props
<PackageReference Include="Rig.TUnit.Databases.NoSql.Mongo" />
                    
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.NoSql.Mongo --version 0.1.0-beta.2
                    
#r "nuget: Rig.TUnit.Databases.NoSql.Mongo, 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.NoSql.Mongo@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.NoSql.Mongo&version=0.1.0-beta.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Rig.TUnit.Databases.NoSql.Mongo&version=0.1.0-beta.2&prerelease
                    
Install as a Cake Tool

Rig.TUnit.Databases.NoSql.Mongo

Testcontainers-backed MongoDB fixture with CollectionPerTestHelper and BsonDiff.

What this package is

The Rig.TUnit MongoDB provider. MongoFixture spins MongoDB via Testcontainers and exposes an IMongoClient + default-database. Two helpers solve the common pain points: CollectionPerTestHelper owns a per-test collection scoped by IsolationKey and drops it on disposal, and BsonDiff performs a structural diff between expected / actual documents with the usual system-field scrub list.

When to use it

  • Integration tests targeting MongoDB-specific features (change streams, $lookup, text indexes, transactions with replica set).
  • Asserting document shape with tolerance for _id / ts drift.
  • Not for: unit tests — MongoDB's in-memory driver Mongo2Go is faster but produces different wire errors from the real server.

Prerequisites

  • .NET 10 SDK
  • Docker Desktop / Colima (MongoDB image ~200 MB)
  • MongoDB.Driver 3.x (transitive)

Quick start

using MongoDB.Bson;
using Rig.TUnit.Core.Helpers;
using Rig.TUnit.Databases.NoSql.Mongo.Fixtures;
using Rig.TUnit.Databases.NoSql.Mongo.Helpers;

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

await using var scope = new CollectionPerTestHelper(
    fx.Database, IsolationKey.FromExecutionContext());
var orders = scope.GetCollection<BsonDocument>();

Options

Property Type Default Description
Image string "mongo:7" Image
StartupTimeoutSeconds int 60 Mongo boots fast
ReplicaSetName string? null Set for transactions; off by default
AuthDatabase string? null Off by default in dev mode

Fixture + helper APIs

  • Rig.TUnit.Databases.NoSql.Mongo.Fixtures.MongoFixture
  • Rig.TUnit.Databases.NoSql.Mongo.Options.MongoFixtureOptions
  • Rig.TUnit.Databases.NoSql.Mongo.Builder.MongoRigBuilder
  • Rig.TUnit.Databases.NoSql.Mongo.Helpers.CollectionPerTestHelper
  • Rig.TUnit.Databases.NoSql.Mongo.Assertions.BsonDiff

Per-test isolation

CollectionPerTestHelper names collections {logical}_{IsolationKey:short} and calls Database.DropCollectionAsync on DisposeAsync. Fully parallel-safe.

Parallelism + performance

  • First-run pull: ~15 s.
  • Warm startup: ~2 s.
  • Per-test collection create + drop: ~30 ms.
  • Parallelism: 8+ concurrent tests — collection-level isolation works well.

Troubleshooting

  • Transactions fail with Standalone servers do not support — set ReplicaSetName = "rs0"; the fixture wires the replicaset init script.
  • BsonDiff reports diff on _id — default scrub list includes _id, _etag, _ts. If your domain exposes a domain-level Id alongside _id, scrub it too.

See docs/troubleshooting.md#mongo.

Provider quirks + edge cases

  • MongoDB's default write-concern is w: 1 (acknowledged by primary) — tests asserting durability across a restart must use w: "majority".
  • Index creation is synchronous for small data, async for large. Test helpers assume small.
  • Driver 3.x uses MongoClient which is thread-safe; do not wrap in using — dispose is process-level.

Benchmarks

See MongoBenchmarks.cs; baseline in benchmarks/baseline-005.json.

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.NoSql.Mongo:

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 45 4/27/2026
0.0.0-alpha.0.14 60 4/26/2026