Skip to content

Commit

Permalink
Add MongoDB module documentation
Browse files Browse the repository at this point in the history
Introduced a new documentation markdown file that provides instructions on how to use the MongoDB module in a .NET environment.
  • Loading branch information
khalidabuhakmeh committed Oct 4, 2023
1 parent 86b8258 commit 07b3a5c
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions docs/modules/mongodb.md
Original file line number Diff line number Diff line change
@@ -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/

0 comments on commit 07b3a5c

Please sign in to comment.