DbFixtures.Mongodb
1.0.20
dotnet add package DbFixtures.Mongodb --version 1.0.20
NuGet\Install-Package DbFixtures.Mongodb -Version 1.0.20
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.20" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DbFixtures.Mongodb" Version="1.0.20" />
<PackageReference Include="DbFixtures.Mongodb" />
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.20
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DbFixtures.Mongodb, 1.0.20"
#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.20
#: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.20
#tool nuget:?package=DbFixtures.Mongodb&version=1.0.20
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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 | Versions 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.
-
net10.0
- DbFixtures.SharedLibs (>= 1.0.5)
- MongoDB.Driver (>= 3.12.0)
-
net8.0
- DbFixtures.SharedLibs (>= 1.0.5)
- MongoDB.Driver (>= 3.12.0)
-
net9.0
- DbFixtures.SharedLibs (>= 1.0.5)
- MongoDB.Driver (>= 3.12.0)
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.20 | 42 | 10/14/2026 |
| 1.0.19 | 892 | 9/21/2026 |
| 1.0.18 | 1,241 | 9/11/2026 |
| 1.0.17 | 154 | 9/9/2026 |
| 1.0.16 | 1,185 | 8/28/2026 |
| 1.0.15 | 1,807 | 8/13/2026 |
| 1.0.14 | 144 | 8/12/2026 |
| 1.0.13 | 1,666 | 7/17/2026 |
| 1.0.12 | 397 | 7/8/2026 |
| 1.0.11 | 3,331 | 5/29/2026 |
| 1.0.10 | 2,336 | 5/12/2026 |
| 1.0.9 | 1,020 | 4/22/2026 |
| 1.0.8 | 3,177 | 3/19/2026 |
| 1.0.7 | 243 | 3/18/2026 |
| 1.0.6 | 3,154 | 1/23/2026 |
| 1.0.5 | 3,837 | 12/8/2025 |
| 1.0.4 | 7,330 | 9/13/2025 |
| 1.0.3 | 379 | 9/10/2025 |
| 1.0.2 | 1,772 | 8/8/2025 |
| 1.0.1 | 270 | 8/8/2025 |
Loading failed