Skip to content

Commit 69292d1

Browse files
docs: Add Neo4j example (#1013)
Co-authored-by: Andre Hofmeister <[email protected]>
1 parent e713c6f commit 69292d1

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

docs/modules/neo4j.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Neo4j
2+
3+
[Neo4j](https://neo4j.com/product/neo4j-graph-database/) is a graph database designed to work with nodes and edges. It is a ACID-compliant transactional graph database engine, and developers can communicate with it using the HTTP endpoint or by using the **Bolt** protocol.
4+
5+
The following example uses the following NuGet packages:
6+
7+
```console title="Install the NuGet dependencies"
8+
dotnet add package Testcontainers.Neo4j
9+
dotnet add package Neo4j.Driver
10+
dotnet add package xunit
11+
```
12+
13+
IDEs and editors may also require the following packages to run tests: `xunit.runner.visualstudio` and `Microsoft.NET.Test.Sdk`.
14+
15+
Copy and paste the following code into a new `.cs` test file within an existing test project.
16+
17+
```csharp
18+
using Neo4j.Driver;
19+
using Testcontainers.Neo4j;
20+
using Xunit;
21+
22+
namespace TestcontainersModules;
23+
24+
public class Neo4jContainerTest : IAsyncLifetime
25+
{
26+
private readonly Neo4jContainer neo4jContainer
27+
= new Neo4jBuilder()
28+
.Build();
29+
30+
[Fact]
31+
public async Task CanReadNeo4jDatabase()
32+
{
33+
const string database = "neo4j";
34+
35+
await using var client = GraphDatabase.Driver(neo4jContainer.GetConnectionString());
36+
37+
await using var session = client.AsyncSession(cfg => cfg.WithDatabase(database));
38+
39+
Assert.Equal(database, session.SessionConfig.Database);
40+
}
41+
42+
public Task InitializeAsync()
43+
=> neo4jContainer.StartAsync();
44+
45+
public Task DisposeAsync()
46+
=> neo4jContainer.DisposeAsync().AsTask();
47+
}
48+
```
49+
50+
To execute the tests, use the command `dotnet test` from a terminal.
51+
52+
[xunit]: https://xunit.net/

0 commit comments

Comments
 (0)