diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index dd52e133e..267efc5a4 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -26,7 +26,7 @@ jobs: # name: Setup .NET # uses: actions/setup-dotnet@v4 # with: -# dotnet-version: '8.0' +# dotnet-version: '9.0.x' - name: Run tests run: dotnet test --framework net9.0 diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index f1ad36c20..7f8e5db2a 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -8,7 +8,8 @@ on: jobs: event_file: name: "Event File" - runs-on: ubuntu-latest +# runs-on: ubuntu-latest + runs-on: self-hosted steps: - name: Upload uses: actions/upload-artifact@v4 @@ -17,10 +18,12 @@ jobs: path: ${{ github.event_path }} build-and-test: name: "Build and test" - runs-on: ubuntu-latest +# runs-on: ubuntu-latest + runs-on: self-hosted env: NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages TC_CLOUD_TOKEN: ${{ secrets.TC_TOKEN }} + DOTNET_INSTALL_DIR: ${{ github.workspace }}/.dotnet steps: - name: Checkout diff --git a/Directory.Packages.props b/Directory.Packages.props index 7375ed1e6..04fd47ca0 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -9,11 +9,11 @@ 8.0.6 - 4.0.0 + 4.1.0 9.0.1 - 0.4.74 + 0.4.105 @@ -44,7 +44,7 @@ - + @@ -60,11 +60,10 @@ - + - @@ -72,10 +71,9 @@ - + - @@ -83,6 +81,8 @@ + + @@ -92,10 +92,10 @@ - + - - + + diff --git a/src/Core/test/Eventuous.Tests.Persistence.Base/Eventuous.Tests.Persistence.Base.csproj b/src/Core/test/Eventuous.Tests.Persistence.Base/Eventuous.Tests.Persistence.Base.csproj index 20223ed8d..0805456be 100644 --- a/src/Core/test/Eventuous.Tests.Persistence.Base/Eventuous.Tests.Persistence.Base.csproj +++ b/src/Core/test/Eventuous.Tests.Persistence.Base/Eventuous.Tests.Persistence.Base.csproj @@ -6,12 +6,11 @@ - + - diff --git a/src/Core/test/Eventuous.Tests.Persistence.Base/Fixtures/DomainFixture.cs b/src/Core/test/Eventuous.Tests.Persistence.Base/Fixtures/DomainFixture.cs index 5483f9560..c6c6f35b8 100644 --- a/src/Core/test/Eventuous.Tests.Persistence.Base/Fixtures/DomainFixture.cs +++ b/src/Core/test/Eventuous.Tests.Persistence.Base/Fixtures/DomainFixture.cs @@ -1,18 +1,17 @@ -using AutoFixture; +using Bogus; using Eventuous.Sut.App; -using NodaTime; namespace Eventuous.Tests.Persistence.Base.Fixtures; public static class DomainFixture { static DomainFixture() => TypeMap.RegisterKnownEventTypes(typeof(DomainFixture).Assembly); + + static Faker Faker => new Faker() + .RuleFor(x => x.BookingId, _ => Guid.NewGuid().ToString("N")) + .RuleFor(x => x.RoomId, _ => Guid.NewGuid().ToString("N")) + .RuleFor(x => x.Price, f => f.Random.Number(50, 200)) + .RuleFor(x => x.CheckIn, f => f.Noda().LocalDate.Soon()) + .RuleFor(x => x.CheckOut, (f, c) => c.CheckIn.PlusDays(f.Random.Number(1, 5))); - public static Commands.ImportBooking CreateImportBooking(IFixture auto) { - var from = auto.Create(); - - return auto.Build() - .With(x => x.CheckIn, from) - .With(x => x.CheckOut, from.PlusDays(2)) - .Create(); - } + public static Commands.ImportBooking CreateImportBooking() => Faker.Generate(); } diff --git a/src/Core/test/Eventuous.Tests.Persistence.Base/Fixtures/Helpers.cs b/src/Core/test/Eventuous.Tests.Persistence.Base/Fixtures/Helpers.cs index 3a22e4c0a..6430902e5 100644 --- a/src/Core/test/Eventuous.Tests.Persistence.Base/Fixtures/Helpers.cs +++ b/src/Core/test/Eventuous.Tests.Persistence.Base/Fixtures/Helpers.cs @@ -1,17 +1,16 @@ -using AutoFixture; using static Eventuous.Sut.App.Commands; using static Eventuous.Sut.Domain.BookingEvents; namespace Eventuous.Tests.Persistence.Base.Fixtures; public static class Helpers { - public static StreamName GetStreamName(this StoreFixtureBase fixture) => new(fixture.Auto.Create()); + public static StreamName GetStreamName() => new(Guid.NewGuid().ToString()); - public static BookingImported CreateEvent(this StoreFixtureBase fixture) => ToEvent(DomainFixture.CreateImportBooking(fixture.Auto)); + public static BookingImported CreateEvent() => ToEvent(DomainFixture.CreateImportBooking()); public static IEnumerable CreateEvents(this StoreFixtureBase fixture, int count) { for (var i = 0; i < count; i++) { - yield return CreateEvent(fixture); + yield return CreateEvent(); } } diff --git a/src/Core/test/Eventuous.Tests.Persistence.Base/Fixtures/StoreFixtureBase.cs b/src/Core/test/Eventuous.Tests.Persistence.Base/Fixtures/StoreFixtureBase.cs index 2769af31b..caab387ac 100644 --- a/src/Core/test/Eventuous.Tests.Persistence.Base/Fixtures/StoreFixtureBase.cs +++ b/src/Core/test/Eventuous.Tests.Persistence.Base/Fixtures/StoreFixtureBase.cs @@ -1,10 +1,8 @@ using System.Text.RegularExpressions; -using AutoFixture; using Bogus; using DotNet.Testcontainers.Containers; using Eventuous.TestHelpers; using Eventuous.TestHelpers.TUnit.Logging; -using MicroElements.AutoFixture.NodaTime; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using TUnit.Core.Interfaces; @@ -15,7 +13,6 @@ public interface IStartableFixture : IAsyncInitializer, IAsyncDisposable; public abstract class StoreFixtureBase { public IEventStore EventStore { get; protected private set; } = null!; - public IFixture Auto { get; } = new Fixture().Customize(new NodaTimeCustomization()); protected static Faker Faker { get; } = new(); protected ServiceProvider Provider { get; set; } = null!; protected bool AutoStart { get; init; } = true; diff --git a/src/Core/test/Eventuous.Tests.Persistence.Base/Store/Append.cs b/src/Core/test/Eventuous.Tests.Persistence.Base/Store/Append.cs index 9d24e4e92..9381647da 100644 --- a/src/Core/test/Eventuous.Tests.Persistence.Base/Store/Append.cs +++ b/src/Core/test/Eventuous.Tests.Persistence.Base/Store/Append.cs @@ -14,8 +14,8 @@ protected StoreAppendTests(T fixture) { [Test] [Category("Store")] public async Task ShouldAppendToNoStream() { - var evt = _fixture.CreateEvent(); - var streamName = _fixture.GetStreamName(); + var evt = Helpers.CreateEvent(); + var streamName = Helpers.GetStreamName(); var result = await _fixture.AppendEvent(streamName, evt, ExpectedStreamVersion.NoStream); await Assert.That(result.NextExpectedVersion).IsEqualTo(0); @@ -24,12 +24,12 @@ public async Task ShouldAppendToNoStream() { [Test] [Category("Store")] public async Task ShouldAppendOneByOne() { - var evt = _fixture.CreateEvent(); - var stream = _fixture.GetStreamName(); + var evt = Helpers.CreateEvent(); + var stream = Helpers.GetStreamName(); var result = await _fixture.AppendEvent(stream, evt, ExpectedStreamVersion.NoStream); - evt = _fixture.CreateEvent(); + evt = Helpers.CreateEvent(); var version = new ExpectedStreamVersion(result.NextExpectedVersion); result = await _fixture.AppendEvent(stream, evt, version); @@ -40,12 +40,12 @@ public async Task ShouldAppendOneByOne() { [Test] [Category("Store")] public async Task ShouldFailOnWrongVersionNoStream() { - var evt = _fixture.CreateEvent(); - var stream = _fixture.GetStreamName(); + var evt = Helpers.CreateEvent(); + var stream = Helpers.GetStreamName(); await _fixture.AppendEvent(stream, evt, ExpectedStreamVersion.NoStream); - evt = _fixture.CreateEvent(); + evt = Helpers.CreateEvent(); await Assert.That(() => _fixture.AppendEvent(stream, evt, ExpectedStreamVersion.NoStream)).Throws(); } @@ -53,12 +53,12 @@ public async Task ShouldFailOnWrongVersionNoStream() { [Test] [Category("Store")] public async Task ShouldFailOnWrongVersion() { - var evt = _fixture.CreateEvent(); - var stream = _fixture.GetStreamName(); + var evt = Helpers.CreateEvent(); + var stream = Helpers.GetStreamName(); await _fixture.AppendEvent(stream, evt, ExpectedStreamVersion.NoStream); - evt = _fixture.CreateEvent(); + evt = Helpers.CreateEvent(); await Assert.That(() => _fixture.AppendEvent(stream, evt, new(3))).Throws(); } @@ -67,12 +67,12 @@ public async Task ShouldFailOnWrongVersion() { [Test] [Category("Store")] public async Task ShouldFailOnWrongVersionWithOptimisticConcurrencyException() { - var evt = _fixture.CreateEvent(); - var stream = _fixture.GetStreamName(); + var evt = Helpers.CreateEvent(); + var stream = Helpers.GetStreamName(); await _fixture.AppendEvent(stream, evt, ExpectedStreamVersion.NoStream); - evt = _fixture.CreateEvent(); + evt = Helpers.CreateEvent(); await Assert.That(() => _fixture.StoreChanges(stream, evt, new(3))).Throws(); } diff --git a/src/Core/test/Eventuous.Tests.Persistence.Base/Store/OtherMethods.cs b/src/Core/test/Eventuous.Tests.Persistence.Base/Store/OtherMethods.cs index 439885867..e7f8901f7 100644 --- a/src/Core/test/Eventuous.Tests.Persistence.Base/Store/OtherMethods.cs +++ b/src/Core/test/Eventuous.Tests.Persistence.Base/Store/OtherMethods.cs @@ -14,8 +14,8 @@ protected StoreOtherOpsTests(T fixture) { [Test] [Category("Store")] public async Task StreamShouldExist(CancellationToken cancellationToken) { - var evt = _fixture.CreateEvent(); - var streamName = _fixture.GetStreamName(); + var evt = Helpers.CreateEvent(); + var streamName = Helpers.GetStreamName(); await _fixture.AppendEvent(streamName, evt, ExpectedStreamVersion.NoStream); var exists = await _fixture.EventStore.StreamExists(streamName, cancellationToken); @@ -25,7 +25,7 @@ public async Task StreamShouldExist(CancellationToken cancellationToken) { [Test] [Category("Store")] public async Task StreamShouldNotExist(CancellationToken cancellationToken) { - var streamName = _fixture.GetStreamName(); + var streamName = Helpers.GetStreamName(); var exists = await _fixture.EventStore.StreamExists(streamName, cancellationToken); await Assert.That(exists).IsFalse(); } diff --git a/src/Core/test/Eventuous.Tests.Persistence.Base/Store/Read.cs b/src/Core/test/Eventuous.Tests.Persistence.Base/Store/Read.cs index 8abb980b5..b80ae2af2 100644 --- a/src/Core/test/Eventuous.Tests.Persistence.Base/Store/Read.cs +++ b/src/Core/test/Eventuous.Tests.Persistence.Base/Store/Read.cs @@ -17,8 +17,8 @@ protected StoreReadTests(T fixture) { [Test] [Category("Store")] public async Task ShouldReadOne(CancellationToken cancellationToken) { - var evt = _fixture.CreateEvent(); - var streamName = _fixture.GetStreamName(); + var evt = Helpers.CreateEvent(); + var streamName = Helpers.GetStreamName(); await _fixture.AppendEvent(streamName, evt, ExpectedStreamVersion.NoStream); var result = await _fixture.EventStore.ReadEvents(streamName, StreamReadPosition.Start, 100, cancellationToken); @@ -30,7 +30,7 @@ public async Task ShouldReadOne(CancellationToken cancellationToken) { [Category("Store")] public async Task ShouldReadMany(CancellationToken cancellationToken) { object[] events = _fixture.CreateEvents(20).ToArray(); - var streamName = _fixture.GetStreamName(); + var streamName = Helpers.GetStreamName(); await _fixture.AppendEvents(streamName, events, ExpectedStreamVersion.NoStream); var result = await _fixture.EventStore.ReadEvents(streamName, StreamReadPosition.Start, 100, cancellationToken); @@ -42,12 +42,12 @@ public async Task ShouldReadMany(CancellationToken cancellationToken) { [Category("Store")] public async Task ShouldReadTail(CancellationToken cancellationToken) { object[] events = _fixture.CreateEvents(20).ToArray(); - var streamName = _fixture.GetStreamName(); + var streamName = Helpers.GetStreamName(); await _fixture.AppendEvents(streamName, events, ExpectedStreamVersion.NoStream); var result = await _fixture.EventStore.ReadEvents(streamName, new(10), 100, cancellationToken); var expected = events.Skip(10); - var actual = result.Select(x => x.Payload); + var actual = result.Select(x => x.Payload!); await Assert.That(actual).IsEquivalentTo(expected); } @@ -55,7 +55,7 @@ public async Task ShouldReadTail(CancellationToken cancellationToken) { [Category("Store")] public async Task ShouldReadHead(CancellationToken cancellationToken) { object[] events = _fixture.CreateEvents(20).ToArray(); - var streamName = _fixture.GetStreamName(); + var streamName = Helpers.GetStreamName(); await _fixture.AppendEvents(streamName, events, ExpectedStreamVersion.NoStream); var result = await _fixture.EventStore.ReadEvents(streamName, StreamReadPosition.Start, 10, cancellationToken); @@ -68,8 +68,8 @@ public async Task ShouldReadHead(CancellationToken cancellationToken) { [Test] [Category("Store")] public async Task ShouldReadMetadata(CancellationToken cancellationToken) { - var evt = _fixture.CreateEvent(); - var streamName = _fixture.GetStreamName(); + var evt = Helpers.CreateEvent(); + var streamName = Helpers.GetStreamName(); await _fixture.AppendEvent(streamName, evt, ExpectedStreamVersion.NoStream, new() { { "Key1", "Value1" }, { "Key2", "Value2" } }); diff --git a/src/Core/test/Eventuous.Tests.Persistence.Base/Store/TieredStoreTests.cs b/src/Core/test/Eventuous.Tests.Persistence.Base/Store/TieredStoreTests.cs index 46d84745f..13d7802ef 100644 --- a/src/Core/test/Eventuous.Tests.Persistence.Base/Store/TieredStoreTests.cs +++ b/src/Core/test/Eventuous.Tests.Persistence.Base/Store/TieredStoreTests.cs @@ -1,5 +1,6 @@ -using AutoFixture; +using Bogus; using DotNet.Testcontainers.Containers; +using Eventuous.TestHelpers.TUnit; using Eventuous.Tests.Persistence.Base.Fixtures; using JetBrains.Annotations; @@ -11,7 +12,7 @@ protected async Task Should_load_hot_and_archive() { var store = _storeFixture.EventStore; var archive = new ArchiveStore(_storeFixture.EventStore); - var testEvents = _fixture.CreateMany(count).ToArray(); + var testEvents = TestEventForTiers.CreateMany(count).ToArray(); var stream = new StreamName($"Test-{Guid.NewGuid():N}"); await store.Store(stream, ExpectedStreamVersion.NoStream, testEvents); @@ -21,14 +22,13 @@ protected async Task Should_load_hot_and_archive() { var combined = new TieredEventReader(store, archive); var loaded = (await combined.ReadStream(stream, StreamReadPosition.Start)).ToArray(); - var actual = loaded.Select(x => (TestEventForTiers)x.Payload!).ToArray(); - await Assert.That(actual).IsEquivalentTo(testEvents); + var actual = loaded.Select(x => (TestEventForTiers)x.Payload!); + await Assert.That(actual).CollectionEquivalentTo(testEvents); await Assert.That(loaded.Take(50).Select(x => x.FromArchive)).DoesNotContain(false); await Assert.That(loaded.Skip(50).Select(x => x.FromArchive)).DoesNotContain(true); } - readonly Fixture _fixture = new(); readonly StoreFixtureBase _storeFixture; protected TieredStoreTestsBase(StoreFixtureBase storeFixture) { @@ -58,4 +58,8 @@ CancellationToken cancellationToken [UsedImplicitly] record TestEventForTiers(string Data, int Number) { public const string TypeName = "test-event-tiers"; + + static readonly Faker Faker = new Faker().CustomInstantiator(f => new(f.Commerce.Product(), f.Random.Int())); + + public static IEnumerable CreateMany(int count) => Faker.Generate(count); } diff --git a/src/Core/test/Eventuous.Tests.Subscriptions.Base/Eventuous.Tests.Subscriptions.Base.csproj b/src/Core/test/Eventuous.Tests.Subscriptions.Base/Eventuous.Tests.Subscriptions.Base.csproj index 8a4a253cd..6647c4590 100644 --- a/src/Core/test/Eventuous.Tests.Subscriptions.Base/Eventuous.Tests.Subscriptions.Base.csproj +++ b/src/Core/test/Eventuous.Tests.Subscriptions.Base/Eventuous.Tests.Subscriptions.Base.csproj @@ -14,7 +14,6 @@ - diff --git a/src/Core/test/Eventuous.Tests.Subscriptions.Base/Fixtures/TestEventHandler.cs b/src/Core/test/Eventuous.Tests.Subscriptions.Base/Fixtures/TestEventHandler.cs index 8f0e29762..dcac54db2 100644 --- a/src/Core/test/Eventuous.Tests.Subscriptions.Base/Fixtures/TestEventHandler.cs +++ b/src/Core/test/Eventuous.Tests.Subscriptions.Base/Fixtures/TestEventHandler.cs @@ -1,3 +1,4 @@ +using Bogus; using Eventuous.Subscriptions; using Eventuous.Subscriptions.Context; using Hypothesist; @@ -12,6 +13,12 @@ namespace Eventuous.Tests.Subscriptions.Base; // ReSharper disable once ClassNeverInstantiated.Global public record TestEvent(string Data, int Number) { public const string TypeName = "test-event"; + + static readonly Faker Faker = new Faker().CustomInstantiator(f => new TestEvent(f.Lorem.Sentence(), f.Random.Int())); + + public static TestEvent Create() => Faker.Generate(); + + public static List CreateMany(int count) => Faker.Generate(count); } public class TestEventHandler(TestEventHandlerOptions? options) : BaseEventHandler { diff --git a/src/Core/test/Eventuous.Tests.Subscriptions.Base/SubscribeToAll.cs b/src/Core/test/Eventuous.Tests.Subscriptions.Base/SubscribeToAll.cs index 5dee0cea3..c9e8f7f18 100644 --- a/src/Core/test/Eventuous.Tests.Subscriptions.Base/SubscribeToAll.cs +++ b/src/Core/test/Eventuous.Tests.Subscriptions.Base/SubscribeToAll.cs @@ -62,7 +62,7 @@ protected async Task ShouldUseExistingCheckpoint(CancellationToken cancellationT TestContext.Current?.OutputWriter.WriteLine("Last checkpoint: {0}", l.Position!); await fixture.StartSubscription(); - await Task.Delay(TimeSpan.FromSeconds(1)); + await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken); await fixture.StopSubscription(); await Assert.That(fixture.Handler.Count).IsEqualTo(0); } @@ -72,7 +72,7 @@ protected async Task ShouldUseExistingCheckpoint(CancellationToken cancellationT async Task> GenerateAndHandleCommands(int count) { var commands = Enumerable .Range(0, count) - .Select(_ => DomainFixture.CreateImportBooking(fixture.Auto)) + .Select(_ => DomainFixture.CreateImportBooking()) .ToList(); var service = new BookingService(fixture.EventStore); diff --git a/src/Core/test/Eventuous.Tests.Subscriptions.Base/SubscribeToStream.cs b/src/Core/test/Eventuous.Tests.Subscriptions.Base/SubscribeToStream.cs index 0743ecc17..70b916ee9 100644 --- a/src/Core/test/Eventuous.Tests.Subscriptions.Base/SubscribeToStream.cs +++ b/src/Core/test/Eventuous.Tests.Subscriptions.Base/SubscribeToStream.cs @@ -86,7 +86,7 @@ async Task> GenerateAndProduceEvents(int count) { var commands = Enumerable .Range(0, count) - .Select(_ => DomainFixture.CreateImportBooking(fixture.Auto)) + .Select(_ => DomainFixture.CreateImportBooking()) .ToList(); var events = commands.Select(ToEvent).ToList(); diff --git a/src/Core/test/Eventuous.Tests.Subscriptions/AutofixtureExtensions.cs b/src/Core/test/Eventuous.Tests.Subscriptions/AutofixtureExtensions.cs deleted file mode 100644 index 90ddd2e06..000000000 --- a/src/Core/test/Eventuous.Tests.Subscriptions/AutofixtureExtensions.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Eventuous.Subscriptions.Context; -using Eventuous.TestHelpers.TUnit.Logging; - -namespace Eventuous.Tests.Subscriptions; - -public static class AutoFixtureExtensions { - public static MessageConsumeContext CreateContext(this Fixture auto) { - var factory = new LoggerFactory().AddTUnit(); - return auto.Build().With(x => x.LogContext, () => new("test", factory)).Create(); - } -} diff --git a/src/Core/test/Eventuous.Tests.Subscriptions/ConsumePipeTests.cs b/src/Core/test/Eventuous.Tests.Subscriptions/ConsumePipeTests.cs index b7f4051b5..949230bb1 100644 --- a/src/Core/test/Eventuous.Tests.Subscriptions/ConsumePipeTests.cs +++ b/src/Core/test/Eventuous.Tests.Subscriptions/ConsumePipeTests.cs @@ -5,13 +5,11 @@ namespace Eventuous.Tests.Subscriptions; public class ConsumePipeTests() { - static readonly Fixture Auto = new(); - [Test] public async Task ShouldCallHandlers() { var handler = new TestHandler(); var pipe = new ConsumePipe().AddDefaultConsumer(handler); - var ctx = Auto.CreateContext(); + var ctx = TestContext.CreateContext(); await pipe.Send(ctx); @@ -24,11 +22,11 @@ public async Task ShouldCallHandlers() { public async Task ShouldAddContextBaggage() { var handler = new TestHandler(); var pipe = new ConsumePipe().AddDefaultConsumer(handler); - var baggage = Auto.Create(); + var baggage = Guid.NewGuid().ToString(); pipe.AddFilterFirst(new TestFilter(Key, baggage)); - var ctx = Auto.CreateContext(); + var ctx = TestContext.CreateContext(); await pipe.Send(ctx); diff --git a/src/Core/test/Eventuous.Tests.Subscriptions/DefaultConsumerTests.cs b/src/Core/test/Eventuous.Tests.Subscriptions/DefaultConsumerTests.cs index e6c135e47..7916e40ff 100644 --- a/src/Core/test/Eventuous.Tests.Subscriptions/DefaultConsumerTests.cs +++ b/src/Core/test/Eventuous.Tests.Subscriptions/DefaultConsumerTests.cs @@ -8,13 +8,11 @@ namespace Eventuous.Tests.Subscriptions; public class DefaultConsumerTests() : IDisposable { readonly TestEventListener _listener = new(); - static readonly Fixture Auto = new(); - [Test] public async Task ShouldFailWhenHandlerNacks() { var handler = new FailingHandler(); var consumer = new DefaultConsumer([handler]); - var ctx = Auto.CreateContext(); + var ctx = TestContext.CreateContext(); await consumer.Consume(ctx); diff --git a/src/Core/test/Eventuous.Tests.Subscriptions/Eventuous.Tests.Subscriptions.csproj b/src/Core/test/Eventuous.Tests.Subscriptions/Eventuous.Tests.Subscriptions.csproj index f6b9b4312..4f2cef625 100644 --- a/src/Core/test/Eventuous.Tests.Subscriptions/Eventuous.Tests.Subscriptions.csproj +++ b/src/Core/test/Eventuous.Tests.Subscriptions/Eventuous.Tests.Subscriptions.csproj @@ -9,6 +9,5 @@ - diff --git a/src/Core/test/Eventuous.Tests.Subscriptions/HandlingStatusTests.cs b/src/Core/test/Eventuous.Tests.Subscriptions/HandlingStatusTests.cs index 005ae0e3b..58a959e2d 100644 --- a/src/Core/test/Eventuous.Tests.Subscriptions/HandlingStatusTests.cs +++ b/src/Core/test/Eventuous.Tests.Subscriptions/HandlingStatusTests.cs @@ -3,9 +3,7 @@ namespace Eventuous.Tests.Subscriptions; -public class HandlingStatusTests() { - static Fixture Auto { get; } = new(); - +public class HandlingStatusTests { [Test] public void AckAndNackShouldNack() { const EventHandlingStatus actual = EventHandlingStatus.Success | EventHandlingStatus.Failure; @@ -39,8 +37,8 @@ public void IgnoredShouldBeIgnored() { [Test] public void NackAndIgnoreShouldFail() { - var context = Auto.CreateContext(); - context.Nack(new Exception()); + var context = TestContext.CreateContext(); + context.Nack(new()); context.Ignore("test"); context.HasFailed().Should().BeTrue(); context.WasIgnored().Should().BeFalse(); @@ -49,8 +47,8 @@ public void NackAndIgnoreShouldFail() { [Test] public void NackAckAndIgnoreShouldFail() { - var context = Auto.CreateContext(); - context.Nack(new Exception()); + var context = TestContext.CreateContext(); + context.Nack(new()); context.Ack(); context.Ignore(); context.HasFailed().Should().BeTrue(); @@ -60,7 +58,7 @@ public void NackAckAndIgnoreShouldFail() { [Test] public void AckAndIgnoreShouldSucceed() { - var context = Auto.CreateContext(); + var context = TestContext.CreateContext(); context.Ack(); context.Ignore(); context.HasFailed().Should().BeFalse(); @@ -70,7 +68,7 @@ public void AckAndIgnoreShouldSucceed() { [Test] public void IgnoreAndIgnoreShouldIgnore() { - var context = Auto.CreateContext(); + var context = TestContext.CreateContext(); context.Ignore(); context.Ignore(); context.WasIgnored().Should().BeTrue(); @@ -79,7 +77,7 @@ public void IgnoreAndIgnoreShouldIgnore() { [Test] public void PendingShouldBePending() { - var context = Auto.CreateContext(); + var context = TestContext.CreateContext(); context.WasIgnored().Should().BeFalse(); context.HasFailed().Should().BeFalse(); context.HandlingResults.IsPending().Should().BeTrue(); diff --git a/src/Core/test/Eventuous.Tests.Subscriptions/RegistrationTests.cs b/src/Core/test/Eventuous.Tests.Subscriptions/RegistrationTests.cs index 3fc505f75..4eb65ba9e 100644 --- a/src/Core/test/Eventuous.Tests.Subscriptions/RegistrationTests.cs +++ b/src/Core/test/Eventuous.Tests.Subscriptions/RegistrationTests.cs @@ -15,9 +15,8 @@ namespace Eventuous.Tests.Subscriptions; -public class RegistrationTests() { +public class RegistrationTests { readonly TestServer _server = new(BuildHost()); - readonly Fixture _auto = new(); readonly ILoggerFactory _logger = LoggingExtensions.GetLoggerFactory(); [Test] @@ -50,17 +49,17 @@ public async Task SubsShouldHaveHandlers(int position, Type handlerType) { var current = subs[position]; var ctx = new MessageConsumeContext( - _auto.Create(), - _auto.Create(), - _auto.Create(), - _auto.Create(), + Guid.NewGuid().ToString(), + Guid.NewGuid().ToString(), + Guid.NewGuid().ToString(), + Guid.NewGuid().ToString(), 0, 0, 0, 0, DateTime.UtcNow, new TestEvent(), - new Metadata(), + new(), current.SubscriptionId, default ) { LogContext = new(current.SubscriptionId, _logger) }; diff --git a/src/Core/test/Eventuous.Tests.Subscriptions/SequenceTests.cs b/src/Core/test/Eventuous.Tests.Subscriptions/SequenceTests.cs index ef029b647..131171671 100644 --- a/src/Core/test/Eventuous.Tests.Subscriptions/SequenceTests.cs +++ b/src/Core/test/Eventuous.Tests.Subscriptions/SequenceTests.cs @@ -60,10 +60,10 @@ public void ShouldWorkForNormalCase() { first.Should().Be(new CommitPosition(9, 9, timestamp)); } - public static IEnumerable<(CommitPositionSequence, CommitPosition)> TestData() { + public static IEnumerable> TestData() { var timestamp = DateTime.Now; - yield return ([new(0, 1, timestamp), new(0, 2, timestamp), new(0, 4, timestamp), new(0, 6, timestamp)], new(0, 2, timestamp)); - yield return ([new(0, 1, timestamp), new(0, 2, timestamp), new(0, 8, timestamp), new(0, 6, timestamp)], new(0, 2, timestamp)); + yield return () => ([new(0, 1, timestamp), new(0, 2, timestamp), new(0, 4, timestamp), new(0, 6, timestamp)], new(0, 2, timestamp)); + yield return () => ([new(0, 1, timestamp), new(0, 2, timestamp), new(0, 8, timestamp), new(0, 6, timestamp)], new(0, 2, timestamp)); } } diff --git a/src/Core/test/Eventuous.Tests.Subscriptions/TestContext.cs b/src/Core/test/Eventuous.Tests.Subscriptions/TestContext.cs new file mode 100644 index 000000000..af068b769 --- /dev/null +++ b/src/Core/test/Eventuous.Tests.Subscriptions/TestContext.cs @@ -0,0 +1,29 @@ +using Bogus; +using Eventuous.Subscriptions.Context; +using Eventuous.TestHelpers.TUnit.Logging; + +namespace Eventuous.Tests.Subscriptions; + +public static class TestContext { + static readonly Faker Auto = new Faker() + .CustomInstantiator( + f => new( + f.Random.String(), + f.Random.String(), + f.Random.String(), + f.Random.String(), + f.Random.ULong(), + f.Random.ULong(), + f.Random.ULong(), + f.Random.ULong(), + f.Date.Past(), + new(), + null, + f.Random.String(), + CancellationToken.None + ) + ) + .RuleFor(x => x.LogContext, (_, _) => new("test", new LoggerFactory().AddTUnit())); + + public static MessageConsumeContext CreateContext() => Auto.Generate(); +} diff --git a/src/Core/test/Eventuous.Tests/Aggregates/TwoAggregateOpsSpec.cs b/src/Core/test/Eventuous.Tests/Aggregates/TwoAggregateOpsSpec.cs index 3e6ad68ad..ba2413418 100644 --- a/src/Core/test/Eventuous.Tests/Aggregates/TwoAggregateOpsSpec.cs +++ b/src/Core/test/Eventuous.Tests/Aggregates/TwoAggregateOpsSpec.cs @@ -1,3 +1,4 @@ +using Bogus; using JetBrains.Annotations; namespace Eventuous.Tests.Aggregates; @@ -7,16 +8,12 @@ namespace Eventuous.Tests.Aggregates; using static Sut.Domain.BookingEvents; public class TwoAggregateOpsSpec : AggregateSpec { - readonly Fixture _fixture = new(); - - public TwoAggregateOpsSpec() => _testData = _fixture.Create(); - protected override void When(Booking booking) { var amount = new Money(_testData.Amount); var checkIn = LocalDate.FromDateTime(DateTime.Today); var checkOut = checkIn.Plus(Period.FromDays(2)); - booking.BookRoom(_fixture.Create(), new(checkIn, checkOut), amount); + booking.BookRoom(Guid.NewGuid().ToString(), new(checkIn, checkOut), amount); booking.RecordPayment(_testData.PaymentId, amount, _testData.PaidAt); } @@ -38,8 +35,10 @@ protected override void When(Booking booking) { [Test] public void should_not_be_overpaid() => Then().State.IsOverpaid().Should().BeFalse(); - readonly TestData _testData; + readonly TestData _testData = Faker.Generate(); [UsedImplicitly] record TestData(string PaymentId, float Amount, DateTimeOffset PaidAt); + + static readonly Faker Faker = new Faker().CustomInstantiator(f => new(f.Random.String(), f.Random.Float(), f.Date.Past())); } diff --git a/src/Core/test/Eventuous.Tests/Eventuous.Tests.csproj b/src/Core/test/Eventuous.Tests/Eventuous.Tests.csproj index 13938e703..22f2f822c 100644 --- a/src/Core/test/Eventuous.Tests/Eventuous.Tests.csproj +++ b/src/Core/test/Eventuous.Tests/Eventuous.Tests.csproj @@ -10,14 +10,10 @@ - - + - - - diff --git a/src/Core/test/Eventuous.Tests/Fixtures/NaiveFixture.cs b/src/Core/test/Eventuous.Tests/Fixtures/NaiveFixture.cs index cb596834a..c53a5cdcd 100644 --- a/src/Core/test/Eventuous.Tests/Fixtures/NaiveFixture.cs +++ b/src/Core/test/Eventuous.Tests/Fixtures/NaiveFixture.cs @@ -1,3 +1,5 @@ +using Bogus; + namespace Eventuous.Tests.Fixtures; using Sut.App; @@ -5,13 +7,16 @@ namespace Eventuous.Tests.Fixtures; public class NaiveFixture { protected IEventStore EventStore { get; } = new InMemoryEventStore(); - protected Fixture Auto { get; } = new(); - protected Commands.BookRoom CreateBookRoomCommand() => new( - Auto.Create(), - Auto.Create(), - LocalDate.FromDateTime(DateTime.Today), - LocalDate.FromDateTime(DateTime.Today.AddDays(2)), - Auto.Create() - ); + static readonly Faker Faker = new Faker() + .CustomInstantiator( + f => { + var checkin = f.Noda().LocalDate.Soon(); + var checkout = checkin.PlusDays(f.Random.Number(1, 5)); + + return new(f.Random.Guid().ToString("N"), f.Random.Guid().ToString("N"), checkin, checkout, f.Random.Number(50, 200)); + } + ); + + protected static Commands.BookRoom CreateBookRoomCommand() => Faker.Generate(); } diff --git a/src/Core/test/Eventuous.Tests/ForgotToSetId.cs b/src/Core/test/Eventuous.Tests/ForgotToSetId.cs index 4f43d7742..17e68cd71 100644 --- a/src/Core/test/Eventuous.Tests/ForgotToSetId.cs +++ b/src/Core/test/Eventuous.Tests/ForgotToSetId.cs @@ -7,7 +7,7 @@ public class ForgotToSetId : NaiveFixture { [Test] public async Task ShouldFailWithNoId(CancellationToken cancellationToken) { - var cmd = new DoIt(Auto.Create()); + var cmd = new DoIt(Guid.NewGuid().ToString()); var result = await Service.Handle(cmd, cancellationToken); result.Success.Should().BeTrue(); } diff --git a/src/Core/test/Eventuous.Tests/StoringEvents.cs b/src/Core/test/Eventuous.Tests/StoringEvents.cs index f574f0ba9..7cdad1708 100644 --- a/src/Core/test/Eventuous.Tests/StoringEvents.cs +++ b/src/Core/test/Eventuous.Tests/StoringEvents.cs @@ -17,13 +17,7 @@ public StoringEvents() { [Test] public async Task StoreInitial(CancellationToken cancellationToken) { - var cmd = new Commands.BookRoom( - Auto.Create(), - Auto.Create(), - LocalDate.FromDateTime(DateTime.Today), - LocalDate.FromDateTime(DateTime.Today.AddDays(2)), - Auto.Create() - ); + var cmd = CreateBookRoomCommand(); Change[] expected = [new(new RoomBooked(cmd.RoomId, cmd.CheckIn, cmd.CheckOut, cmd.Price), TypeNames.RoomBooked)]; diff --git a/src/Core/test/Eventuous.Tests/StoringEventsWithCustomStream.cs b/src/Core/test/Eventuous.Tests/StoringEventsWithCustomStream.cs index 53b5fcba8..b9a4b6ca6 100644 --- a/src/Core/test/Eventuous.Tests/StoringEventsWithCustomStream.cs +++ b/src/Core/test/Eventuous.Tests/StoringEventsWithCustomStream.cs @@ -38,7 +38,7 @@ public async Task TestOnExisting(CancellationToken cancellationToken) { await Service.Handle(cmd, cancellationToken); - var secondCmd = new Commands.RecordPayment(new(cmd.BookingId), Auto.Create(), new(cmd.Price), DateTimeOffset.Now); + var secondCmd = new Commands.RecordPayment(new(cmd.BookingId), Guid.NewGuid().ToString(), new(cmd.Price), DateTimeOffset.Now); var expected = new Change[] { new(new BookingPaymentRegistered(secondCmd.PaymentId, secondCmd.Amount.Amount), TypeNames.PaymentRegistered), diff --git a/src/Diagnostics/test/Eventuous.Tests.OpenTelemetry/Eventuous.Tests.OpenTelemetry.csproj b/src/Diagnostics/test/Eventuous.Tests.OpenTelemetry/Eventuous.Tests.OpenTelemetry.csproj index ed473b928..32874d039 100644 --- a/src/Diagnostics/test/Eventuous.Tests.OpenTelemetry/Eventuous.Tests.OpenTelemetry.csproj +++ b/src/Diagnostics/test/Eventuous.Tests.OpenTelemetry/Eventuous.Tests.OpenTelemetry.csproj @@ -16,7 +16,6 @@ - @@ -34,9 +33,6 @@ - - - diff --git a/src/Diagnostics/test/Eventuous.Tests.OpenTelemetry/Fixtures/MetricsSubscriptionFixtureBase.cs b/src/Diagnostics/test/Eventuous.Tests.OpenTelemetry/Fixtures/MetricsSubscriptionFixtureBase.cs index 12e8d36ee..eacb6d17a 100644 --- a/src/Diagnostics/test/Eventuous.Tests.OpenTelemetry/Fixtures/MetricsSubscriptionFixtureBase.cs +++ b/src/Diagnostics/test/Eventuous.Tests.OpenTelemetry/Fixtures/MetricsSubscriptionFixtureBase.cs @@ -17,7 +17,6 @@ public interface IMetricsSubscriptionFixtureBase { public string DefaultTagValue { get; } string SubscriptionId { get; } IProducer Producer { get; } - IFixture Auto { get; } } public abstract class MetricsSubscriptionFixtureBase : StoreFixtureBase, IMetricsSubscriptionFixtureBase diff --git a/src/Diagnostics/test/Eventuous.Tests.OpenTelemetry/MetricsTests.cs b/src/Diagnostics/test/Eventuous.Tests.OpenTelemetry/MetricsTests.cs index 5bf7a10f9..318ae4f53 100644 --- a/src/Diagnostics/test/Eventuous.Tests.OpenTelemetry/MetricsTests.cs +++ b/src/Diagnostics/test/Eventuous.Tests.OpenTelemetry/MetricsTests.cs @@ -35,13 +35,12 @@ public async Task ShouldMeasureSubscriptionGapCountBase() { // duration.CheckTag(SubscriptionMetrics.MessageTypeTag, TestEvent.TypeName); // } - static MetricValue? GetValue(MetricValue[] values, string metric) - => values.FirstOrDefault(x => x.Name == metric); + static MetricValue? GetValue(MetricValue[] values, string metric) => values.FirstOrDefault(x => x.Name == metric); [Before(Test)] public async Task InitializeAsync() { - var testEvents = fixture.Auto.CreateMany(fixture.Count).ToList(); - await fixture.Producer.Produce(fixture.Stream, testEvents, new Metadata()); + var testEvents = TestEvent.CreateMany(fixture.Count); + await fixture.Producer.Produce(fixture.Stream, testEvents, new()); while (fixture.Counter.Count < fixture.Count / 2) { await Task.Delay(100); diff --git a/src/Directory.Build.props b/src/Directory.Build.props index aac351cc9..9fb283431 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -62,13 +62,11 @@ - - diff --git a/src/EventStore/test/Eventuous.Tests.EventStore/Eventuous.Tests.EventStore.csproj b/src/EventStore/test/Eventuous.Tests.EventStore/Eventuous.Tests.EventStore.csproj index bac49f0a3..dfffe6827 100644 --- a/src/EventStore/test/Eventuous.Tests.EventStore/Eventuous.Tests.EventStore.csproj +++ b/src/EventStore/test/Eventuous.Tests.EventStore/Eventuous.Tests.EventStore.csproj @@ -15,11 +15,8 @@ - - - diff --git a/src/EventStore/test/Eventuous.Tests.EventStore/Fixtures/DomainFixture.cs b/src/EventStore/test/Eventuous.Tests.EventStore/Fixtures/DomainFixture.cs index d8a039f47..4b6ae12d7 100644 --- a/src/EventStore/test/Eventuous.Tests.EventStore/Fixtures/DomainFixture.cs +++ b/src/EventStore/test/Eventuous.Tests.EventStore/Fixtures/DomainFixture.cs @@ -1,20 +1,18 @@ +using Bogus; using Eventuous.Sut.App; using Eventuous.Sut.Domain; -using MicroElements.AutoFixture.NodaTime; namespace Eventuous.Tests.EventStore.Fixtures; public static class DomainFixture { static DomainFixture() => TypeMap.RegisterKnownEventTypes(typeof(BookingEvents.BookingImported).Assembly); - static IFixture Auto { get; } = new Fixture().Customize(new NodaTimeCustomization()); + static Faker Faker => new Faker() + .RuleFor(x => x.BookingId, _ => Guid.NewGuid().ToString("N")) + .RuleFor(x => x.RoomId, _ => Guid.NewGuid().ToString("N")) + .RuleFor(x => x.Price, f => f.Random.Number(50, 200)) + .RuleFor(x => x.CheckIn, f => f.Noda().LocalDate.Soon()) + .RuleFor(x => x.CheckOut, (f, c) => c.CheckIn.PlusDays(f.Random.Number(1, 5))); - public static Commands.ImportBooking CreateImportBooking() { - var from = Auto.Create(); - - return Auto.Build() - .With(x => x.CheckIn, from) - .With(x => x.CheckOut, from.PlusDays(2)) - .Create(); - } + public static Commands.ImportBooking CreateImportBooking() => Faker.Generate(); } diff --git a/src/EventStore/test/Eventuous.Tests.EventStore/ProducerTracesTests.cs b/src/EventStore/test/Eventuous.Tests.EventStore/ProducerTracesTests.cs index 0d94a7f3c..da2b1e2a1 100644 --- a/src/EventStore/test/Eventuous.Tests.EventStore/ProducerTracesTests.cs +++ b/src/EventStore/test/Eventuous.Tests.EventStore/ProducerTracesTests.cs @@ -31,7 +31,7 @@ public TracesTests() : base(new()) { [Test] [Category("Diagnostics")] public async Task ShouldPropagateRemoteContext(CancellationToken cancellationToken) { - var testEvent = Auto.Create(); + var testEvent = TestEvent.Create(); await Producer.Produce(Stream, testEvent, new(), cancellationToken: cancellationToken); diff --git a/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/Fixtures/LegacySubscriptionFixture.cs b/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/Fixtures/LegacySubscriptionFixture.cs index e33ed9200..d64c0501c 100644 --- a/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/Fixtures/LegacySubscriptionFixture.cs +++ b/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/Fixtures/LegacySubscriptionFixture.cs @@ -8,8 +8,6 @@ namespace Eventuous.Tests.EventStore.Subscriptions.Fixtures; public abstract class LegacySubscriptionFixture: IAsyncInitializer, IAsyncDisposable where T : class, IEventHandler { - protected readonly Fixture Auto = new(); - protected StreamName Stream { get; } = new($"test-{Guid.NewGuid():N}"); protected StoreFixture StoreFixture { get; } = new(); protected T Handler { get; } diff --git a/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/Fixtures/PersistentSubscriptionFixture.cs b/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/Fixtures/PersistentSubscriptionFixture.cs index 3b2769713..0e387a697 100644 --- a/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/Fixtures/PersistentSubscriptionFixture.cs +++ b/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/Fixtures/PersistentSubscriptionFixture.cs @@ -7,16 +7,14 @@ namespace Eventuous.Tests.EventStore.Subscriptions.Fixtures; public class PersistentSubscriptionFixture( - THandler handler, + THandler handler, Func subscriptionFactory, - bool autoStart = true, - LogLevel logLevel = LogLevel.Information + bool autoStart = true, + LogLevel logLevel = LogLevel.Information ) where THandler : class, IEventHandler where TSubscription : PersistentSubscriptionBase where TOptions : PersistentSubscriptionOptions { - public readonly Fixture Auto = new(); - public StreamName Stream { get; } = new($"test-{Guid.NewGuid():N}"); public THandler Handler { get; } = handler; public EventStoreProducer Producer { get; private set; } = null!; diff --git a/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/PublishAndSubscribeManyPartitionedTests.cs b/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/PublishAndSubscribeManyPartitionedTests.cs index 135930e3a..b6eebd894 100644 --- a/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/PublishAndSubscribeManyPartitionedTests.cs +++ b/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/PublishAndSubscribeManyPartitionedTests.cs @@ -15,9 +15,7 @@ public class PublishAndSubscribeManyPartitionedTests() : LegacySubscriptionFixtu public async Task SubscribeAndProduceMany(CancellationToken cancellationToken) { const int count = 10; - var testEvents = Enumerable.Range(1, count) - .Select(i => new TestEvent(Auto.Create(), i)) - .ToList(); + var testEvents = TestEvent.CreateMany(count); await Start(); await Producer.Produce(Stream, testEvents, new Metadata(), cancellationToken: cancellationToken); diff --git a/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/PublishAndSubscribeManyTests.cs b/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/PublishAndSubscribeManyTests.cs index 3865eda6e..ea026ba2e 100644 --- a/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/PublishAndSubscribeManyTests.cs +++ b/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/PublishAndSubscribeManyTests.cs @@ -10,7 +10,7 @@ public class PublishAndSubscribeManyTests() : LegacySubscriptionFixture(1.Millis public async Task SubscribeAndProduceMany(CancellationToken cancellationToken) { const int count = 100; - var testEvents = Auto.CreateMany(count).ToList(); + var testEvents = TestEvent.CreateMany(count).ToList(); await Start(); await Producer.Produce(Stream, testEvents, new(), cancellationToken: cancellationToken); diff --git a/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/PublishAndSubscribeOneTests.cs b/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/PublishAndSubscribeOneTests.cs index e3fd05236..963d3d184 100644 --- a/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/PublishAndSubscribeOneTests.cs +++ b/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/PublishAndSubscribeOneTests.cs @@ -8,7 +8,7 @@ public class PublishAndSubscribeOneTests() : LegacySubscriptionFixture(null, fal [Test] [Category("Stream catch-up subscription")] public async Task SubscribeAndProduce(CancellationToken cancellationToken) { - var testEvent = Auto.Create(); + var testEvent = TestEvent.Create(); await Start(); await Producer.Produce(Stream, testEvent, new(), cancellationToken: cancellationToken); diff --git a/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/StreamPersistentPublishAndSubscribeManyTests.cs b/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/StreamPersistentPublishAndSubscribeManyTests.cs index 980f941e4..67836c4c0 100644 --- a/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/StreamPersistentPublishAndSubscribeManyTests.cs +++ b/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/StreamPersistentPublishAndSubscribeManyTests.cs @@ -17,7 +17,7 @@ CancellationToken ) { const int count = 1000; - var testEvents = fixture.Auto.CreateMany(count).ToList(); + var testEvents = TestEvent.CreateMany(count); await fixture.InitializeAsync(); await fixture.Start(); @@ -27,11 +27,9 @@ CancellationToken await fixture.DisposeAsync(); } - public static PersistentSubscriptionFixture[] GetFixtures() { - return [ - new(new(), CreateWithRegularClient, false), - new(new(), CreateWithPersistentSubClient, false), - ]; + public static IEnumerable>> GetFixtures() { + yield return () => new(new(), CreateWithRegularClient, false); + yield return () => new(new(), CreateWithPersistentSubClient, false); } static StreamPersistentSubscription CreateWithRegularClient(string id, string connectionString, StreamName stream, TestEventHandler handler, ILoggerFactory loggerFactory) { diff --git a/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/StreamSubscriptionWithLinksTests.cs b/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/StreamSubscriptionWithLinksTests.cs index 73cad106b..08496ffb6 100644 --- a/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/StreamSubscriptionWithLinksTests.cs +++ b/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/StreamSubscriptionWithLinksTests.cs @@ -58,7 +58,7 @@ async Task> Seed(IServiceProvider provider, int count) { for (var i = 0; i < count; i++) { var evt = new TestEvent(Guid.NewGuid().ToString(), i); - var stream = new StreamName($"{_prefix}-{Auto.Create()}"); + var stream = new StreamName($"{_prefix}-{Guid.NewGuid():N}"); await producer.Produce(stream, evt, null); events.Add(evt); } diff --git a/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/SubscribeTests.cs b/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/SubscribeTests.cs index 5522d779c..2f66b18dd 100644 --- a/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/SubscribeTests.cs +++ b/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/SubscribeTests.cs @@ -64,7 +64,5 @@ static void ConfigureOptions(StreamSubscriptionOptions options, StreamNameFixtur } public class StreamNameFixture { - static readonly Fixture Auto = new(); - - public StreamName StreamName = new(Auto.Create()); + public StreamName StreamName = new(Guid.NewGuid().ToString("N")); } diff --git a/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/SubscriptionIgnoredMessagesTests.cs b/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/SubscriptionIgnoredMessagesTests.cs index 25ca7ad9d..1d1668954 100644 --- a/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/SubscriptionIgnoredMessagesTests.cs +++ b/src/EventStore/test/Eventuous.Tests.EventStore/Subscriptions/SubscriptionIgnoredMessagesTests.cs @@ -45,8 +45,8 @@ public async Task SubscribeAndProduceManyWithIgnored(CancellationToken cancellat IEnumerable Generate() { for (var i = 0; i < count; i++) { - yield return new TestEvent(Auto.Create(), i); - yield return new UnknownEvent(Auto.Create(), i); + yield return new TestEvent(Guid.NewGuid().ToString(), i); + yield return new UnknownEvent(Guid.NewGuid().ToString(), i); } } } diff --git a/src/Experimental/src/ElasticPlayground/CombinedStore.cs b/src/Experimental/src/ElasticPlayground/CombinedStore.cs index 20620b8c8..3a43a1cf3 100644 --- a/src/Experimental/src/ElasticPlayground/CombinedStore.cs +++ b/src/Experimental/src/ElasticPlayground/CombinedStore.cs @@ -1,11 +1,9 @@ -using AutoFixture; using EventStore.Client; using Eventuous.ElasticSearch.Store; using Eventuous.EventStore; using Eventuous.Sut.App; using Eventuous.Sut.Domain; using Nest; -using NodaTime; using static Eventuous.Sut.App.Commands; namespace ElasticPlayground; @@ -15,8 +13,6 @@ public class CombinedStore { readonly EsdbEventStore _esdbEventStore; readonly ElasticEventStore _elasticEventStore; - static readonly Fixture Fixture = new(); - public CombinedStore(IElasticClient elasticClient, EventStoreClient eventStoreClient) { _elasticEventStore = new(elasticClient); _esdbEventStore = new(eventStoreClient); @@ -24,13 +20,7 @@ public CombinedStore(IElasticClient elasticClient, EventStoreClient eventStoreCl } public async Task Execute() { - var bookRoom = new BookRoom( - Fixture.Create(), - Fixture.Create(), - LocalDate.FromDateTime(DateTime.Today), - LocalDate.FromDateTime(DateTime.Today.AddDays(1)), - 100 - ); + var bookRoom = Generator.CreateBookRoomCommand(); await Seed(_esdbEventStore, bookRoom); await Seed(_elasticEventStore, bookRoom); @@ -39,7 +29,7 @@ public async Task Execute() { var service = new ThrowingCommandService(new BookingService(_store)); - var cmd = bookRoom.ToRecordPayment(Fixture.Create(), 2); + var cmd = bookRoom.ToRecordPayment(Generator.RandomString(), 2); var result = await service.Handle(cmd, default); @@ -51,7 +41,7 @@ static async Task Seed(IEventStore store, BookRoom bookRoom) { await service.Handle(bookRoom, default); - var processPayment = bookRoom.ToRecordPayment(Fixture.Create(), 2); + var processPayment = bookRoom.ToRecordPayment(Generator.RandomString(), 2); await service.Handle(processPayment, default); } diff --git a/src/Experimental/src/ElasticPlayground/ConnectorAndArchive.cs b/src/Experimental/src/ElasticPlayground/ConnectorAndArchive.cs index 4bc2fa554..1f989488f 100644 --- a/src/Experimental/src/ElasticPlayground/ConnectorAndArchive.cs +++ b/src/Experimental/src/ElasticPlayground/ConnectorAndArchive.cs @@ -1,11 +1,9 @@ -using AutoFixture; using EventStore.Client; using Eventuous.ElasticSearch.Store; using Eventuous.EventStore; using Eventuous.Sut.App; using Eventuous.Sut.Domain; using Nest; -using NodaTime; using static Eventuous.Sut.App.Commands; namespace ElasticPlayground; @@ -15,8 +13,6 @@ public class ConnectorAndArchive { readonly ElasticEventStore _elasticEventStore; readonly TieredEventStore _tieredStore; - static readonly Fixture Fixture = new(); - public ConnectorAndArchive(IElasticClient elasticClient, EventStoreClient eventStoreClient) { _elasticEventStore = new(elasticClient); _esdbEventStore = new(eventStoreClient); @@ -24,13 +20,7 @@ public ConnectorAndArchive(IElasticClient elasticClient, EventStoreClient eventS } public async Task Execute() { - var bookRoom = new BookRoom( - Fixture.Create(), - Fixture.Create(), - LocalDate.FromDateTime(DateTime.Today), - LocalDate.FromDateTime(DateTime.Today.AddDays(1)), - 100 - ); + var bookRoom = Generator.CreateBookRoomCommand(); await Seed(_elasticEventStore, bookRoom); @@ -43,7 +33,7 @@ await _esdbEventStore.TruncateStream( var service = new ThrowingCommandService(new BookingService(_tieredStore)); - var cmd = bookRoom.ToRecordPayment(Fixture.Create(), 2); + var cmd = bookRoom.ToRecordPayment(Generator.RandomString(), 2); var result = await service.Handle(cmd, default); @@ -55,7 +45,7 @@ static async Task Seed(IEventStore store, BookRoom bookRoom) { await service.Handle(bookRoom, default); - var processPayment = bookRoom.ToRecordPayment(Fixture.Create(), 2); + var processPayment = bookRoom.ToRecordPayment(Generator.RandomString(), 2); await service.Handle(processPayment, default); } diff --git a/src/Experimental/src/ElasticPlayground/ElasticOnly.cs b/src/Experimental/src/ElasticPlayground/ElasticOnly.cs index 0fa3c318a..6191abd9d 100644 --- a/src/Experimental/src/ElasticPlayground/ElasticOnly.cs +++ b/src/Experimental/src/ElasticPlayground/ElasticOnly.cs @@ -1,35 +1,24 @@ -using AutoFixture; using Eventuous.ElasticSearch.Store; using Eventuous.Sut.App; using Eventuous.Sut.Domain; using Nest; -using NodaTime; namespace ElasticPlayground; public class ElasticOnly { readonly ICommandService _service; - static readonly Fixture Fixture = new(); - public ElasticOnly(IElasticClient client) { var eventStore = new ElasticEventStore(client); _service = new ThrowingCommandService(new BookingService(eventStore)); } public async Task Execute() { - var bookRoom = new Commands.BookRoom( - Fixture.Create(), - Fixture.Create(), - LocalDate.FromDateTime(DateTime.Today), - LocalDate.FromDateTime(DateTime.Today.AddDays(1)), - 100 - ); - - var result = await _service.Handle(bookRoom, default); + var bookRoom = Generator.CreateBookRoomCommand(); + var result = await _service.Handle(bookRoom, default); result.Dump(); - var processPayment = bookRoom.ToRecordPayment(Fixture.Create()); + var processPayment = bookRoom.ToRecordPayment(Generator.RandomString()); var secondResult = await _service.Handle(processPayment, default); secondResult.Dump(); diff --git a/src/Experimental/src/ElasticPlayground/ElasticPlayground.csproj b/src/Experimental/src/ElasticPlayground/ElasticPlayground.csproj index a68958853..ffe74f999 100644 --- a/src/Experimental/src/ElasticPlayground/ElasticPlayground.csproj +++ b/src/Experimental/src/ElasticPlayground/ElasticPlayground.csproj @@ -11,7 +11,8 @@ - + + diff --git a/src/Experimental/src/ElasticPlayground/Generator.cs b/src/Experimental/src/ElasticPlayground/Generator.cs new file mode 100644 index 000000000..c14994955 --- /dev/null +++ b/src/Experimental/src/ElasticPlayground/Generator.cs @@ -0,0 +1,20 @@ +using Bogus; +using Eventuous.Sut.App; + +namespace ElasticPlayground; + +public class Generator{ + public static string RandomString() => Guid.NewGuid().ToString(); + + static readonly Faker Faker = new Faker() + .CustomInstantiator( + f => { + var checkin = f.Noda().LocalDate.Soon(); + var checkout = checkin.PlusDays(f.Random.Number(1, 5)); + + return new(f.Random.Guid().ToString("N"), f.Random.Guid().ToString("N"), checkin, checkout, f.Random.Number(50, 200)); + } + ); + + public static Commands.BookRoom CreateBookRoomCommand() => Faker.Generate(); +} \ No newline at end of file diff --git a/src/Experimental/src/ElasticPlayground/OnlyArchive.cs b/src/Experimental/src/ElasticPlayground/OnlyArchive.cs index 32d728016..ddbbbb6e2 100644 --- a/src/Experimental/src/ElasticPlayground/OnlyArchive.cs +++ b/src/Experimental/src/ElasticPlayground/OnlyArchive.cs @@ -1,4 +1,3 @@ -using AutoFixture; using EventStore.Client; using Eventuous.ElasticSearch.Store; using Eventuous.EventStore; @@ -12,8 +11,6 @@ namespace ElasticPlayground; public class OnlyArchive { readonly TieredEventStore _tieredEventStore; - static readonly Fixture Fixture = new(); - public OnlyArchive(IElasticClient elasticClient, EventStoreClient eventStoreClient) { var elasticEventStore = new ElasticEventStore(elasticClient); var esdbEventStore = new EsdbEventStore(eventStoreClient); @@ -25,7 +22,7 @@ public async Task Execute() { var service = new ThrowingCommandService(new BookingService(_tieredEventStore)); - var cmd = new RecordPayment(new(bookingId), Fixture.Create(), new Money(10), DateTimeOffset.Now); + var cmd = new RecordPayment(new(bookingId), Generator.RandomString(), new(10), DateTimeOffset.Now); var result = await service.Handle(cmd, default); diff --git a/src/Extensions/test/Eventuous.Tests.Extensions.AspNetCore/AggregateCommandsTests.cs b/src/Extensions/test/Eventuous.Tests.Extensions.AspNetCore/AggregateCommandsTests.cs index 1477f4b41..86573a608 100644 --- a/src/Extensions/test/Eventuous.Tests.Extensions.AspNetCore/AggregateCommandsTests.cs +++ b/src/Extensions/test/Eventuous.Tests.Extensions.AspNetCore/AggregateCommandsTests.cs @@ -91,13 +91,13 @@ public async Task MapEnrichedCommand() { .MapCommands() .MapCommand((x, _) => x with { GuestId = TestData.GuestId }) ); - var cmd = fixture.GetBookRoom(); + var cmd = ServerFixture.GetBookRoom(); var content = await fixture.ExecuteRequest(cmd, "book", cmd.BookingId); await VerifyJson(content); } static async Task Execute(ServerFixture fixture, string route) { - var bookRoom = fixture.GetBookRoom(); + var bookRoom = ServerFixture.GetBookRoom(); var import = new ImportBookingHttp( bookRoom.BookingId, diff --git a/src/Extensions/test/Eventuous.Tests.Extensions.AspNetCore/ControllerTests.cs b/src/Extensions/test/Eventuous.Tests.Extensions.AspNetCore/ControllerTests.cs index d22bee757..6d323d6ca 100644 --- a/src/Extensions/test/Eventuous.Tests.Extensions.AspNetCore/ControllerTests.cs +++ b/src/Extensions/test/Eventuous.Tests.Extensions.AspNetCore/ControllerTests.cs @@ -9,9 +9,8 @@ namespace Eventuous.Tests.Extensions.AspNetCore; using static SutBookingCommands; [ClassDataSource>] -public class ControllerTests : IDisposable { - readonly ServerFixture _fixture; - readonly TestEventListener _listener; +public class ControllerTests { + readonly ServerFixture _fixture; public ControllerTests(WebApplicationFactory factory) { var commandMap = new CommandMap() @@ -31,14 +30,14 @@ public ControllerTests(WebApplicationFactory factory) { } ); - _listener = new(); + listener = new(); } [Test] public async Task RecordPaymentUsingMappedCommand(CancellationToken cancellationToken) { using var client = _fixture.GetClient(); - var bookRoom = _fixture.GetBookRoom(); + var bookRoom = ServerFixture.GetBookRoom(); await client.PostJsonAsync("/book", bookRoom, cancellationToken: cancellationToken); @@ -55,5 +54,11 @@ public async Task RecordPaymentUsingMappedCommand(CancellationToken cancellation last.Payload.Should().BeEquivalentTo(expected); } - public void Dispose() => _listener.Dispose(); + static TestEventListener? listener; + + [After(Class)] + public static void Dispose() => listener?.Dispose(); + + [Before(Class)] + public static void BeforeClass() => listener = new(); } diff --git a/src/Extensions/test/Eventuous.Tests.Extensions.AspNetCore/DiscoveredCommandsTests.cs b/src/Extensions/test/Eventuous.Tests.Extensions.AspNetCore/DiscoveredCommandsTests.cs index 05af186aa..1dd7a3b0c 100644 --- a/src/Extensions/test/Eventuous.Tests.Extensions.AspNetCore/DiscoveredCommandsTests.cs +++ b/src/Extensions/test/Eventuous.Tests.Extensions.AspNetCore/DiscoveredCommandsTests.cs @@ -16,7 +16,7 @@ public async Task CallDiscoveredCommandRoute() { app => app.MapDiscoveredCommands(typeof(NestedCommands).Assembly) ); - var cmd = fixture.GetNestedBookRoom(new DateTime(2023, 10, 1)); + var cmd = ServerFixture.GetNestedBookRoom(new DateTime(2023, 10, 1)); var streamEvents = await fixture.ExecuteRequest(cmd, NestedBookRoute, cmd.BookingId); await VerifyJson(streamEvents); } diff --git a/src/Extensions/test/Eventuous.Tests.Extensions.AspNetCore/Eventuous.Tests.Extensions.AspNetCore.csproj b/src/Extensions/test/Eventuous.Tests.Extensions.AspNetCore/Eventuous.Tests.Extensions.AspNetCore.csproj index 140f675d7..e38984dff 100644 --- a/src/Extensions/test/Eventuous.Tests.Extensions.AspNetCore/Eventuous.Tests.Extensions.AspNetCore.csproj +++ b/src/Extensions/test/Eventuous.Tests.Extensions.AspNetCore/Eventuous.Tests.Extensions.AspNetCore.csproj @@ -13,6 +13,7 @@ + diff --git a/src/Extensions/test/Eventuous.Tests.Extensions.AspNetCore/Fixture/ServerFixture.cs b/src/Extensions/test/Eventuous.Tests.Extensions.AspNetCore/Fixture/ServerFixture.cs index 36fed0e83..c89786ca8 100644 --- a/src/Extensions/test/Eventuous.Tests.Extensions.AspNetCore/Fixture/ServerFixture.cs +++ b/src/Extensions/test/Eventuous.Tests.Extensions.AspNetCore/Fixture/ServerFixture.cs @@ -9,8 +9,6 @@ namespace Eventuous.Tests.Extensions.AspNetCore.Fixture; using static SutBookingCommands; public class ServerFixture { - readonly AutoFixture.Fixture _fixture = new(); - public ServerFixture( WebApplicationFactory factory, Action? register = null, @@ -47,20 +45,22 @@ public RestClient GetClient() { public T Resolve() where T : notnull => _app.Services.GetRequiredService(); + static string RandomString() => Guid.NewGuid().ToString(); + public Task ReadStream(string id) => Resolve().ReadEvents(StreamName.For(id), StreamReadPosition.Start, 100, default); - internal BookRoom GetBookRoom() { + internal static BookRoom GetBookRoom() { var now = new DateTime(2023, 10, 1); var date = LocalDate.FromDateTime(now); - return new(_fixture.Create(), _fixture.Create(), date, date.PlusDays(1), 100, "guest"); + return new(RandomString(), RandomString(), date, date.PlusDays(1), 100, "guest"); } - internal NestedCommands.NestedBookRoom GetNestedBookRoom(DateTime? dateTime = null) { + internal static NestedCommands.NestedBookRoom GetNestedBookRoom(DateTime? dateTime = null) { var date = LocalDate.FromDateTime(dateTime ?? DateTime.Now); - return new(_fixture.Create(), _fixture.Create(), date, date.PlusDays(1), 100, "guest"); + return new(RandomString(), RandomString(), date, date.PlusDays(1), 100, "guest"); } public async Task ExecuteRequest(TCommand cmd, string route, string id) diff --git a/src/GooglePubSub/test/Eventuous.Tests.GooglePubSub/PubSubTests.cs b/src/GooglePubSub/test/Eventuous.Tests.GooglePubSub/PubSubTests.cs index 29374c77b..bc3b0eb38 100644 --- a/src/GooglePubSub/test/Eventuous.Tests.GooglePubSub/PubSubTests.cs +++ b/src/GooglePubSub/test/Eventuous.Tests.GooglePubSub/PubSubTests.cs @@ -12,8 +12,6 @@ namespace Eventuous.Tests.GooglePubSub; public class PubSubTests { static PubSubTests() => TypeMap.Instance.RegisterKnownEventTypes(typeof(TestEvent).Assembly); - static readonly Fixture Auto = new(); - readonly GooglePubSubSubscription _subscription; readonly GooglePubSubProducer _producer; readonly TestEventHandler _handler; @@ -50,7 +48,7 @@ public PubSubTests(PubSubFixture _) { [Test] [Retry(3)] public async Task SubscribeAndProduce(CancellationToken cancellationToken) { - var testEvent = Auto.Create(); + var testEvent = TestEvent.Create(); await _producer.Produce(_pubsubTopic, testEvent, null, cancellationToken: cancellationToken); @@ -62,7 +60,7 @@ public async Task SubscribeAndProduce(CancellationToken cancellationToken) { public async Task SubscribeAndProduceMany(CancellationToken cancellationToken) { const int count = 10000; - var testEvents = Auto.CreateMany(count).ToList(); + var testEvents = TestEvent.CreateMany(count); await _producer.Produce(_pubsubTopic, testEvents, null, cancellationToken: cancellationToken); await _handler.AssertCollection(40.Seconds(), [..testEvents]).Validate(cancellationToken); @@ -81,5 +79,6 @@ public async Task DisposeAsync(CancellationToken cancellationToken) { await PubSubFixture.DeleteSubscription(_pubsubSubscription, cancellationToken); await PubSubFixture.DeleteTopic(_pubsubTopic, cancellationToken); + await _subscription.DisposeAsync(); } } diff --git a/src/Kafka/test/Eventuous.Tests.Kafka/BasicProducerTests.cs b/src/Kafka/test/Eventuous.Tests.Kafka/BasicProducerTests.cs index 4c2fcabef..426809b98 100644 --- a/src/Kafka/test/Eventuous.Tests.Kafka/BasicProducerTests.cs +++ b/src/Kafka/test/Eventuous.Tests.Kafka/BasicProducerTests.cs @@ -20,14 +20,12 @@ public BasicProducerTests(KafkaFixture fixture) { TypeMap.Instance.AddType("testEvent"); } - static readonly Fixture Auto = new(); - [Test] public async Task ShouldProduceAndWait(CancellationToken cancellationToken) { - var topicName = Auto.Create(); + var topicName = Guid.NewGuid().ToString(); TestContext.Current?.OutputWriter.WriteLine($"Topic: {topicName}"); - var events = Auto.CreateMany().ToArray(); + var events = TestEvent.CreateMany(10); await Produce(); @@ -52,7 +50,7 @@ async Task ExecuteConsume() { while (!cts.IsCancellationRequested) { await Consume(consumer, cts.Token); - if (consumed.Count == events.Length) break; + if (consumed.Count == events.Count) break; } } diff --git a/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/Eventuous.Tests.Projections.MongoDB.csproj b/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/Eventuous.Tests.Projections.MongoDB.csproj index 406194be9..e25960ca1 100644 --- a/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/Eventuous.Tests.Projections.MongoDB.csproj +++ b/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/Eventuous.Tests.Projections.MongoDB.csproj @@ -13,6 +13,7 @@ + diff --git a/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/Fixtures/DomainFixture.cs b/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/Fixtures/DomainFixture.cs index 4e2c921dc..bac34e09e 100644 --- a/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/Fixtures/DomainFixture.cs +++ b/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/Fixtures/DomainFixture.cs @@ -1,25 +1,31 @@ +using Bogus; using Eventuous.Projections.MongoDB.Tools; +using Eventuous.Sut.App; +using Eventuous.Sut.Domain; using NodaTime; -using static Eventuous.Sut.Domain.BookingEvents; namespace Eventuous.Tests.Projections.MongoDB.Fixtures; public static class DomainFixture { - static Fixture Auto { get; } = new(); + static DomainFixture() => TypeMap.RegisterKnownEventTypes(typeof(BookingEvents.BookingImported).Assembly); - static DomainFixture() - => TypeMap.RegisterKnownEventTypes(); - - public static BookingImported CreateImportBooking() { - var from = Auto.Create(); - - return new BookingImported( - Auto.Create(), - Auto.Create(), - LocalDate.FromDateTime(from), - LocalDate.FromDateTime(from.AddDays(Auto.Create())) + static Faker CmdFaker => new Faker() + .RuleFor(x => x.BookingId, _ => Guid.NewGuid().ToString("N")) + .RuleFor(x => x.RoomId, _ => Guid.NewGuid().ToString("N")) + .RuleFor(x => x.Price, f => f.Random.Number(50, 200)) + .RuleFor(x => x.CheckIn, f => f.Noda().LocalDate.Soon()) + .RuleFor(x => x.CheckOut, (f, c) => c.CheckIn.PlusDays(f.Random.Number(1, 5))); + + static Faker EventFaker => new Faker() + .CustomInstantiator(f => { + var checkIn = f.Noda().LocalDate.Soon(); + return new(f.Commerce.Product(), f.Random.Number(50, 200), checkIn, checkIn.PlusDays(f.Random.Number(1, 5))); + } ); - } + + public static Commands.ImportBooking CreateImportBooking() => CmdFaker.Generate(); + + public static BookingEvents.BookingImported CreateImportBookingEvent() => EventFaker.Generate(); } public record BookingDocument(string Id) : ProjectedDocument(Id) { diff --git a/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/Fixtures/IntegrationFixture.cs b/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/Fixtures/IntegrationFixture.cs index 8f3d66416..e518342ff 100644 --- a/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/Fixtures/IntegrationFixture.cs +++ b/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/Fixtures/IntegrationFixture.cs @@ -1,3 +1,4 @@ +using System.Runtime.InteropServices; using EventStore.Client; using Eventuous.EventStore; using Eventuous.TestHelpers; @@ -13,7 +14,6 @@ public sealed class IntegrationFixture : IAsyncInitializer, IAsyncDisposable { public IEventStore EventStore { get; set; } = null!; public EventStoreClient Client { get; private set; } = null!; public IMongoDatabase Mongo { get; private set; } = null!; - public Fixture Auto { get; } = new(); static IEventSerializer Serializer { get; } = new DefaultEventSerializer(TestPrimitives.DefaultOptions); @@ -34,12 +34,15 @@ static IntegrationFixture() { MongoDbContainer _mongoContainer = null!; public async Task InitializeAsync() { - _esdbContainer = new EventStoreDbBuilder().Build(); + var image = RuntimeInformation.ProcessArchitecture == Architecture.Arm64 + ? "eventstore/eventstore:24.6.0-alpha-arm64v8" + : "eventstore/eventstore:24.6"; + _esdbContainer = new EventStoreDbBuilder().WithImage(image).Build(); await _esdbContainer.StartAsync(); var settings = EventStoreClientSettings.Create(_esdbContainer.GetConnectionString()); Client = new(settings); EventStore = new EsdbEventStore(Client); - _mongoContainer = new MongoDbBuilder().Build(); + _mongoContainer = new MongoDbBuilder().WithImage("mongo:8").Build(); await _mongoContainer.StartAsync(); var mongoSettings = MongoClientSettings.FromConnectionString(_mongoContainer.GetConnectionString()); Mongo = new MongoClient(mongoSettings).GetDatabase("bookings"); diff --git a/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/ProjectWithBuilder.cs b/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/ProjectWithBuilder.cs index 8f5273ddb..ad81a9c1f 100644 --- a/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/ProjectWithBuilder.cs +++ b/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/ProjectWithBuilder.cs @@ -12,11 +12,11 @@ public class ProjectWithBuilder(IntegrationFixture fixture) { [Test] [MethodDataSource(typeof(CollectionSource), nameof(CollectionSource.TestOptions))] public async Task ShouldProjectImported(MongoProjectionOptions? options) { + var evt = DomainFixture.CreateImportBookingEvent(); var projectionFixture = new ProjectionTestBase(nameof(ProjectWithBuilder), fixture); - var evt = DomainFixture.CreateImportBooking(); var id = new BookingId(projectionFixture.CreateId()); var stream = StreamNameFactory.For(id); - + await projectionFixture.InitializeAsync(); var first = await Act(projectionFixture, stream, evt); @@ -33,7 +33,7 @@ public async Task ShouldProjectImported(MongoProjectionOptions? first.Doc.Should().BeEquivalentTo(expected); - var payment = new BookingPaymentRegistered(projectionFixture.Fixture.Auto.Create(), evt.Price); + var payment = new BookingPaymentRegistered(Guid.NewGuid().ToString(), evt.Price); var second = await Act(projectionFixture, stream, payment); @@ -94,8 +94,8 @@ public SutProjection(IMongoDatabase database) : base(database) { } public static class CollectionSource { - public static IEnumerable?> TestOptions() { - yield return null; - yield return new() { CollectionName = "test" }; + public static IEnumerable?>> TestOptions() { + yield return () => null; + yield return () => new() { CollectionName = "test" }; } } diff --git a/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/ProjectWithBulkBuilder.cs b/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/ProjectWithBulkBuilder.cs index a976cbc67..921f9ef89 100644 --- a/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/ProjectWithBulkBuilder.cs +++ b/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/ProjectWithBulkBuilder.cs @@ -12,7 +12,7 @@ public class ProjectWithBulkBuilder(IntegrationFixture fixture) : ProjectionTest [Test] public async Task ShouldProjectImported() { await InitializeAsync(); - var evt = DomainFixture.CreateImportBooking(); + var evt = DomainFixture.CreateImportBookingEvent(); var id = new BookingId(CreateId()); var stream = StreamNameFactory.For(id); @@ -30,7 +30,7 @@ public async Task ShouldProjectImported() { first.Doc.Should().BeEquivalentTo(expected); - var payment = new BookingPaymentRegistered(Fixture.Auto.Create(), evt.Price); + var payment = new BookingPaymentRegistered(Guid.NewGuid().ToString(), evt.Price); var second = await Act(stream, payment); await DisposeAsync(); diff --git a/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/ProjectingWithTypedHandlers.cs b/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/ProjectingWithTypedHandlers.cs index 3ce2347f8..4fdd8197e 100644 --- a/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/ProjectingWithTypedHandlers.cs +++ b/src/Mongo/test/Eventuous.Tests.Projections.MongoDB/ProjectingWithTypedHandlers.cs @@ -13,7 +13,7 @@ public sealed class ProjectingWithTypedHandlers(IntegrationFixture fixture) [Test] public async Task ShouldProjectImported(CancellationToken cancellationToken) { await InitializeAsync(); - var evt = DomainFixture.CreateImportBooking(); + var evt = DomainFixture.CreateImportBookingEvent(); var id = new BookingId(CreateId()); var stream = StreamNameFactory.For(id); diff --git a/src/Postgres/test/Eventuous.Tests.Postgres/Eventuous.Tests.Postgres.csproj b/src/Postgres/test/Eventuous.Tests.Postgres/Eventuous.Tests.Postgres.csproj index 84c31fafe..ac943b456 100644 --- a/src/Postgres/test/Eventuous.Tests.Postgres/Eventuous.Tests.Postgres.csproj +++ b/src/Postgres/test/Eventuous.Tests.Postgres/Eventuous.Tests.Postgres.csproj @@ -6,11 +6,9 @@ Exe - - diff --git a/src/Postgres/test/Eventuous.Tests.Postgres/Projections/ProjectorTests.cs b/src/Postgres/test/Eventuous.Tests.Postgres/Projections/ProjectorTests.cs index b01c61df1..ef3ce8712 100644 --- a/src/Postgres/test/Eventuous.Tests.Postgres/Projections/ProjectorTests.cs +++ b/src/Postgres/test/Eventuous.Tests.Postgres/Projections/ProjectorTests.cs @@ -52,7 +52,7 @@ async Task CreateSchema() { async Task> GenerateAndProduceEvents(int count) { var commands = Enumerable .Range(0, count) - .Select(_ => DomainFixture.CreateImportBooking(_fixture.Auto)) + .Select(_ => DomainFixture.CreateImportBooking()) .ToList(); foreach (var command in commands) { diff --git a/src/Postgres/test/Eventuous.Tests.Postgres/Subscriptions/SubscribeTests.cs b/src/Postgres/test/Eventuous.Tests.Postgres/Subscriptions/SubscribeTests.cs index 8051d0d27..0825c95ed 100644 --- a/src/Postgres/test/Eventuous.Tests.Postgres/Subscriptions/SubscribeTests.cs +++ b/src/Postgres/test/Eventuous.Tests.Postgres/Subscriptions/SubscribeTests.cs @@ -56,7 +56,5 @@ static void ConfigureOptions(PostgresStreamSubscriptionOptions options, StreamNa } public class StreamNameFixture { - static readonly Fixture Auto = new(); - - public StreamName StreamName = new(Auto.Create()); + public StreamName StreamName = new(Guid.NewGuid().ToString()); } diff --git a/src/RabbitMq/test/Eventuous.Tests.RabbitMq/Eventuous.Tests.RabbitMq.csproj b/src/RabbitMq/test/Eventuous.Tests.RabbitMq/Eventuous.Tests.RabbitMq.csproj index aa2febb01..b08d4560f 100644 --- a/src/RabbitMq/test/Eventuous.Tests.RabbitMq/Eventuous.Tests.RabbitMq.csproj +++ b/src/RabbitMq/test/Eventuous.Tests.RabbitMq/Eventuous.Tests.RabbitMq.csproj @@ -8,7 +8,5 @@ - - diff --git a/src/RabbitMq/test/Eventuous.Tests.RabbitMq/SubscriptionSpec.cs b/src/RabbitMq/test/Eventuous.Tests.RabbitMq/SubscriptionSpec.cs index dc47f90b0..41f9e2cf5 100644 --- a/src/RabbitMq/test/Eventuous.Tests.RabbitMq/SubscriptionSpec.cs +++ b/src/RabbitMq/test/Eventuous.Tests.RabbitMq/SubscriptionSpec.cs @@ -12,28 +12,25 @@ namespace Eventuous.Tests.RabbitMq; public class SubscriptionSpec { static SubscriptionSpec() => TypeMap.Instance.RegisterKnownEventTypes(typeof(TestEvent).Assembly); - static readonly Fixture Auto = new(); - RabbitMqSubscription _subscription = null!; RabbitMqProducer _producer = null!; TestEventHandler _handler = null!; + TestEventListener _es = null!; readonly StreamName _exchange; readonly ILogger _log; - readonly TestEventListener _es; readonly ILoggerFactory _loggerFactory; readonly RabbitMqFixture _fixture; public SubscriptionSpec(RabbitMqFixture fixture) { _fixture = fixture; - _es = new(); - _exchange = new(Auto.Create()); + _exchange = new(Guid.NewGuid().ToString()); _loggerFactory = LoggingExtensions.GetLoggerFactory(); _log = _loggerFactory.CreateLogger(); } [Test] public async Task SubscribeAndProduce(CancellationToken cancellationToken) { - var testEvent = Auto.Create(); + var testEvent = TestEvent.Create(); await _producer.Produce(_exchange, testEvent, new(), cancellationToken: cancellationToken); await _handler.AssertThat().Timebox(10.Seconds()).Any().Match(x => x as TestEvent == testEvent).Validate(cancellationToken); } @@ -42,17 +39,18 @@ public async Task SubscribeAndProduce(CancellationToken cancellationToken) { public async Task SubscribeAndProduceMany(CancellationToken cancellationToken) { const int count = 10000; - var testEvents = Auto.CreateMany(count).ToList(); + var testEvents = TestEvent.CreateMany(count); await _producer.Produce(_exchange, testEvents, new(), cancellationToken: cancellationToken); await _handler.AssertCollection(30.Seconds(), [..testEvents]).Validate(cancellationToken); } [Before(Test)] public async ValueTask InitializeAsync() { + _es = new(); _handler = new(); _producer = new(_fixture.ConnectionFactory); - var queue = Auto.Create(); + var queue = Guid.NewGuid().ToString(); _subscription = new( _fixture.ConnectionFactory, @@ -74,5 +72,6 @@ public async ValueTask DisposeAsync() { await _producer.StopAsync(); await _subscription.UnsubscribeWithLog(_log); _es.Dispose(); + await _subscription.DisposeAsync(); } } diff --git a/src/Redis/test/Eventuous.Tests.Redis/Eventuous.Tests.Redis.csproj b/src/Redis/test/Eventuous.Tests.Redis/Eventuous.Tests.Redis.csproj index 1c4a49dd8..f7cf6e2c7 100644 --- a/src/Redis/test/Eventuous.Tests.Redis/Eventuous.Tests.Redis.csproj +++ b/src/Redis/test/Eventuous.Tests.Redis/Eventuous.Tests.Redis.csproj @@ -4,7 +4,6 @@ Exe - diff --git a/src/Redis/test/Eventuous.Tests.Redis/Fixtures/DomainFixture.cs b/src/Redis/test/Eventuous.Tests.Redis/Fixtures/DomainFixture.cs index f5fd0c50c..7b66114df 100644 --- a/src/Redis/test/Eventuous.Tests.Redis/Fixtures/DomainFixture.cs +++ b/src/Redis/test/Eventuous.Tests.Redis/Fixtures/DomainFixture.cs @@ -1,21 +1,18 @@ +using Bogus; using Eventuous.Sut.App; using Eventuous.Sut.Domain; -using MicroElements.AutoFixture.NodaTime; -using NodaTime; namespace Eventuous.Tests.Redis.Fixtures; public static class DomainFixture { - static IFixture Auto { get; } = new Fixture().Customize(new NodaTimeCustomization()); - static DomainFixture() => TypeMap.RegisterKnownEventTypes(typeof(BookingEvents.BookingImported).Assembly); + + static Faker Faker => new Faker() + .RuleFor(x => x.BookingId, _ => Guid.NewGuid().ToString("N")) + .RuleFor(x => x.RoomId, _ => Guid.NewGuid().ToString("N")) + .RuleFor(x => x.Price, f => f.Random.Number(50, 200)) + .RuleFor(x => x.CheckIn, f => f.Noda().LocalDate.Soon()) + .RuleFor(x => x.CheckOut, (f, c) => c.CheckIn.PlusDays(f.Random.Number(1, 5))); - public static Commands.ImportBooking CreateImportBooking() { - var from = Auto.Create(); - - return Auto.Build() - .With(x => x.CheckIn, from) - .With(x => x.CheckOut, from.PlusDays(2)) - .Create(); - } + public static Commands.ImportBooking CreateImportBooking() => Faker.Generate(); } diff --git a/src/Redis/test/Eventuous.Tests.Redis/Fixtures/SharedAutoFixture.cs b/src/Redis/test/Eventuous.Tests.Redis/Fixtures/SharedAutoFixture.cs deleted file mode 100644 index 7e34c985a..000000000 --- a/src/Redis/test/Eventuous.Tests.Redis/Fixtures/SharedAutoFixture.cs +++ /dev/null @@ -1,7 +0,0 @@ -using MicroElements.AutoFixture.NodaTime; - -namespace Eventuous.Tests.Redis.Fixtures; - -public static class SharedAutoFixture { - public static IFixture Auto { get; } = new Fixture().Customize(new NodaTimeCustomization()); -} diff --git a/src/Redis/test/Eventuous.Tests.Redis/Fixtures/SubscriptionFixture.cs b/src/Redis/test/Eventuous.Tests.Redis/Fixtures/SubscriptionFixture.cs index c16843b57..3e305e59d 100644 --- a/src/Redis/test/Eventuous.Tests.Redis/Fixtures/SubscriptionFixture.cs +++ b/src/Redis/test/Eventuous.Tests.Redis/Fixtures/SubscriptionFixture.cs @@ -21,7 +21,7 @@ namespace Eventuous.Tests.Redis.Fixtures; public SubscriptionFixture(bool subscribeToAll, LogLevel logLevel = LogLevel.Trace) { Handler = new T(); _subscribeToAll = subscribeToAll; - Stream = new(SharedAutoFixture.Auto.Create()); + Stream = new(Guid.NewGuid().ToString()); LoggerFactory = LoggingExtensions.GetLoggerFactory(logLevel); SubscriptionId = $"test-{Guid.NewGuid():N}"; Log = LoggerFactory.CreateLogger(GetType()); diff --git a/src/Redis/test/Eventuous.Tests.Redis/Store/Helpers.cs b/src/Redis/test/Eventuous.Tests.Redis/Store/Helpers.cs index 5a17bb584..0d0fe3daa 100644 --- a/src/Redis/test/Eventuous.Tests.Redis/Store/Helpers.cs +++ b/src/Redis/test/Eventuous.Tests.Redis/Store/Helpers.cs @@ -5,11 +5,9 @@ namespace Eventuous.Tests.Redis.Store; public static class Helpers { - public static StreamName GetStreamName() - => new(SharedAutoFixture.Auto.Create()); + public static StreamName GetStreamName() => new(Guid.NewGuid().ToString("N")); - public static BookingImported CreateEvent() - => ToEvent(DomainFixture.CreateImportBooking()); + public static BookingImported CreateEvent() => ToEvent(DomainFixture.CreateImportBooking()); public static IEnumerable CreateEvents(int count) { for (var i = 0; i < count; i++) { diff --git a/src/SqlServer/test/Eventuous.Tests.SqlServer/Eventuous.Tests.SqlServer.csproj b/src/SqlServer/test/Eventuous.Tests.SqlServer/Eventuous.Tests.SqlServer.csproj index 994fe7e25..f18110cb9 100644 --- a/src/SqlServer/test/Eventuous.Tests.SqlServer/Eventuous.Tests.SqlServer.csproj +++ b/src/SqlServer/test/Eventuous.Tests.SqlServer/Eventuous.Tests.SqlServer.csproj @@ -5,7 +5,6 @@ Exe - @@ -17,8 +16,4 @@ - - - - \ No newline at end of file diff --git a/src/SqlServer/test/Eventuous.Tests.SqlServer/Projections/ProjectorTests.cs b/src/SqlServer/test/Eventuous.Tests.SqlServer/Projections/ProjectorTests.cs index 0f9b428f5..dd976305c 100644 --- a/src/SqlServer/test/Eventuous.Tests.SqlServer/Projections/ProjectorTests.cs +++ b/src/SqlServer/test/Eventuous.Tests.SqlServer/Projections/ProjectorTests.cs @@ -62,7 +62,7 @@ async Task CreateSchema() { async Task> GenerateAndProduceEvents(int count) { var commands = Enumerable .Range(0, count) - .Select(_ => DomainFixture.CreateImportBooking(_fixture.Auto)) + .Select(_ => DomainFixture.CreateImportBooking()) .ToList(); foreach (var command in commands) { diff --git a/src/SqlServer/test/Eventuous.Tests.SqlServer/Subscriptions/SubscribeTests.cs b/src/SqlServer/test/Eventuous.Tests.SqlServer/Subscriptions/SubscribeTests.cs index 84390b79d..289f564aa 100644 --- a/src/SqlServer/test/Eventuous.Tests.SqlServer/Subscriptions/SubscribeTests.cs +++ b/src/SqlServer/test/Eventuous.Tests.SqlServer/Subscriptions/SubscribeTests.cs @@ -56,7 +56,5 @@ static void ConfigureOptions(SqlServerStreamSubscriptionOptions options, StreamN } public class StreamNameFixture { - static readonly Fixture Auto = new(); - - public StreamName StreamName = new(Auto.Create()); + public StreamName StreamName = new(Guid.NewGuid().ToString()); } diff --git a/test/Eventuous.TestHelpers.TUnit/Assertions.cs b/test/Eventuous.TestHelpers.TUnit/Assertions.cs new file mode 100644 index 000000000..11580e18c --- /dev/null +++ b/test/Eventuous.TestHelpers.TUnit/Assertions.cs @@ -0,0 +1,55 @@ +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using TUnit.Assertions.AssertConditions.Interfaces; +using TUnit.Assertions.AssertionBuilders; +using TUnit.Assertions.Enums; + +namespace Eventuous.TestHelpers.TUnit; + +[SuppressMessage("Usage", "TUnitAssertions0003:Compiler argument populated")] +public static class Assertions { + public static InvokableValueAssertionBuilder CollectionEquivalentTo + <[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TActual, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TInner>( + this IValueSource valueSource, + IEnumerable expected, + [CallerArgumentExpression(nameof(expected))] string doNotPopulateThisValue = "" + ) + where TActual : IEnumerable { + return CollectionsIsExtensions.IsEquivalentTo(valueSource, expected, doNotPopulateThisValue); + } + + public static InvokableValueAssertionBuilder CollectionIsEquivalentTo + <[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TActual, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TInner>( + this IValueSource valueSource, + IEnumerable expected, + IEqualityComparer comparer, + [CallerArgumentExpression(nameof(expected))] string doNotPopulateThisValue = "" + ) + where TActual : IEnumerable { + return CollectionsIsExtensions.IsEquivalentTo(valueSource, expected, comparer, doNotPopulateThisValue); + } + + public static InvokableValueAssertionBuilder CollectionEquivalentTo + <[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TActual, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TInner>( + this IValueSource valueSource, + IEnumerable expected, + CollectionOrdering collectionOrdering, + [CallerArgumentExpression(nameof(expected))] string doNotPopulateThisValue = "" + ) + where TActual : IEnumerable { + return CollectionsIsExtensions.IsEquivalentTo(valueSource, expected, collectionOrdering, doNotPopulateThisValue); + } + + public static InvokableValueAssertionBuilder CollectionEquivalentTo + <[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TActual, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TInner>( + this IValueSource valueSource, + IEnumerable expected, + IEqualityComparer comparer, + CollectionOrdering collectionOrdering, + [CallerArgumentExpression(nameof(expected))] string doNotPopulateThisValue = "" + ) + where TActual : IEnumerable { + return CollectionsIsExtensions.IsEquivalentTo(valueSource, expected, comparer, collectionOrdering, doNotPopulateThisValue); + } + +} diff --git a/test/Eventuous.TestHelpers.TUnit/Eventuous.TestHelpers.TUnit.csproj b/test/Eventuous.TestHelpers.TUnit/Eventuous.TestHelpers.TUnit.csproj index 0c19ddd67..96a1b2d0d 100644 --- a/test/Eventuous.TestHelpers.TUnit/Eventuous.TestHelpers.TUnit.csproj +++ b/test/Eventuous.TestHelpers.TUnit/Eventuous.TestHelpers.TUnit.csproj @@ -5,6 +5,7 @@ +