Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kostiantyn-matsebora committed Nov 29, 2024
1 parent 4d8580e commit ff5f075
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,21 @@ public CassandraMultitenantConfigurator AddKeyspace(Id tenantId, string keyspace
public CassandraMultitenantConfigurator UseCosmosDb(IConfiguration configuration, string connectionStringName = "StreamStore", RemoteCertificateValidationCallback? remoteCertValidationCallback = null)
{
var connectionString = configuration.GetConnectionString(connectionStringName);
if (connectionString == null) throw new InvalidOperationException($"Connection string {connectionStringName} is not found");
if (string.IsNullOrEmpty(connectionString))
{
throw new ArgumentException($"Connection string {connectionStringName} is not found in configuration", nameof(configuration));
}

return UseCosmosDb(connectionString, remoteCertValidationCallback);
}

public CassandraMultitenantConfigurator UseCosmosDb(string? connectionString = null, RemoteCertificateValidationCallback? remoteCertValidationCallback = null)
{
mode = CassandraMode.CosmosDbCassandra;
if (connectionString != null)
if (connectionString != null)
{
clusterConfigurator.AddConfigurator(builder => builder.WithCosmosDbConnectionString(connectionString, remoteCertValidationCallback));
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

using Cassandra;
using FluentAssertions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using StreamStore.NoSql.Cassandra.Configuration;
using StreamStore.NoSql.Cassandra.Multitenancy;
using StreamStore.Testing;

namespace StreamStore.NoSql.Tests.Cassandra.Configuration.MultitenantConfigurator;

public class Configuring_cosmosdb: Scenario
{

[Fact]
public void When_connection_string_is_not_set()
{
// Arrange
var configuration = new ConfigurationBuilder().Build();
var configurator = new CassandraMultitenantConfigurator();

// Act
var act = () => configurator.UseCosmosDb(configuration);

//Assert
act.Should().Throw<ArgumentException>();
}


[Fact]
public void When_connection_string_is_defined()
{
// Arrange
var configurator = new CassandraMultitenantConfigurator();
var services = new ServiceCollection();
var connectionString = "HostName=azure.com;Username=streamstore;Password=xxxxxxxxxxx;Port=10350";

var inMemoryConfig = new Dictionary<string, string?>()
{
{ "ConnectionStrings:StreamStore", connectionString },
};
var configuration = new ConfigurationBuilder().AddInMemoryCollection(inMemoryConfig).Build();

// Act
configurator
.UseCosmosDb(configuration)
.WithKeyspaceProvider<FakeKeyspaceProvider>();
configurator.Configure(services);
var provider = services.BuildServiceProvider();

// Assert
var clusterConfigurator = provider.GetRequiredService<IClusterConfigurator>();
var builder = Cluster.Builder();
clusterConfigurator.Configure(builder);
var cluster = builder.Build();
cluster.Should().NotBeNull();

// Arrange
configurator = new CassandraMultitenantConfigurator();
services = new ServiceCollection();

// Act
configurator
.UseCosmosDb(connectionString)
.WithKeyspaceProvider<FakeKeyspaceProvider>();
configurator.Configure(services);
provider = services.BuildServiceProvider();

// Assert
clusterConfigurator = provider.GetRequiredService<IClusterConfigurator>();
builder = Cluster.Builder();
clusterConfigurator.Configure(builder);
cluster = builder.Build();
cluster.Should().NotBeNull();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,6 @@ public void When_tenant_keyspaces_configured_manually()
act.Should().Throw<InvalidOperationException>();
}

class FakeKeyspaceProvider : ICassandraKeyspaceProvider
{
public string GetKeyspace(Id tenantId)
{
throw new NotImplementedException();
}
}

class FakeStorageConfigurationProvider : ICassandraTenantStorageConfigurationProvider
{
public CassandraStorageConfiguration GetConfiguration(Id tenanId)
Expand All @@ -135,4 +127,11 @@ public CassandraStorageConfiguration GetConfiguration(Id tenanId)
}
}
}
class FakeKeyspaceProvider : ICassandraKeyspaceProvider
{
public string GetKeyspace(Id tenantId)
{
throw new NotImplementedException();
}
}
}

0 comments on commit ff5f075

Please sign in to comment.