Verify.MongoDB 2.0.82

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
.NET 6.0 .NET Core 3.1
dotnet add package Verify.MongoDB --version 2.0.82
NuGet\Install-Package Verify.MongoDB -Version 2.0.82
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="Verify.MongoDB" Version="2.0.82" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Verify.MongoDB --version 2.0.82
#r "nuget: Verify.MongoDB, 2.0.82"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Verify.MongoDB as a Cake Addin
#addin nuget:?package=Verify.MongoDB&version=2.0.82

// Install Verify.MongoDB as a Cake Tool
#tool nuget:?package=Verify.MongoDB&version=2.0.82

Verify.MongoDB

.NET NuGet Status

Extends Verify to allow verification of MongoDB bits.

Verify.MongoDB is heavily inspired by @SimonCropp's Verify.EntityFramework

Enable

Enable VerifyMongoDb once at assembly load time:

VerifyMongoDb.Enable();

Recording

Recording allows all commands executed by the MongoDB driver to be captured and then (optionally) verified.

Call MongoDbRecording.EnableRecording() on MongoClientSettings.

var clientSettings = MongoClientSettings.FromUrl(new MongoUrl(configuration["MongoConnectionString"]));

clientSettings.EnableRecording();

By default, all three event types (Started, Succeeded and Failed) are recorded. You can optionally specify the events required.

clientSettings.EnableRecording(MongoDbEvents.Succeeded | MongoDbEvents.Failed);

EnableRecording should only be called in the test context.

Usage

To start recording call MongoDbRecording.StartRecording(). The results will be automatically included in the verified file.

MongoDBRecording.StartRecording();

await collection.FindAsync(Builders<BsonDocument>.Filter.Eq("_id", "blah"),
    new FindOptions<BsonDocument, BsonDocument>());
    
await Verifier.Verify("collection");

Will result in the following verified file:

{
  target: collection,
  mongo: [
    {
      Database: VerifyTests,
      Document: {
        filter: {
          _id: blah
        },
        find: docs
      },
      Type: Started,
      Command: find,
      StartTime: DateTimeOffset_1,
      OperationId: Id_1,
      RequestId: Id_2
    },
    {
      Document: {
        cursor: {
          firstBatch: [],
          id: 0,
          ns: VerifyTests.docs
        },
        ok: 1.0
      },
      Type: Succeeded,
      Command: find,
      StartTime: DateTimeOffset_2,
      OperationId: Id_1,
      RequestId: Id_2
    }
  ]
}
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp3.1
Compatible target framework(s)
Additional computed target framework(s)
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
2.0.82 225 10/5/2022
2.0.2 339 6/3/2022
1.0.79 329 4/28/2022
1.0.75 304 4/16/2022
1.0.73 330 3/30/2022
1.0.71 321 3/30/2022