From aa0516955ef83884646155c2f862df6fdc038051 Mon Sep 17 00:00:00 2001 From: Khalid Abuhakmeh Date: Wed, 4 Oct 2023 10:17:18 -0400 Subject: [PATCH 1/2] Add Neo4j documentation A new document, neo4j.md, has been added in the docs/modules directory. This document contains information about Neo4j, including a brief introduction, installation of NuGet dependencies, and a guide to run tests in .NET. --- docs/modules/neo4j.md | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 docs/modules/neo4j.md diff --git a/docs/modules/neo4j.md b/docs/modules/neo4j.md new file mode 100644 index 000000000..7f3e8edf3 --- /dev/null +++ b/docs/modules/neo4j.md @@ -0,0 +1,52 @@ +# Neo4j + +[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. + +The following example uses the following NuGet packages: + +```console title="Install the NuGet dependencies" +dotnet add package Testcontainers.Neo4j +dotnet add package Neo4j.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 Neo4j.Driver; +using Testcontainers.Neo4j; +using Xunit; + +namespace TestcontainersModules; + +public class Neo4jContainerTest : IAsyncLifetime +{ + private readonly Neo4jContainer neo4JContainer + = new Neo4jBuilder().Build(); + + [Fact] + public async Task CanReadNeo4jDatabase() + { + const string database = "neo4j"; + var connectionString = neo4JContainer.GetConnectionString(); + await using var client = GraphDatabase.Driver(connectionString); + + await using var session = + client.AsyncSession(cfg => cfg.WithDatabase(database)); + + Assert.Equal(database, session.SessionConfig.Database); + } + + public Task InitializeAsync() + => neo4JContainer.StartAsync(); + + public Task DisposeAsync() + => neo4JContainer.DisposeAsync().AsTask(); +} +``` + +To execute the tests, use the command `dotnet test` from a terminal. + +[xunit]: https://xunit.net/ From 162a4c31e7f48b6e27d5567a4fab117b41796f96 Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Thu, 5 Oct 2023 18:13:30 +0200 Subject: [PATCH 2/2] Update docs/modules/neo4j.md --- docs/modules/neo4j.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/modules/neo4j.md b/docs/modules/neo4j.md index 7f3e8edf3..44a5cec0b 100644 --- a/docs/modules/neo4j.md +++ b/docs/modules/neo4j.md @@ -23,27 +23,27 @@ namespace TestcontainersModules; public class Neo4jContainerTest : IAsyncLifetime { - private readonly Neo4jContainer neo4JContainer - = new Neo4jBuilder().Build(); + private readonly Neo4jContainer neo4jContainer + = new Neo4jBuilder() + .Build(); [Fact] public async Task CanReadNeo4jDatabase() { const string database = "neo4j"; - var connectionString = neo4JContainer.GetConnectionString(); - await using var client = GraphDatabase.Driver(connectionString); - await using var session = - client.AsyncSession(cfg => cfg.WithDatabase(database)); + await using var client = GraphDatabase.Driver(neo4jContainer.GetConnectionString()); + + await using var session = client.AsyncSession(cfg => cfg.WithDatabase(database)); Assert.Equal(database, session.SessionConfig.Database); } public Task InitializeAsync() - => neo4JContainer.StartAsync(); + => neo4jContainer.StartAsync(); public Task DisposeAsync() - => neo4JContainer.DisposeAsync().AsTask(); + => neo4jContainer.DisposeAsync().AsTask(); } ```