-
-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced a new documentation markdown file that provides instructions on how to use the MongoDB module in a .NET environment.
- Loading branch information
1 parent
86b8258
commit 07b3a5c
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |