DbFixtures.Mongodb 1.0.18

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

Fixtures Manager MongoDB Driver

An abstraction layer for the mongodb package to facilitate handling database fixtures for testing purposes, in a MongoDB database.
This package is ment to be used in conjunction with the dbfixtures package, but can also be used by itself.

Installation

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

Usage

This package exposes 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();
}

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; }
}
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.19 510 9/21/2026
1.0.18 1,123 9/11/2026
1.0.17 150 9/9/2026
1.0.16 1,176 8/28/2026
1.0.15 1,798 8/13/2026
1.0.14 139 8/12/2026
1.0.13 1,663 7/17/2026
1.0.12 395 7/8/2026
1.0.11 3,300 5/29/2026
1.0.10 2,325 5/12/2026
1.0.9 1,017 4/22/2026
1.0.8 3,173 3/19/2026
1.0.7 239 3/18/2026
1.0.6 3,151 1/23/2026
1.0.5 3,833 12/8/2025
1.0.4 7,327 9/13/2025
1.0.3 376 9/10/2025
1.0.2 1,767 8/8/2025
1.0.1 267 8/8/2025
1.0.0 301 7/20/2025