From eaa6068162880b1586d8576e2bf0c6b44db080d3 Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Sat, 18 Feb 2023 10:46:01 +0100 Subject: [PATCH] chore: Clean up EventStoreDb module (#792) --- Testcontainers.sln | 28 ++--- .../EventStoreDbBuilder.cs | 113 +++++++++--------- .../EventStoreDbConfiguration.cs | 2 +- .../EventStoreDbContainer.cs | 10 +- .../Testcontainers.EventStoreDb.csproj | 22 ++-- src/Testcontainers.EventStoreDb/Usings.cs | 2 +- .../EventStoreDbContainerTest.cs | 90 +++++++------- .../Testcontainers.EventStoreDb.Tests.csproj | 34 +++--- .../Usings.cs | 5 +- 9 files changed, 148 insertions(+), 158 deletions(-) diff --git a/Testcontainers.sln b/Testcontainers.sln index a39d90077..b101ad9f8 100644 --- a/Testcontainers.sln +++ b/Testcontainers.sln @@ -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}" @@ -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}" @@ -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 @@ -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 @@ -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 @@ -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} @@ -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} @@ -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 diff --git a/src/Testcontainers.EventStoreDb/EventStoreDbBuilder.cs b/src/Testcontainers.EventStoreDb/EventStoreDbBuilder.cs index 74cd23f9a..0d4ac1557 100644 --- a/src/Testcontainers.EventStoreDb/EventStoreDbBuilder.cs +++ b/src/Testcontainers.EventStoreDb/EventStoreDbBuilder.cs @@ -1,68 +1,67 @@ -namespace Testcontainers.EventStore +namespace Testcontainers.EventStoreDb; + +public sealed class EventStoreDbBuilder : ContainerBuilder { - public sealed class EventStoreDbBuilder : ContainerBuilder - { - 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; + + /// + /// Initializes a new instance of the class. + /// + public EventStoreDbBuilder() + : this(new EventStoreDbConfiguration()) + { + DockerResourceConfiguration = Init().DockerResourceConfiguration; + } - /// - /// Initializes a new instance of the class. - /// - public EventStoreDbBuilder() - : this(new EventStoreDbConfiguration()) - { - DockerResourceConfiguration = Init().DockerResourceConfiguration; - } + /// + /// Initializes a new instance of the class. + /// + /// The Docker resource configuration. + private EventStoreDbBuilder(EventStoreDbConfiguration dockerResourceConfiguration) + : base(dockerResourceConfiguration) + { + DockerResourceConfiguration = dockerResourceConfiguration; + } - /// - /// Initializes a new instance of the class. - /// - /// The Docker resource configuration. - private EventStoreDbBuilder(EventStoreDbConfiguration dockerResourceConfiguration) - : base(dockerResourceConfiguration) - { - DockerResourceConfiguration = dockerResourceConfiguration; - } + /// + protected override EventStoreDbConfiguration DockerResourceConfiguration { get; } - /// - protected override EventStoreDbConfiguration DockerResourceConfiguration { get; } - - /// - public override EventStoreDbContainer Build() - { - return new EventStoreDbContainer(DockerResourceConfiguration, TestcontainersSettings.Logger); - } + /// + public override EventStoreDbContainer Build() + { + return new EventStoreDbContainer(DockerResourceConfiguration, TestcontainersSettings.Logger); + } - /// - 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"); - } + /// + 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()); + } - /// - protected override EventStoreDbBuilder Clone(IContainerConfiguration resourceConfiguration) - { - return Merge(DockerResourceConfiguration, new EventStoreDbConfiguration(resourceConfiguration)); - } + /// + protected override EventStoreDbBuilder Clone(IContainerConfiguration resourceConfiguration) + { + return Merge(DockerResourceConfiguration, new EventStoreDbConfiguration(resourceConfiguration)); + } - /// - protected override EventStoreDbBuilder Clone(IResourceConfiguration resourceConfiguration) - { - return Merge(DockerResourceConfiguration, new EventStoreDbConfiguration(resourceConfiguration)); - } + /// + protected override EventStoreDbBuilder Clone(IResourceConfiguration resourceConfiguration) + { + return Merge(DockerResourceConfiguration, new EventStoreDbConfiguration(resourceConfiguration)); + } - /// - protected override EventStoreDbBuilder Merge(EventStoreDbConfiguration oldValue, EventStoreDbConfiguration newValue) - { - return new EventStoreDbBuilder(new EventStoreDbConfiguration(oldValue, newValue)); - } + /// + protected override EventStoreDbBuilder Merge(EventStoreDbConfiguration oldValue, EventStoreDbConfiguration newValue) + { + return new EventStoreDbBuilder(new EventStoreDbConfiguration(oldValue, newValue)); } } \ No newline at end of file diff --git a/src/Testcontainers.EventStoreDb/EventStoreDbConfiguration.cs b/src/Testcontainers.EventStoreDb/EventStoreDbConfiguration.cs index 44642a2a9..f9874b738 100644 --- a/src/Testcontainers.EventStoreDb/EventStoreDbConfiguration.cs +++ b/src/Testcontainers.EventStoreDb/EventStoreDbConfiguration.cs @@ -1,4 +1,4 @@ -namespace Testcontainers.EventStore; +namespace Testcontainers.EventStoreDb; /// [PublicAPI] diff --git a/src/Testcontainers.EventStoreDb/EventStoreDbContainer.cs b/src/Testcontainers.EventStoreDb/EventStoreDbContainer.cs index a3955b4dc..11f82ccb9 100644 --- a/src/Testcontainers.EventStoreDb/EventStoreDbContainer.cs +++ b/src/Testcontainers.EventStoreDb/EventStoreDbContainer.cs @@ -1,4 +1,4 @@ -namespace Testcontainers.EventStore; +namespace Testcontainers.EventStoreDb; /// [PublicAPI] @@ -15,13 +15,13 @@ public EventStoreDbContainer(EventStoreDbConfiguration configuration, ILogger lo } /// - /// Gets the EventStore connection string. + /// Gets the EventStoreDb connection string. /// - /// The EventStore connection string. + /// The EventStoreDb connection string. 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(); } -} +} \ No newline at end of file diff --git a/src/Testcontainers.EventStoreDb/Testcontainers.EventStoreDb.csproj b/src/Testcontainers.EventStoreDb/Testcontainers.EventStoreDb.csproj index 7dad7011b..37a1be0f7 100644 --- a/src/Testcontainers.EventStoreDb/Testcontainers.EventStoreDb.csproj +++ b/src/Testcontainers.EventStoreDb/Testcontainers.EventStoreDb.csproj @@ -1,12 +1,12 @@ - - netstandard2.0;netstandard2.1 - latest - - - - - - - - + + netstandard2.0;netstandard2.1 + latest + + + + + + + + \ No newline at end of file diff --git a/src/Testcontainers.EventStoreDb/Usings.cs b/src/Testcontainers.EventStoreDb/Usings.cs index 939d7c10d..bf2829a65 100644 --- a/src/Testcontainers.EventStoreDb/Usings.cs +++ b/src/Testcontainers.EventStoreDb/Usings.cs @@ -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; \ No newline at end of file diff --git a/tests/Testcontainers.EventStoreDb.Tests/EventStoreDbContainerTest.cs b/tests/Testcontainers.EventStoreDb.Tests/EventStoreDbContainerTest.cs index 4693ab087..81220148c 100644 --- a/tests/Testcontainers.EventStoreDb.Tests/EventStoreDbContainerTest.cs +++ b/tests/Testcontainers.EventStoreDb.Tests/EventStoreDbContainerTest.cs @@ -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()); + + // 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); + } +} \ No newline at end of file diff --git a/tests/Testcontainers.EventStoreDb.Tests/Testcontainers.EventStoreDb.Tests.csproj b/tests/Testcontainers.EventStoreDb.Tests/Testcontainers.EventStoreDb.Tests.csproj index 590a976fd..18db7cab5 100644 --- a/tests/Testcontainers.EventStoreDb.Tests/Testcontainers.EventStoreDb.Tests.csproj +++ b/tests/Testcontainers.EventStoreDb.Tests/Testcontainers.EventStoreDb.Tests.csproj @@ -1,18 +1,18 @@ - - net6.0 - false - false - - - - - - - - - - - - - + + net6.0 + false + false + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/Testcontainers.EventStoreDb.Tests/Usings.cs b/tests/Testcontainers.EventStoreDb.Tests/Usings.cs index f9962bcf3..8660e2560 100644 --- a/tests/Testcontainers.EventStoreDb.Tests/Usings.cs +++ b/tests/Testcontainers.EventStoreDb.Tests/Usings.cs @@ -1,7 +1,6 @@ global using System; global using System.Linq; -global using System.Text.Json; -global using System.Threading; global using System.Threading.Tasks; +global using DotNet.Testcontainers.Commons; global using EventStore.Client; -global using Xunit; +global using Xunit; \ No newline at end of file