Rig.TUnit.Databases.NoSql.Cosmos
0.1.0-beta.2
dotnet add package Rig.TUnit.Databases.NoSql.Cosmos --version 0.1.0-beta.2
NuGet\Install-Package Rig.TUnit.Databases.NoSql.Cosmos -Version 0.1.0-beta.2
<PackageReference Include="Rig.TUnit.Databases.NoSql.Cosmos" Version="0.1.0-beta.2" />
<PackageVersion Include="Rig.TUnit.Databases.NoSql.Cosmos" Version="0.1.0-beta.2" />
<PackageReference Include="Rig.TUnit.Databases.NoSql.Cosmos" />
paket add Rig.TUnit.Databases.NoSql.Cosmos --version 0.1.0-beta.2
#r "nuget: Rig.TUnit.Databases.NoSql.Cosmos, 0.1.0-beta.2"
#:package Rig.TUnit.Databases.NoSql.Cosmos@0.1.0-beta.2
#addin nuget:?package=Rig.TUnit.Databases.NoSql.Cosmos&version=0.1.0-beta.2&prerelease
#tool nuget:?package=Rig.TUnit.Databases.NoSql.Cosmos&version=0.1.0-beta.2&prerelease
Rig.TUnit.Databases.NoSql.Cosmos
Testcontainers-backed Linux Cosmos emulator fixture with
RuChargeCaptureandPartitionKeyDistributionChecker.
What this package is
The Rig.TUnit Cosmos DB provider. CosmosFixture spins the
mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-preview
Linux emulator via the generic Testcontainers API (the dedicated
Testcontainers.CosmosDb module targets the legacy Windows emulator —
incompatible, see testcontainers-dotnet#1306). Ships two novel helpers:
RuChargeCapture (per-operation RU budget assertions) and
PartitionKeyDistributionChecker (max-share + normalised Shannon entropy
hot-partition detector).
When to use it
- Integration tests against the Cosmos API surface.
- Asserting per-operation RU budgets stay within design targets.
- Detecting hot-partition drift before production.
- Not for: Windows CI runners — the Linux emulator cannot host there.
Tests marked
[Category("cosmos")]auto-skip via runtimeOperatingSystem.IsWindows()guard.
Prerequisites
- .NET 10 SDK
- Docker Desktop / Colima (Linux containers only)
Microsoft.Azure.Cosmos3.x (transitive)
Quick start
using Microsoft.Azure.Cosmos;
using Rig.TUnit.Databases.NoSql.Cosmos.Fixtures;
using Rig.TUnit.Databases.NoSql.Cosmos.Helpers;
await using var fx = new CosmosFixture();
await fx.InitializeAsync();
using var client = new CosmosClient(fx.ConnectionString);
var db = await client.CreateDatabaseIfNotExistsAsync(fx.DatabaseName);
Options
| Property | Type | Default | Description |
|---|---|---|---|
Image |
string |
"mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-preview" |
Emulator image |
StartupTimeoutSeconds |
int |
300 |
Emulator boot is slow |
DatabaseName |
string |
"rigtunit" |
Default database |
HttpsGatewayPort |
int |
8081 |
Emulator gateway port |
Fixture + helper APIs
Rig.TUnit.Databases.NoSql.Cosmos.Fixtures.CosmosFixtureRig.TUnit.Databases.NoSql.Cosmos.Options.CosmosFixtureOptionsRig.TUnit.Databases.NoSql.Cosmos.Builder.CosmosRigBuilderRig.TUnit.Databases.NoSql.Cosmos.Helpers.RuChargeCaptureRig.TUnit.Databases.NoSql.Cosmos.Helpers.PartitionKeyDistributionChecker
Per-test isolation
Container-per-test (IsolationKey suffix) is cost-prohibitive — the
emulator takes ~2 min to start. Default is one fixture per test-class
with per-test container names (test-cosmos-{IsolationKey}) created via
CreateContainerIfNotExistsAsync and deleted on teardown.
Parallelism + performance
- First-run pull: ~2–3 min (~3 GB image).
- Warm startup: ~90–120 s.
- Per-test container create + delete: ~200 ms + RU cost.
- Parallelism: Linux-only, typically 2–4 concurrent tests; emulator does not like high churn.
Troubleshooting
- Tests skipped on Windows CI — expected; Cosmos tests gate on
OperatingSystem.IsWindows()returning false. Run the matrix cell on Linux runners. TransportException— emulator still warming up; fixture waits but in a busy CI cell the default timeout can be exceeded. RaiseStartupTimeoutSeconds.- RU budget assertions flake — Cosmos RU charges drift with index policy and data shape; capture a baseline per-operation first, then assert within a 15 % tolerance.
See docs/troubleshooting.md#cosmos.
Provider quirks + edge cases
- Emulator uses a self-signed certificate; the fixture disables cert
validation on the embedded
HttpClient. Do not reuse that handler in production. RuChargeCaptureis thread-safe; aggregate RU budgets across parallel ops withcapture.Total.PartitionKeyDistributionChecker.IsBalanced(keys, threshold)uses normalised entropy; the default threshold is0.9(0=maximally skewed, 1=uniform).
Benchmarks
See CosmosBenchmarks.cs;
baseline in benchmarks/baseline-005.json. RU-charge assertions are a
common regression vector and are tracked closely.
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.Azure.Cosmos (>= 3.44.0)
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.0)
- Newtonsoft.Json (>= 13.0.3)
- Rig.TUnit.Databases.NoSql (>= 0.1.0-beta.2)
- Testcontainers (>= 4.11.0)
- TUnit.Core (>= 1.34.5)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Rig.TUnit.Databases.NoSql.Cosmos:
| 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 | 48 | 4/26/2026 |