From e80cbe38f4184f344c2be2349160372ae23d9442 Mon Sep 17 00:00:00 2001 From: Gavin de Kock Date: Wed, 26 Feb 2025 01:25:27 +0000 Subject: [PATCH] Add cassandra.md to documentation. --- docs/modules/cassandra.md | 27 +++++++++++++++++++ .../CassandraContainerTest.cs | 4 ++- .../Testcontainers.Cassandra.Tests.csproj | 4 ++- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 docs/modules/cassandra.md diff --git a/docs/modules/cassandra.md b/docs/modules/cassandra.md new file mode 100644 index 000000000..7d5d8dc5d --- /dev/null +++ b/docs/modules/cassandra.md @@ -0,0 +1,27 @@ +# Cassandra + +[Cassandra](https://cassandra.apache.org/) is a powerful, open-source NoSQL distributed, highly available, fault-tolerant database used to store, manage, and retrieve structured data. + +Add the following dependency to your project file: + +```shell title="NuGet" +dotnet add package Testcontainers.Cassandra +``` + +You can start a Cassandra container instance from any .NET application. This example uses xUnit.net's `IAsyncLifetime` interface to manage the lifecycle of the container. The container is started in the `InitializeAsync` method before the test method runs, ensuring that the environment is ready for testing. After the test completes, the container is removed in the `DisposeAsync` method. + +=== "Usage Example" + ```csharp + --8<-- "tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs:UseCassandraContainer" + ``` + +The test example uses the following NuGet dependencies: + +=== "Package References" + ```xml + --8<-- "tests/Testcontainers.Cassandra.Tests/Testcontainers.Cassandra.Tests.csproj:PackageReferences" + ``` + +To execute the tests, use the command `dotnet test` from a terminal. + +--8<-- "docs/modules/_call_out_test_projects.txt" diff --git a/tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs b/tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs index a871cb368..d36fd2670 100644 --- a/tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs +++ b/tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs @@ -2,6 +2,7 @@ namespace Testcontainers.Cassandra; public sealed class CassandraContainerTest : IAsyncLifetime { + // # --8<-- [start:UseCassandraContainer] private readonly CassandraContainer _cassandraContainer = new CassandraBuilder().Build(); public Task InitializeAsync() @@ -50,6 +51,7 @@ public void ExecuteCqlStatementReturnsExpectedResult() Assert.Single(rows); Assert.Equal("COMPLETED", rows[0]["bootstrapped"]); } + // # --8<-- [end:UseCassandraContainer] [Fact] [Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] @@ -66,4 +68,4 @@ public async Task ExecScriptAsyncReturnsSuccess() Assert.True(0L.Equals(execResult.ExitCode), execResult.Stderr); Assert.Empty(execResult.Stderr); } -} \ No newline at end of file +} diff --git a/tests/Testcontainers.Cassandra.Tests/Testcontainers.Cassandra.Tests.csproj b/tests/Testcontainers.Cassandra.Tests/Testcontainers.Cassandra.Tests.csproj index 4cd6fb727..d6c55b1a9 100644 --- a/tests/Testcontainers.Cassandra.Tests/Testcontainers.Cassandra.Tests.csproj +++ b/tests/Testcontainers.Cassandra.Tests/Testcontainers.Cassandra.Tests.csproj @@ -5,14 +5,16 @@ false + + - \ No newline at end of file +