Skip to content

Commit

Permalink
Implemented the GetConnectionString
Browse files Browse the repository at this point in the history
  • Loading branch information
gavindekock committed Feb 16, 2025
1 parent 309c52d commit b430da8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
18 changes: 7 additions & 11 deletions src/Testcontainers.Cassandra/CassandraContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,18 @@ public CassandraContainer(CassandraConfiguration configuration)
_configuration = configuration;
}

/// <summary>
/// Gets the Cassandra contact point.
/// </summary>
/// <returns>The Cassandra contact point.</returns>
public IPEndPoint GetContactPoint()
{
return new IPEndPoint(Dns.GetHostAddresses(Hostname)[0], GetMappedPublicPort(CassandraBuilder.CqlPort));
}

/// <summary>
/// Gets the Cassandra connection string.
/// </summary>
/// <returns>The Cassandra connection string.</returns>
public string GetConnectionString()
{
throw new NotImplementedException();
var properties = new Dictionary<string, string>
{
{ "Contact Points", Hostname },
{ "Port", GetMappedPublicPort(CassandraBuilder.CqlPort).ToString() },
};
return string.Join(";", properties.Select(property => string.Join("=", property.Key, property.Value)));
}

/// <summary>
Expand All @@ -47,4 +43,4 @@ await CopyAsync(Encoding.Default.GetBytes(scriptContent), scriptFilePath, Unix.F
return await ExecAsync(new[] { "cqlsh", "--file", scriptFilePath }, ct)
.ConfigureAwait(false);
}
}
}
4 changes: 3 additions & 1 deletion src/Testcontainers.Cassandra/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
global using System.IO;
global using System.Net;
global using System.Text;
global using System.Linq;
global using System.Threading;
global using System.Threading.Tasks;
global using System.Collections.Generic;
global using Docker.DotNet.Models;
global using DotNet.Testcontainers.Builders;
global using DotNet.Testcontainers.Configurations;
global using DotNet.Testcontainers.Containers;
global using JetBrains.Annotations;
global using JetBrains.Annotations;
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public Task DisposeAsync()
public void ConnectionStateReturnsOpen()
{
// Given
using var cluster = Cluster.Builder().AddContactPoint(_cassandraContainer.GetContactPoint()).Build();
using var cluster = Cluster.Builder().WithConnectionString(_cassandraContainer.GetConnectionString()).Build();

// When
using var session = cluster.Connect();
Expand All @@ -35,7 +35,7 @@ public void DriverExecutesCqlStatementAndReturnResult()
// Given
const string selectFromSystemLocalStatement = "SELECT * FROM system.local WHERE key = ?;";

using var cluster = Cluster.Builder().AddContactPoint(_cassandraContainer.GetContactPoint()).Build();
using var cluster = Cluster.Builder().WithConnectionString(_cassandraContainer.GetConnectionString()).Build();

// When
using var session = cluster.Connect();
Expand Down Expand Up @@ -66,4 +66,4 @@ public async Task ExecScriptAsyncReturnsSuccess()
Assert.True(0L.Equals(execResult.ExitCode), execResult.Stderr);
Assert.Empty(execResult.Stderr);
}
}
}

0 comments on commit b430da8

Please sign in to comment.