DbFixtures 1.0.6

dotnet add package DbFixtures --version 1.0.6
                    
NuGet\Install-Package DbFixtures -Version 1.0.6
                    
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="DbFixtures" Version="1.0.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DbFixtures" Version="1.0.6" />
                    
Directory.Packages.props
<PackageReference Include="DbFixtures" />
                    
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 DbFixtures --version 1.0.6
                    
#r "nuget: DbFixtures, 1.0.6"
                    
#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 DbFixtures@1.0.6
                    
#: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=DbFixtures&version=1.0.6
                    
Install as a Cake Addin
#tool nuget:?package=DbFixtures&version=1.0.6
                    
Install as a Cake Tool

Fixtures Manager

An abstraction layer for handling database fixtures for automated testing purposes, providing a standardized interface across different database systems.

Installation

dotnet add [path/to/your/csproj/file] package DbFixtures

Features

  • Test runner agnostic
  • No dependencies
  • Standardized interface across multiple database systems
  • Easily set your database for each test's needs

Drivers

This package will use drivers to handle the database operations. Each driver will be dedicated to 1 databse system (ex: MongoDb, Redis).
You can set as many drivers as needed and the fixtures will be sent to each one.

Official drivers

Driver interface

The drivers are expected to use the following interface

public interface IDriver
{
  // clears the specified "tables" of any content
  public Task Truncate(string[] tableNames);

  // inserts the supplied "rows" into the specified "table"
  public Task InsertFixtures<T>(string tableName, T[] fixtures);

  // cleanup and terminate the connection to the database
  public Task Close();
}

Usage

This package exposes the following interface

public interface IDbFixtures
{
  public Task InsertFixtures<T>(string[] tableNames, Dictionary<string, T[]> fixtures);

  public Task CloseDrivers();
}

Where

  • InsertFixtures<T>(string[] tableNames, Dictionary<string, T[]> fixtures): call this function with the fixtures to be sent to each registered driver.
    Note: the fixtures will be inserted in the order they are provided.

  • CloseDrivers(): call this function to run any necessary cleanup operations on all registered drivers.

Example

using System.Text.Json.Serialization;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Driver;
using SharedLibs.Types;

namespace DbFixtures.Mongodb.Tests.E2E;

[Trait("Type", "E2E")]
public class MongodbDriverTests : IDisposable
{
  private const string DB_NAME = "testDb";
  private readonly IDbFixtures _dbFixtures;
  private readonly IMongoClient _client;

  public MongodbDriverTests()
  {
    this._client = new MongoClient("mongodb://admin:pw@api_db:27017/admin?authMechanism=SCRAM-SHA-256");
    var driver = new MongodbDriver(this._client, DB_NAME);
    this._dbFixtures = new DbFixtures([driver]);

    this._client.DropDatabase(DB_NAME);
  }

  public void Dispose()
  {
    this._dbFixtures.CloseDrivers();
  }

  [Fact]
  public async TasK MySutMethod_ItShouldWork()
  {
    var db = this._client.GetDatabase(DB_NAME);
    var collOne = db.GetCollection<TestModel>("coll");
    var collTwo = db.GetCollection<TestModel>("anotherColl");

    TestModel[] expectedDocs = [
      new TestModel{ Id = ObjectId.GenerateNewId().ToString(), Prop1 = "final doc 1" },
      new TestModel{ Id = ObjectId.GenerateNewId().ToString(), Prop1 = "final doc 2", Prop2 = 123 },
    ];

    await this._dbFixtures.InsertFixtures(
      ["coll", "anotherColl"],
      new Dictionary<string, TestModel[]>
      {
        { "coll", [] },
        { "anotherColl", expectedDocs },
      }
    );

    var CollOneDocs = collOne.Find(FilterDefinition<TestModel>.Empty).ToList();
    var CollTwoDocs = collTwo.Find(FilterDefinition<TestModel>.Empty).ToList();
    Assert.Empty(CollOneDocs);
    Assert.Equal(expectedDocs.ToJson(), CollTwoDocs.ToJson());
  }
}

public class TestModel
{
  [JsonPropertyName("id")]
  [BsonId]
  [BsonRepresentation(BsonType.ObjectId)]
  [BsonIgnoreIfDefault]
  public string? Id { get; set; }

  [JsonPropertyName("prop1")]
  public required string Prop1 { get; set; }

  [JsonPropertyName("prop2")]
  public int Prop2 { get; set; }
}

How It Works

Each registered driver will be called to:

  • clear the "tables" that will be used in the current fixture insertion operation from any content.

  • insert the fixtures in the order they were provided.

  • terminate the connection to their database.

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

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.6 1,576 9/9/2026
1.0.5 2,899 8/12/2026
1.0.4 1,653 7/17/2026
1.0.3 22,894 9/10/2025
1.0.2 1,783 8/8/2025
1.0.1 264 8/8/2025
1.0.0 301 7/20/2025