From c182d4568e94673e612c14d61b157e533c589399 Mon Sep 17 00:00:00 2001 From: Tom Longhurst <30480171+thomhurst@users.noreply.github.com> Date: Fri, 2 May 2025 15:19:00 +0100 Subject: [PATCH] Automate Start/Stop on ContainerFixture when using `[ClassDataSource<>]` --- .../ChaserCheckpointSeedingTests.cs | 6 ------ test/Kurrent.Replicator.Tests/CustomPartitionerTests.cs | 6 ------ test/Kurrent.Replicator.Tests/Fixtures/ContainerFixture.cs | 7 ++++--- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/test/Kurrent.Replicator.Tests/ChaserCheckpointSeedingTests.cs b/test/Kurrent.Replicator.Tests/ChaserCheckpointSeedingTests.cs index 5a5a87ac..8f932fe4 100644 --- a/test/Kurrent.Replicator.Tests/ChaserCheckpointSeedingTests.cs +++ b/test/Kurrent.Replicator.Tests/ChaserCheckpointSeedingTests.cs @@ -29,12 +29,6 @@ public ChaserCheckpointSeedingTests(ContainerFixture fixture) { .ForContext(); } - [Before(Test)] - public async Task Start() => await _fixture.StartContainers(); - - [After(Test)] - public async Task Stop() => await _fixture.StopContainers(); - [Test] public async Task Verify() { var v5DataPath = _fixture.V5DataPath; diff --git a/test/Kurrent.Replicator.Tests/CustomPartitionerTests.cs b/test/Kurrent.Replicator.Tests/CustomPartitionerTests.cs index b7d5b468..e69943a9 100644 --- a/test/Kurrent.Replicator.Tests/CustomPartitionerTests.cs +++ b/test/Kurrent.Replicator.Tests/CustomPartitionerTests.cs @@ -31,12 +31,6 @@ public ValuePartitionerTests(ContainerFixture fixture) { .ForContext(); } - [Before(Test)] - public async Task Start() => await _fixture.StartContainers(); - - [After(Test)] - public async Task Stop() => await _fixture.StopContainers(); - [Test] public async Task ShouldKeepOrderWithinPartition() { var checkpointStore = new CheckpointStore(); diff --git a/test/Kurrent.Replicator.Tests/Fixtures/ContainerFixture.cs b/test/Kurrent.Replicator.Tests/Fixtures/ContainerFixture.cs index 97f280b9..27f9777e 100644 --- a/test/Kurrent.Replicator.Tests/Fixtures/ContainerFixture.cs +++ b/test/Kurrent.Replicator.Tests/Fixtures/ContainerFixture.cs @@ -3,15 +3,16 @@ using EventStore.Client; using EventStore.ClientAPI; using Testcontainers.EventStoreDb; +using TUnit.Core.Interfaces; namespace Kurrent.Replicator.Tests.Fixtures; -public class ContainerFixture { +public class ContainerFixture : IAsyncInitializer, IAsyncDisposable { EventStoreDbContainer _kurrentDbContainer; IContainer _eventStoreContainer; public DirectoryInfo V5DataPath { get; private set; } - public async Task StartContainers() { + public async Task InitializeAsync() { V5DataPath = Directory.CreateTempSubdirectory(); _kurrentDbContainer = BuildV23Container(); _eventStoreContainer = BuildV5Container(V5DataPath); @@ -21,7 +22,7 @@ public async Task StartContainers() { await Task.Delay(TimeSpan.FromSeconds(2)); // give it some time to spin up } - public async Task StopContainers() { + public async ValueTask DisposeAsync() { await Task.WhenAll(_kurrentDbContainer.StopAsync(), _eventStoreContainer.StopAsync()); await _eventStoreContainer.DisposeAsync(); await _kurrentDbContainer.DisposeAsync();