Skip to content

Commit

Permalink
chore: Clean up EventStoreDb module (#792)
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn authored Feb 18, 2023
1 parent 955d709 commit eaa6068
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 158 deletions.
28 changes: 14 additions & 14 deletions Testcontainers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.DynamoDb", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Elasticsearch", "src\Testcontainers.Elasticsearch\Testcontainers.Elasticsearch.csproj", "{641DDEA5-B6E0-41E6-BA11-7A28C0913127}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.EventStoreDb", "src\Testcontainers.EventStoreDb\Testcontainers.EventStoreDb.csproj", "{84D707E0-C9FA-4327-85DC-0AFEBEA73572}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.LocalStack", "src\Testcontainers.LocalStack\Testcontainers.LocalStack.csproj", "{3792268A-EF08-4569-8118-991E08FD61C4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.MariaDb", "src\Testcontainers.MariaDb\Testcontainers.MariaDb.csproj", "{4B204EB3-C478-422E-9B6F-62DF3871291A}"
Expand Down Expand Up @@ -53,6 +55,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.DynamoDb.Tes
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Elasticsearch.Tests", "tests\Testcontainers.Elasticsearch.Tests\Testcontainers.Elasticsearch.Tests.csproj", "{DD5B3678-468F-4D73-AECE-705E3D66CD43}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.EventStoreDb.Tests", "tests\Testcontainers.EventStoreDb.Tests\Testcontainers.EventStoreDb.Tests.csproj", "{64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.LocalStack.Tests", "tests\Testcontainers.LocalStack.Tests\Testcontainers.LocalStack.Tests.csproj", "{728CBE16-1D52-4F84-AF01-7229E6013512}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.MariaDb.Tests", "tests\Testcontainers.MariaDb.Tests\Testcontainers.MariaDb.Tests.csproj", "{7F0AE083-9DB8-4BD4-91F7-C199DCC7301D}"
Expand Down Expand Up @@ -85,10 +89,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.ResourceReap
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.Tests", "tests\Testcontainers.Tests\Testcontainers.Tests.csproj", "{27CDB869-A150-4593-958F-6F26E5391E7C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.EventStoreDb", "src\Testcontainers.EventStoreDb\Testcontainers.EventStoreDb.csproj", "{84D707E0-C9FA-4327-85DC-0AFEBEA73572}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testcontainers.EventStoreDb.Tests", "tests\Testcontainers.EventStoreDb.Tests\Testcontainers.EventStoreDb.Tests.csproj", "{64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -110,6 +110,10 @@ Global
{641DDEA5-B6E0-41E6-BA11-7A28C0913127}.Debug|Any CPU.Build.0 = Debug|Any CPU
{641DDEA5-B6E0-41E6-BA11-7A28C0913127}.Release|Any CPU.ActiveCfg = Release|Any CPU
{641DDEA5-B6E0-41E6-BA11-7A28C0913127}.Release|Any CPU.Build.0 = Release|Any CPU
{84D707E0-C9FA-4327-85DC-0AFEBEA73572}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{84D707E0-C9FA-4327-85DC-0AFEBEA73572}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84D707E0-C9FA-4327-85DC-0AFEBEA73572}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84D707E0-C9FA-4327-85DC-0AFEBEA73572}.Release|Any CPU.Build.0 = Release|Any CPU
{3792268A-EF08-4569-8118-991E08FD61C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3792268A-EF08-4569-8118-991E08FD61C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3792268A-EF08-4569-8118-991E08FD61C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -178,6 +182,10 @@ Global
{DD5B3678-468F-4D73-AECE-705E3D66CD43}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DD5B3678-468F-4D73-AECE-705E3D66CD43}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DD5B3678-468F-4D73-AECE-705E3D66CD43}.Release|Any CPU.Build.0 = Release|Any CPU
{64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0}.Release|Any CPU.Build.0 = Release|Any CPU
{728CBE16-1D52-4F84-AF01-7229E6013512}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{728CBE16-1D52-4F84-AF01-7229E6013512}.Debug|Any CPU.Build.0 = Debug|Any CPU
{728CBE16-1D52-4F84-AF01-7229E6013512}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -242,19 +250,12 @@ Global
{27CDB869-A150-4593-958F-6F26E5391E7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27CDB869-A150-4593-958F-6F26E5391E7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27CDB869-A150-4593-958F-6F26E5391E7C}.Release|Any CPU.Build.0 = Release|Any CPU
{84D707E0-C9FA-4327-85DC-0AFEBEA73572}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{84D707E0-C9FA-4327-85DC-0AFEBEA73572}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84D707E0-C9FA-4327-85DC-0AFEBEA73572}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84D707E0-C9FA-4327-85DC-0AFEBEA73572}.Release|Any CPU.Build.0 = Release|Any CPU
{64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{DCECB1F6-D9AA-431F-AE42-25D56B9E7DFC} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{2EAFA567-9F68-4C52-9DBC-8F3EC11BB2CE} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{641DDEA5-B6E0-41E6-BA11-7A28C0913127} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{84D707E0-C9FA-4327-85DC-0AFEBEA73572} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{3792268A-EF08-4569-8118-991E08FD61C4} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{4B204EB3-C478-422E-9B6F-62DF3871291A} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{1266E1E6-5CEF-4161-8B45-83282455746E} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
Expand All @@ -272,6 +273,7 @@ Global
{E4520FB1-4466-4DCA-AD08-4075102C68D3} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{101515E6-74C1-40F9-85C8-871F742A378D} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{DD5B3678-468F-4D73-AECE-705E3D66CD43} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{728CBE16-1D52-4F84-AF01-7229E6013512} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{7F0AE083-9DB8-4BD4-91F7-C199DCC7301D} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{5DB1F35F-B714-4B62-84BE-16A33084D3E1} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
Expand All @@ -288,7 +290,5 @@ Global
{31EE94A0-E721-4073-B6F1-DD912D004DEF} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{9E8E6AA5-65D1-498F-BEAB-BA34723A0050} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{27CDB869-A150-4593-958F-6F26E5391E7C} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
{84D707E0-C9FA-4327-85DC-0AFEBEA73572} = {673F23AE-7694-4BB9-ABD4-136D6C13634E}
{64F8E9B9-78FD-4E13-BDDF-0340E2D4E1D0} = {7164F1FB-7F24-444A-ACD2-2C329C2B3CCF}
EndGlobalSection
EndGlobal
113 changes: 56 additions & 57 deletions src/Testcontainers.EventStoreDb/EventStoreDbBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,68 +1,67 @@
namespace Testcontainers.EventStore
namespace Testcontainers.EventStoreDb;

public sealed class EventStoreDbBuilder : ContainerBuilder<EventStoreDbBuilder, EventStoreDbContainer, EventStoreDbConfiguration>
{
public sealed class EventStoreDbBuilder : ContainerBuilder<EventStoreDbBuilder, EventStoreDbContainer, EventStoreDbConfiguration>
{
private const string EventStoreImage = "eventstore/eventstore:21.2.0-buster-slim";
public const string EventStoreDbImage = "eventstore/eventstore:22.10.1-buster-slim";

public const ushort EventStorePort = 2113;
public const ushort EventStoreDbPort = 2113;

/// <summary>
/// Initializes a new instance of the <see cref="EventStoreDbBuilder" /> class.
/// </summary>
public EventStoreDbBuilder()
: this(new EventStoreDbConfiguration())
{
DockerResourceConfiguration = Init().DockerResourceConfiguration;
}

/// <summary>
/// Initializes a new instance of the <see cref="EventStoreDbBuilder" /> class.
/// </summary>
public EventStoreDbBuilder()
: this(new EventStoreDbConfiguration())
{
DockerResourceConfiguration = Init().DockerResourceConfiguration;
}
/// <summary>
/// Initializes a new instance of the <see cref="EventStoreDbBuilder" /> class.
/// </summary>
/// <param name="dockerResourceConfiguration">The Docker resource configuration.</param>
private EventStoreDbBuilder(EventStoreDbConfiguration dockerResourceConfiguration)
: base(dockerResourceConfiguration)
{
DockerResourceConfiguration = dockerResourceConfiguration;
}

/// <summary>
/// Initializes a new instance of the <see cref="EventStoreDbBuilder" /> class.
/// </summary>
/// <param name="dockerResourceConfiguration">The Docker resource configuration.</param>
private EventStoreDbBuilder(EventStoreDbConfiguration dockerResourceConfiguration)
: base(dockerResourceConfiguration)
{
DockerResourceConfiguration = dockerResourceConfiguration;
}
/// <inheritdoc />
protected override EventStoreDbConfiguration DockerResourceConfiguration { get; }

/// <inheritdoc />
protected override EventStoreDbConfiguration DockerResourceConfiguration { get; }

/// <inheritdoc />
public override EventStoreDbContainer Build()
{
return new EventStoreDbContainer(DockerResourceConfiguration, TestcontainersSettings.Logger);
}
/// <inheritdoc />
public override EventStoreDbContainer Build()
{
return new EventStoreDbContainer(DockerResourceConfiguration, TestcontainersSettings.Logger);
}

/// <inheritdoc />
protected override EventStoreDbBuilder Init()
{
return base.Init()
.WithImage(EventStoreImage)
.WithPortBinding(EventStorePort, true)
.WithWaitStrategy(Wait.ForUnixContainer().UntilContainerIsHealthy())
.WithEnvironment("EVENTSTORE_CLUSTER_SIZE", "1")
.WithEnvironment("EVENTSTORE_RUN_PROJECTIONS", "All")
.WithEnvironment("EVENTSTORE_START_STANDARD_PROJECTIONS", "true")
.WithEnvironment("EVENTSTORE_INSECURE", "true");
}
/// <inheritdoc />
protected override EventStoreDbBuilder Init()
{
return base.Init()
.WithImage(EventStoreDbImage)
.WithPortBinding(EventStoreDbPort, true)
.WithEnvironment("EVENTSTORE_CLUSTER_SIZE", "1")
.WithEnvironment("EVENTSTORE_RUN_PROJECTIONS", "All")
.WithEnvironment("EVENTSTORE_START_STANDARD_PROJECTIONS", "true")
.WithEnvironment("EVENTSTORE_INSECURE", "true")
.WithWaitStrategy(Wait.ForUnixContainer().UntilContainerIsHealthy());
}

/// <inheritdoc />
protected override EventStoreDbBuilder Clone(IContainerConfiguration resourceConfiguration)
{
return Merge(DockerResourceConfiguration, new EventStoreDbConfiguration(resourceConfiguration));
}
/// <inheritdoc />
protected override EventStoreDbBuilder Clone(IContainerConfiguration resourceConfiguration)
{
return Merge(DockerResourceConfiguration, new EventStoreDbConfiguration(resourceConfiguration));
}

/// <inheritdoc />
protected override EventStoreDbBuilder Clone(IResourceConfiguration<CreateContainerParameters> resourceConfiguration)
{
return Merge(DockerResourceConfiguration, new EventStoreDbConfiguration(resourceConfiguration));
}
/// <inheritdoc />
protected override EventStoreDbBuilder Clone(IResourceConfiguration<CreateContainerParameters> resourceConfiguration)
{
return Merge(DockerResourceConfiguration, new EventStoreDbConfiguration(resourceConfiguration));
}

/// <inheritdoc />
protected override EventStoreDbBuilder Merge(EventStoreDbConfiguration oldValue, EventStoreDbConfiguration newValue)
{
return new EventStoreDbBuilder(new EventStoreDbConfiguration(oldValue, newValue));
}
/// <inheritdoc />
protected override EventStoreDbBuilder Merge(EventStoreDbConfiguration oldValue, EventStoreDbConfiguration newValue)
{
return new EventStoreDbBuilder(new EventStoreDbConfiguration(oldValue, newValue));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Testcontainers.EventStore;
namespace Testcontainers.EventStoreDb;

/// <inheritdoc cref="ContainerConfiguration" />
[PublicAPI]
Expand Down
10 changes: 5 additions & 5 deletions src/Testcontainers.EventStoreDb/EventStoreDbContainer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Testcontainers.EventStore;
namespace Testcontainers.EventStoreDb;

/// <inheritdoc cref="DockerContainer" />
[PublicAPI]
Expand All @@ -15,13 +15,13 @@ public EventStoreDbContainer(EventStoreDbConfiguration configuration, ILogger lo
}

/// <summary>
/// Gets the EventStore connection string.
/// Gets the EventStoreDb connection string.
/// </summary>
/// <returns>The EventStore connection string.</returns>
/// <returns>The EventStoreDb connection string.</returns>
public string GetConnectionString()
{
var endpoint = new UriBuilder("esdb", Hostname, GetMappedPublicPort(EventStoreDbBuilder.EventStorePort));
var endpoint = new UriBuilder("esdb", Hostname, GetMappedPublicPort(EventStoreDbBuilder.EventStoreDbPort));
endpoint.Query = "tls=false";
return endpoint.ToString();
}
}
}
22 changes: 11 additions & 11 deletions src/Testcontainers.EventStoreDb/Testcontainers.EventStoreDb.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)src/Testcontainers/Testcontainers.csproj" />
</ItemGroup>
</Project>
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(SolutionDir)src/Testcontainers/Testcontainers.csproj"/>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Testcontainers.EventStoreDb/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
global using DotNet.Testcontainers.Configurations;
global using DotNet.Testcontainers.Containers;
global using JetBrains.Annotations;
global using Microsoft.Extensions.Logging;
global using Microsoft.Extensions.Logging;
Original file line number Diff line number Diff line change
@@ -1,52 +1,44 @@
namespace Testcontainers.EventStore;
namespace Testcontainers.EventStoreDb;

public sealed class EventStoreDbContainerTest : IAsyncLifetime
{
private readonly EventStoreDbContainer _eventStoreContainer = new EventStoreDbBuilder().Build();

public Task InitializeAsync()
{
return _eventStoreContainer.StartAsync();
}

public Task DisposeAsync()
{
return _eventStoreContainer.DisposeAsync().AsTask();
}

[Fact]
public async Task ConnectionEstablished()
{
// Given
var settings = EventStoreClientSettings.Create(_eventStoreContainer.GetConnectionString());
using EventStoreClient connection = new EventStoreClient(settings);

// When
var tokenSource = new CancellationTokenSource();
var cancellationToken = tokenSource.Token;

var evt = new { EntityId = Guid.NewGuid().ToString("N"), ImportantData = "I wrote my first event!" };

var eventData = new EventData(
Uuid.NewUuid(),
"TestEvent",
JsonSerializer.SerializeToUtf8Bytes(evt));

await connection.AppendToStreamAsync(
"some-stream",
StreamState.Any,
new[] { eventData },
cancellationToken: cancellationToken);

var result = connection.ReadStreamAsync(
Direction.Forwards,
"some-stream",
StreamPosition.Start,
cancellationToken: cancellationToken);

var events = await result.ToListAsync(cancellationToken);

// Then
Assert.NotNull(events);
}
}
private readonly EventStoreDbContainer _eventStoreDbContainer = new EventStoreDbBuilder().Build();

public Task InitializeAsync()
{
return _eventStoreDbContainer.StartAsync();
}

public Task DisposeAsync()
{
return _eventStoreDbContainer.DisposeAsync().AsTask();
}

[Fact]
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
public async Task ReadStreamReturnsEvent()
{
// Given
const string eventType = "some-event";

const string streamName = "some-stream";

var settings = EventStoreClientSettings.Create(_eventStoreDbContainer.GetConnectionString());

using var client = new EventStoreClient(settings);

var eventData = new EventData(Uuid.NewUuid(), eventType, Array.Empty<byte>());

// When
_ = await client.AppendToStreamAsync(streamName, StreamState.NoStream, new[] { eventData })
.ConfigureAwait(false);

var resolvedEvents = client.ReadStreamAsync(Direction.Forwards, streamName, StreamPosition.Start);

var resolvedEvent = await resolvedEvents.FirstAsync()
.ConfigureAwait(false);

// Then
Assert.Equal(eventType, resolvedEvent.Event.EventType);
}
}
Loading

0 comments on commit eaa6068

Please sign in to comment.