From 07b3a5c616ff63979e24cb98ca4a87a3ee5ccead Mon Sep 17 00:00:00 2001 From: Khalid Abuhakmeh Date: Wed, 4 Oct 2023 08:47:02 -0400 Subject: [PATCH 1/2] Add MongoDB module documentation Introduced a new documentation markdown file that provides instructions on how to use the MongoDB module in a .NET environment. --- docs/modules/mongodb.md | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 docs/modules/mongodb.md diff --git a/docs/modules/mongodb.md b/docs/modules/mongodb.md new file mode 100644 index 000000000..fd92b9ee9 --- /dev/null +++ b/docs/modules/mongodb.md @@ -0,0 +1,51 @@ +# MongoDB + +[MongoDB](https://www.mongodb.com/what-is-mongodb) is a cross-platform document-oriented database. MongoDB's document model is simple for developers to use within their applications, while still providing all the complex capabilities of traditional relational databases. + +The following example uses the following NuGet packages: + +```console title="Install the NuGet dependencies" +dotnet add package Testcontainers.MongoDb +dotnet add package MongoDB.Driver +dotnet add package xunit +``` + +IDEs and editors may also require the following packages to run tests: `xunit.runner.visualstudio` and `Microsoft.NET.Test.Sdk`. + +Copy and paste the following code into a new `.cs` test file within an existing test project. + +```csharp +using MongoDB.Driver; +using Testcontainers.MongoDb; +using Xunit; + +namespace TestcontainersModules; + +public class MongoDbContainerTest : IAsyncLifetime +{ + private readonly MongoDbContainer mongoDbContainer = + new MongoDbBuilder().Build(); + + [Fact] + public async Task ReadFromMongoDbDatabase() + { + var client = + new MongoClient(mongoDbContainer.GetConnectionString()); + + using var databases = + await client.ListDatabasesAsync(); + + Assert.True(await databases.AnyAsync()); + } + + public Task InitializeAsync() + => mongoDbContainer.StartAsync(); + + public Task DisposeAsync() + => mongoDbContainer.DisposeAsync().AsTask(); +} +``` + +To execute the tests, use the command `dotnet test` from a terminal. + +[xunit]: https://xunit.net/ From 865e0a4f3291bbab05cb17159d7646a9f6af0ff6 Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Thu, 5 Oct 2023 18:07:04 +0200 Subject: [PATCH 2/2] Update docs/modules/mongodb.md --- docs/modules/mongodb.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/modules/mongodb.md b/docs/modules/mongodb.md index fd92b9ee9..46408e7ec 100644 --- a/docs/modules/mongodb.md +++ b/docs/modules/mongodb.md @@ -24,16 +24,15 @@ namespace TestcontainersModules; public class MongoDbContainerTest : IAsyncLifetime { private readonly MongoDbContainer mongoDbContainer = - new MongoDbBuilder().Build(); + new MongoDbBuilder() + .Build(); [Fact] public async Task ReadFromMongoDbDatabase() { - var client = - new MongoClient(mongoDbContainer.GetConnectionString()); + var client = new MongoClient(mongoDbContainer.GetConnectionString()); - using var databases = - await client.ListDatabasesAsync(); + using var databases = await client.ListDatabasesAsync(); Assert.True(await databases.AnyAsync()); }