Skip to content

Commit 76ce3e0

Browse files
docs(Cassandra): Add example (testcontainers#1382)
Co-authored-by: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com>
1 parent fc47836 commit 76ce3e0

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

docs/modules/cassandra.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Apache Cassandra
2+
3+
[Apache Cassandra](https://cassandra.apache.org/) is a powerful, open-source, distributed NoSQL database that is highly available and fault-tolerant, used to store, manage, and retrieve structured data.
4+
5+
Add the following dependency to your project file:
6+
7+
```shell title="NuGet"
8+
dotnet add package Testcontainers.Cassandra
9+
```
10+
11+
You can start an Apache 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.
12+
13+
=== "Usage Example"
14+
```csharp
15+
--8<-- "tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs:UseCassandraContainer"
16+
```
17+
18+
The test example uses the following NuGet dependencies:
19+
20+
=== "Package References"
21+
```xml
22+
--8<-- "tests/Testcontainers.Cassandra.Tests/Testcontainers.Cassandra.Tests.csproj:PackageReferences"
23+
```
24+
25+
To execute the tests, use the command `dotnet test` from a terminal.
26+
27+
--8<-- "docs/modules/_call_out_test_projects.txt"

mkdocs.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@ nav:
4747
- examples/aspnet.md
4848
- Modules:
4949
- modules/index.md
50+
- modules/cassandra.md
51+
- modules/pulsar.md
5052
- modules/db2.md
5153
- modules/elasticsearch.md
5254
- modules/mongodb.md
5355
- modules/mssql.md
5456
- modules/neo4j.md
5557
- modules/postgres.md
56-
- modules/pulsar.md
5758
- modules/rabbitmq.md
5859
- contributing.md
5960
- contributing_docs.md

tests/Testcontainers.Cassandra.Tests/CassandraContainerTest.cs

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace Testcontainers.Cassandra;
22

33
public sealed class CassandraContainerTest : IAsyncLifetime
44
{
5+
// # --8<-- [start:UseCassandraContainer]
56
private readonly CassandraContainer _cassandraContainer = new CassandraBuilder().Build();
67

78
public Task InitializeAsync()
@@ -50,6 +51,7 @@ public void ExecuteCqlStatementReturnsExpectedResult()
5051
Assert.Single(rows);
5152
Assert.Equal("COMPLETED", rows[0]["bootstrapped"]);
5253
}
54+
// # --8<-- [end:UseCassandraContainer]
5355

5456
[Fact]
5557
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]

tests/Testcontainers.Cassandra.Tests/Testcontainers.Cassandra.Tests.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
<IsPublishable>false</IsPublishable>
66
</PropertyGroup>
77
<ItemGroup>
8+
<!-- -8<- [start:PackageReferences] -->
89
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
910
<PackageReference Include="coverlet.collector"/>
1011
<PackageReference Include="xunit.runner.visualstudio"/>
1112
<PackageReference Include="xunit"/>
1213
<PackageReference Include="CassandraCSharpDriver"/>
14+
<!-- -8<- [end:PackageReferences] -->
1315
</ItemGroup>
1416
<ItemGroup>
1517
<ProjectReference Include="../../src/Testcontainers.Cassandra/Testcontainers.Cassandra.csproj"/>

0 commit comments

Comments
 (0)