Skip to content

Commit

Permalink
Add cassandra.md to documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
gavindekock committed Feb 26, 2025
1 parent b53e4f2 commit e80cbe3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
27 changes: 27 additions & 0 deletions docs/modules/cassandra.md
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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))]
Expand All @@ -66,4 +68,4 @@ public async Task ExecScriptAsyncReturnsSuccess()
Assert.True(0L.Equals(execResult.ExitCode), execResult.Stderr);
Assert.Empty(execResult.Stderr);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
<IsPublishable>false</IsPublishable>
</PropertyGroup>
<ItemGroup>
<!-- -8<- [start:PackageReferences] -->
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
<PackageReference Include="coverlet.collector"/>
<PackageReference Include="xunit.runner.visualstudio"/>
<PackageReference Include="xunit"/>
<PackageReference Include="CassandraCSharpDriver"/>
<!-- -8<- [end:PackageReferences] -->
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../src/Testcontainers.Cassandra/Testcontainers.Cassandra.csproj"/>
<ProjectReference Include="../Testcontainers.Commons/Testcontainers.Commons.csproj"/>
</ItemGroup>
</Project>
</Project>

0 comments on commit e80cbe3

Please sign in to comment.