From 5f35713af3fa7387807ecc3626c21139c251ea78 Mon Sep 17 00:00:00 2001 From: Focus Date: Sat, 14 Jun 2025 12:31:25 +0300 Subject: [PATCH 01/13] Add shouldly --- Source/EventFlow.Tests/EventFlow.Tests.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/EventFlow.Tests/EventFlow.Tests.csproj b/Source/EventFlow.Tests/EventFlow.Tests.csproj index 29f1502c4..89e630555 100644 --- a/Source/EventFlow.Tests/EventFlow.Tests.csproj +++ b/Source/EventFlow.Tests/EventFlow.Tests.csproj @@ -10,6 +10,7 @@ + From fd319b8c57dae0955b52685a13c0501497ad4297 Mon Sep 17 00:00:00 2001 From: Focus Date: Sat, 14 Jun 2025 12:31:35 +0300 Subject: [PATCH 02/13] Replace in LicenseHeaderTests --- Source/EventFlow.Tests/LicenseHeaderTests.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/EventFlow.Tests/LicenseHeaderTests.cs b/Source/EventFlow.Tests/LicenseHeaderTests.cs index 0175c4f4b..b37536771 100644 --- a/Source/EventFlow.Tests/LicenseHeaderTests.cs +++ b/Source/EventFlow.Tests/LicenseHeaderTests.cs @@ -27,9 +27,10 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using EventFlow.TestHelpers; -using FluentAssertions; using NUnit.Framework; +using Shouldly; +// ReSharper disable StringLiteralTypo // ReSharper disable StringLiteralTypo namespace EventFlow.Tests @@ -61,7 +62,7 @@ public async Task EveryFileHasCorrectLicenseHeader() var sourceFiles = await Task.WhenAll(sourceFilesPaths.Select(GetSourceFileAsync)); // Sanity asserts - sourceFiles.Should().HaveCountGreaterThan(700); + sourceFiles.Length.ShouldBeGreaterThan(700); // Missing headers var missingHeaders = sourceFiles @@ -79,8 +80,8 @@ public async Task EveryFileHasCorrectLicenseHeader() validationErrors.ForEach(Console.WriteLine); // Asserts - missingHeaders.Should().BeEmpty(); - validationErrors.Should().BeEmpty(); + missingHeaders.ShouldBeEmpty(); + validationErrors.ShouldBeEmpty(); } private static string PathRelativeTo(string root, string fullPath) From 8b3e0c1e6fe3b86a81ab3edf5f4710f158148d14 Mon Sep 17 00:00:00 2001 From: Focus Date: Sat, 14 Jun 2025 12:53:55 +0300 Subject: [PATCH 03/13] More replaces --- .../CustomAggregateIdExplorationTest.cs | 4 +-- .../EventUpgradeExplorationTest.cs | 4 +-- .../RegisterSubscribersExplorationTests.cs | 4 +-- .../GuidFactoriesDeterministicTests.cs | 4 +-- .../UnitTests/Core/IdentityTests.cs | 27 ++++++++++--------- .../UnitTests/Core/ReflectionHelperTests.cs | 8 +++--- .../UnitTests/Core/RetryDelayTests.cs | 6 ++--- ...OptimisticConcurrencyRetryStrategyTests.cs | 6 ++--- .../Core/TransientFaultHandlerTests.cs | 10 +++---- ...VersionedTypeDefinitionServiceTestSuite.cs | 24 ++++++++--------- 10 files changed, 49 insertions(+), 48 deletions(-) diff --git a/Source/EventFlow.Tests/Exploration/CustomAggregateIdExplorationTest.cs b/Source/EventFlow.Tests/Exploration/CustomAggregateIdExplorationTest.cs index d3938991f..bca593b27 100644 --- a/Source/EventFlow.Tests/Exploration/CustomAggregateIdExplorationTest.cs +++ b/Source/EventFlow.Tests/Exploration/CustomAggregateIdExplorationTest.cs @@ -25,9 +25,9 @@ using EventFlow.Aggregates; using EventFlow.Core; using EventFlow.TestHelpers; -using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.Exploration { @@ -48,7 +48,7 @@ public async Task AggregatesCanHaveCustomImplementedIdentity() var customAggregate = await aggregateStore.LoadAsync(customId, CancellationToken.None).ConfigureAwait(false); // Assert - customAggregate.Id.Value.Should().Be(customId.Value); + customAggregate.Id.Value.ShouldBe(customId.Value); } } diff --git a/Source/EventFlow.Tests/Exploration/EventUpgradeExplorationTest.cs b/Source/EventFlow.Tests/Exploration/EventUpgradeExplorationTest.cs index a68a13ff0..6b035fc7c 100644 --- a/Source/EventFlow.Tests/Exploration/EventUpgradeExplorationTest.cs +++ b/Source/EventFlow.Tests/Exploration/EventUpgradeExplorationTest.cs @@ -29,9 +29,9 @@ using EventFlow.EventStores; using EventFlow.Extensions; using EventFlow.TestHelpers; -using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.Exploration { @@ -77,7 +77,7 @@ await aggregateStore.UpdateAsync( var aggregate = await aggregateStore.LoadAsync( id, CancellationToken.None); - aggregate.V2Applied.Should().BeTrue(); + aggregate.V2Applied.ShouldBeTrue(); } public class SourceId : ISourceId diff --git a/Source/EventFlow.Tests/Exploration/RegisterSubscribersExplorationTests.cs b/Source/EventFlow.Tests/Exploration/RegisterSubscribersExplorationTests.cs index f89cbf3cf..920f5a856 100644 --- a/Source/EventFlow.Tests/Exploration/RegisterSubscribersExplorationTests.cs +++ b/Source/EventFlow.Tests/Exploration/RegisterSubscribersExplorationTests.cs @@ -34,9 +34,9 @@ using EventFlow.TestHelpers.Aggregates.Events; using EventFlow.TestHelpers.Aggregates.Queries; using EventFlow.TestHelpers.Aggregates.ValueObjects; -using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.Exploration { @@ -68,7 +68,7 @@ await commandBus.PublishAsync( } // Assert - wasHandled.Should().BeTrue(); + wasHandled.ShouldBeTrue(); } public static IEnumerable> TestCases() diff --git a/Source/EventFlow.Tests/UnitTests/Core/GuidFactories/GuidFactoriesDeterministicTests.cs b/Source/EventFlow.Tests/UnitTests/Core/GuidFactories/GuidFactoriesDeterministicTests.cs index 95958286a..caef88f7b 100644 --- a/Source/EventFlow.Tests/UnitTests/Core/GuidFactories/GuidFactoriesDeterministicTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Core/GuidFactories/GuidFactoriesDeterministicTests.cs @@ -25,8 +25,8 @@ using System.Linq; using AutoFixture; using EventFlow.TestHelpers; -using FluentAssertions; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Core.GuidFactories { @@ -52,7 +52,7 @@ public void Create_EmptyNameBytes_ThrowsArgumentNullException() public void Create(Guid namespaceId, byte[] nameBytes, Guid expected) { var result = EventFlow.Core.GuidFactories.Deterministic.Create(namespaceId, nameBytes); - result.Should().Be(expected); + result.ShouldBe(expected); } private static IEnumerable GetTestCases() diff --git a/Source/EventFlow.Tests/UnitTests/Core/IdentityTests.cs b/Source/EventFlow.Tests/UnitTests/Core/IdentityTests.cs index b32ec053f..ee8c02fc8 100644 --- a/Source/EventFlow.Tests/UnitTests/Core/IdentityTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Core/IdentityTests.cs @@ -24,7 +24,7 @@ using EventFlow.Core; using EventFlow.TestHelpers; using EventFlow.TestHelpers.Aggregates; -using FluentAssertions; +using Shouldly; using NUnit.Framework; namespace EventFlow.Tests.UnitTests.Core @@ -43,8 +43,8 @@ public void NewDeterministic_ReturnsKnownResult() var testId = ThingyId.NewDeterministic(namespaceId, name); // Assert - testId.Value.Should().Be("thingy-da7ab6b1-c513-581f-a1a0-7cdf17109deb"); - ThingyId.IsValid(testId.Value).Should().BeTrue(); + testId.Value.ShouldBe("thingy-da7ab6b1-c513-581f-a1a0-7cdf17109deb"); + ThingyId.IsValid(testId.Value).ShouldBeTrue(); } [TestCase("thingy-da7ab6b1-c513-581f-a1a0-7cdf17109deb", "da7ab6b1-c513-581f-a1a0-7cdf17109deb")] @@ -59,9 +59,9 @@ public void WithValidValue(string value, string expectedGuidValue) Assert.DoesNotThrow(() => thingyId = ThingyId.With(value)); // Assert - thingyId.Should().NotBeNull(); - thingyId.Value.Should().Be(value); - thingyId.GetGuid().Should().Be(expectedGuid); + thingyId.ShouldNotBeNull(); + thingyId.Value.ShouldBe(value); + thingyId.GetGuid().ShouldBe(expectedGuid); } [Test] @@ -74,7 +74,7 @@ public void InputOutput() var thingyId = ThingyId.With(guid); // Assert - thingyId.GetGuid().Should().Be(guid); + thingyId.GetGuid().ShouldBe(guid); } [Test] @@ -84,7 +84,7 @@ public void ShouldBeLowerCase() var testId = ThingyId.New; // Assert - testId.Value.Should().Be(testId.Value.ToLowerInvariant()); + testId.Value.ShouldBe(testId.Value.ToLowerInvariant()); } [Test] @@ -94,7 +94,7 @@ public void New_IsValid() var testId = ThingyId.New; // Assert - ThingyId.IsValid(testId.Value).Should().BeTrue(testId.Value); + ThingyId.IsValid(testId.Value).ShouldBeTrue(testId.Value); } [Test] @@ -104,7 +104,7 @@ public void NewComb_IsValid() var testId = ThingyId.NewComb(); // Assert - ThingyId.IsValid(testId.Value).Should().BeTrue(testId.Value); + ThingyId.IsValid(testId.Value).ShouldBeTrue(testId.Value); } [Test] @@ -114,7 +114,7 @@ public void NewDeterministic_IsValid() var testId = ThingyId.NewDeterministic(Guid.NewGuid(), Guid.NewGuid().ToString()); // Assert - ThingyId.IsValid(testId.Value).Should().BeTrue(testId.Value); + ThingyId.IsValid(testId.Value).ShouldBeTrue(testId.Value); } [TestCase("da7ab6b1-c513-581f-a1a0-7cdf17109deb")] @@ -127,7 +127,8 @@ public void NewDeterministic_IsValid() public void CannotCreateBadIds(string badIdValue) { // Act - Assert.Throws(() => ThingyId.With(badIdValue)).Message.Should().Contain("Identity is invalid:"); + var exception = Assert.Throws(() => ThingyId.With(badIdValue)); + exception.Message.ShouldContain("Identity is invalid:"); } public class Id : Identity @@ -148,7 +149,7 @@ public void JustId() var id = Id.With(guid); // Assert - id.Value.Should().Be(expected); + id.Value.ShouldBe(expected); } } } diff --git a/Source/EventFlow.Tests/UnitTests/Core/ReflectionHelperTests.cs b/Source/EventFlow.Tests/UnitTests/Core/ReflectionHelperTests.cs index c9de8a0d0..153300696 100644 --- a/Source/EventFlow.Tests/UnitTests/Core/ReflectionHelperTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Core/ReflectionHelperTests.cs @@ -23,8 +23,8 @@ using System; using EventFlow.Core; using EventFlow.TestHelpers; -using FluentAssertions; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Core { @@ -39,7 +39,7 @@ public void CompileMethodInvocation() var result = caller(new Calculator(), 1, 2); // Assert - result.Should().Be(3); + result.ShouldBe(3); } [Test] @@ -55,7 +55,7 @@ public void CompileMethodInvocation_CanUpcast() // Assert var c = (Number) result; - c.I.Should().Be(3); + c.I.ShouldBe(3); } [Test] @@ -71,7 +71,7 @@ public void CompileMethodInvocation_CanDoBothUpcastAndPass() // Assert var c = (Number)result; - c.I.Should().Be(3); + c.I.ShouldBe(3); } public interface INumber { } diff --git a/Source/EventFlow.Tests/UnitTests/Core/RetryDelayTests.cs b/Source/EventFlow.Tests/UnitTests/Core/RetryDelayTests.cs index 86d6a9950..b5163a549 100644 --- a/Source/EventFlow.Tests/UnitTests/Core/RetryDelayTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Core/RetryDelayTests.cs @@ -23,8 +23,8 @@ using System; using EventFlow.Core; using EventFlow.TestHelpers; -using FluentAssertions; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Core { @@ -46,8 +46,8 @@ public void PickDelay_IsWithinBounds() var delay = sut.PickDelay(); // Assert - delay.TotalMilliseconds.Should().BeGreaterOrEqualTo(min); - delay.TotalMilliseconds.Should().BeLessOrEqualTo(max); + delay.TotalMilliseconds.ShouldBeGreaterThanOrEqualTo(min); + delay.TotalMilliseconds.ShouldBeLessThanOrEqualTo(max); } } } \ No newline at end of file diff --git a/Source/EventFlow.Tests/UnitTests/Core/RetryStrategies/OptimisticConcurrencyRetryStrategyTests.cs b/Source/EventFlow.Tests/UnitTests/Core/RetryStrategies/OptimisticConcurrencyRetryStrategyTests.cs index f9694d334..895957c03 100644 --- a/Source/EventFlow.Tests/UnitTests/Core/RetryStrategies/OptimisticConcurrencyRetryStrategyTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Core/RetryStrategies/OptimisticConcurrencyRetryStrategyTests.cs @@ -25,9 +25,9 @@ using EventFlow.Core.RetryStrategies; using EventFlow.Exceptions; using EventFlow.TestHelpers; -using FluentAssertions; using Moq; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Core.RetryStrategies { @@ -63,7 +63,7 @@ public void ShouldThisBeRetried_OptimisticConcurrencyException_ShouldBeRetired(i var shouldThisBeRetried = Sut.ShouldThisBeRetried(optimisticConcurrencyException, A(), currentRetryCount); // Assert - shouldThisBeRetried.ShouldBeRetried.Should().Be(expectedShouldThisBeRetried); + shouldThisBeRetried.ShouldBeRetried.ShouldBe(expectedShouldThisBeRetried); } [TestCase(0)] @@ -80,7 +80,7 @@ public void ShouldThisBeRetried_Exception_ShouldNeverBeRetired(int currentRetryC var shouldThisBeRetried = Sut.ShouldThisBeRetried(exception, A(), currentRetryCount); // Assert - shouldThisBeRetried.ShouldBeRetried.Should().BeFalse(); + shouldThisBeRetried.ShouldBeRetried.ShouldBeFalse(); } } diff --git a/Source/EventFlow.Tests/UnitTests/Core/TransientFaultHandlerTests.cs b/Source/EventFlow.Tests/UnitTests/Core/TransientFaultHandlerTests.cs index 8fd22e814..0ba677595 100644 --- a/Source/EventFlow.Tests/UnitTests/Core/TransientFaultHandlerTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Core/TransientFaultHandlerTests.cs @@ -25,10 +25,10 @@ using System.Threading.Tasks; using EventFlow.Core; using EventFlow.TestHelpers; -using FluentAssertions; using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Core { @@ -73,14 +73,14 @@ public async Task Result() var result = await Sut.TryAsync(c => action.Object(), A diff --git a/Source/EventFlow.Tests/EventFlow.Tests.csproj b/Source/EventFlow.Tests/EventFlow.Tests.csproj index 89e630555..29f1502c4 100644 --- a/Source/EventFlow.Tests/EventFlow.Tests.csproj +++ b/Source/EventFlow.Tests/EventFlow.Tests.csproj @@ -10,7 +10,6 @@ - diff --git a/Source/EventFlow.Tests/IntegrationTests/BackwardCompatibilityTests.cs b/Source/EventFlow.Tests/IntegrationTests/BackwardCompatibilityTests.cs index 5c6f60dc1..5f0dcda65 100644 --- a/Source/EventFlow.Tests/IntegrationTests/BackwardCompatibilityTests.cs +++ b/Source/EventFlow.Tests/IntegrationTests/BackwardCompatibilityTests.cs @@ -33,9 +33,9 @@ using EventFlow.TestHelpers.Aggregates.Commands; using EventFlow.TestHelpers.Aggregates.Queries; using EventFlow.TestHelpers.Aggregates.ValueObjects; -using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.IntegrationTests { @@ -71,9 +71,9 @@ public async Task ValidateTestAggregate() var testAggregate = await _aggregateStore.LoadAsync(_thingyId, CancellationToken.None); // Assert - testAggregate.Version.Should().Be(2); - testAggregate.PingsReceived.Should().Contain(PingId.With("95433aa0-11f7-4128-bd5f-18e0ecc4d7c1")); - testAggregate.PingsReceived.Should().Contain(PingId.With("2352d09b-4712-48cc-bb4f-5560d7c52558")); + testAggregate.Version.ShouldBe(2); + testAggregate.PingsReceived.ShouldContain(PingId.With("95433aa0-11f7-4128-bd5f-18e0ecc4d7c1")); + testAggregate.PingsReceived.ShouldContain(PingId.With("2352d09b-4712-48cc-bb4f-5560d7c52558")); } [Test, Explicit] diff --git a/Source/EventFlow.Tests/IntegrationTests/BasicTests.cs b/Source/EventFlow.Tests/IntegrationTests/BasicTests.cs index 2a9bfe38c..28bdb467a 100644 --- a/Source/EventFlow.Tests/IntegrationTests/BasicTests.cs +++ b/Source/EventFlow.Tests/IntegrationTests/BasicTests.cs @@ -38,9 +38,9 @@ using EventFlow.TestHelpers.Aggregates.Queries; using EventFlow.TestHelpers.Aggregates.ValueObjects; using EventFlow.Tests.IntegrationTests.ReadStores.ReadModels; -using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.IntegrationTests { @@ -126,10 +126,10 @@ public async Task BasicFlow(IEventFlowOptions eventFlowOptions) .ConfigureAwait(false); // Assert - pingReadModels.Should().HaveCount(2); - testAggregate.DomainErrorAfterFirstReceived.Should().BeTrue(); - testReadModelFromQuery1.DomainErrorAfterFirstReceived.Should().BeTrue(); - testReadModelFromQuery2.Should().NotBeNull(); + pingReadModels.Count.ShouldBe(2); + testAggregate.DomainErrorAfterFirstReceived.ShouldBeTrue(); + testReadModelFromQuery1.DomainErrorAfterFirstReceived.ShouldBeTrue(); + testReadModelFromQuery2.ShouldNotBeNull(); } } diff --git a/Source/EventFlow.Tests/IntegrationTests/CancellationTests.cs b/Source/EventFlow.Tests/IntegrationTests/CancellationTests.cs index c1ad2930a..1d166af68 100644 --- a/Source/EventFlow.Tests/IntegrationTests/CancellationTests.cs +++ b/Source/EventFlow.Tests/IntegrationTests/CancellationTests.cs @@ -44,9 +44,9 @@ using EventFlow.TestHelpers.Aggregates.ValueObjects; using EventFlow.TestHelpers.Extensions; using EventFlow.Tests.IntegrationTests.ReadStores.ReadModels; -using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.IntegrationTests { @@ -137,29 +137,29 @@ private List CreateSteps(ThingyId id) CancellationBoundary.BeforeCommittingEvents, _commandHandler.ExecuteCompletionSource, () => Task.FromResult(_commandHandler.HasBeenCalled), - v => v.Should().BeTrue(), - v => v.Should().BeFalse()), + v => v.ShouldBeTrue(), + v => v.ShouldBeFalse()), new Step>( CancellationBoundary.BeforeUpdatingReadStores, _eventPersistence.CommitCompletionSource, () => _eventPersistence.LoadCommittedEventsAsync(id, 0, CancellationToken.None), - v => v.Should().NotBeEmpty(), - v => v.Should().BeEmpty()), + v => v.ShouldNotBeEmpty(), + v => v.ShouldBeEmpty()), new Step>( CancellationBoundary.BeforeNotifyingSubscribers, _readStore.UpdateCompletionSource, () => _readStore.GetAsync(id.ToString(), CancellationToken.None), - v => v.ReadModel.Should().NotBeNull(), - v => v.ReadModel.Should().BeNull()), + v => v.ReadModel.ShouldNotBeNull(), + v => v.ReadModel.ShouldBeNull()), new Step( CancellationBoundary.CancelAlways, _subscriber.HandleCompletionSource, () => Task.FromResult(_subscriber.HasHandled), - v => v.Should().BeTrue(), - v => v.Should().BeFalse()) + v => v.ShouldBeTrue(), + v => v.ShouldBeFalse()) }; return steps; diff --git a/Source/EventFlow.Tests/IntegrationTests/CommandResultTests.cs b/Source/EventFlow.Tests/IntegrationTests/CommandResultTests.cs index 605f2caed..79a06cdf0 100644 --- a/Source/EventFlow.Tests/IntegrationTests/CommandResultTests.cs +++ b/Source/EventFlow.Tests/IntegrationTests/CommandResultTests.cs @@ -24,15 +24,14 @@ using System.Threading.Tasks; using EventFlow.Aggregates.ExecutionResults; using EventFlow.Commands; -using EventFlow.Configuration; using EventFlow.Extensions; using EventFlow.TestHelpers; using EventFlow.TestHelpers.Aggregates; using EventFlow.TestHelpers.Aggregates.Queries; using EventFlow.Tests.UnitTests.Specifications; -using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.IntegrationTests { @@ -107,14 +106,14 @@ public async Task CommandResult() new TestSuccessResultCommand(ThingyId.New), CancellationToken.None) .ConfigureAwait(false); - success.IsSuccess.Should().BeTrue(); - success.MagicNumber.Should().Be(42); + success.IsSuccess.ShouldBeTrue(); + success.MagicNumber.ShouldBe(42); var failed = await commandBus.PublishAsync( new TestFailedResultCommand(ThingyId.New), CancellationToken.None) .ConfigureAwait(false); - failed.IsSuccess.Should().BeFalse(); + failed.IsSuccess.ShouldBeFalse(); } } } diff --git a/Source/EventFlow.Tests/IntegrationTests/ReadStores/MultipleAggregateReadStoreManagerTests.cs b/Source/EventFlow.Tests/IntegrationTests/ReadStores/MultipleAggregateReadStoreManagerTests.cs index 484211f58..536f553ad 100644 --- a/Source/EventFlow.Tests/IntegrationTests/ReadStores/MultipleAggregateReadStoreManagerTests.cs +++ b/Source/EventFlow.Tests/IntegrationTests/ReadStores/MultipleAggregateReadStoreManagerTests.cs @@ -31,9 +31,9 @@ using EventFlow.Queries; using EventFlow.ReadStores; using EventFlow.TestHelpers; -using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; +using Shouldly; // ReSharper disable ClassNeverInstantiated.Local @@ -71,9 +71,7 @@ public async Task EventOrdering() new ReadModelByIdQuery(ReadModelId), CancellationToken.None); - readModelAb.Indexes.Should().BeEquivalentTo( - new []{0, 1, 2, 3}, - o => o.WithStrictOrdering()); + readModelAb.Indexes.ShouldBe(new []{0, 1, 2, 3}, ignoreOrder: false); } protected override IServiceProvider Configure(IEventFlowOptions eventFlowOptions) diff --git a/Source/EventFlow.Tests/IntegrationTests/Sagas/AggregateSagaTests.cs b/Source/EventFlow.Tests/IntegrationTests/Sagas/AggregateSagaTests.cs index ced49a553..f36704984 100644 --- a/Source/EventFlow.Tests/IntegrationTests/Sagas/AggregateSagaTests.cs +++ b/Source/EventFlow.Tests/IntegrationTests/Sagas/AggregateSagaTests.cs @@ -25,7 +25,6 @@ using System.Threading; using System.Threading.Tasks; using EventFlow.Aggregates; -using EventFlow.Configuration; using EventFlow.Extensions; using EventFlow.Sagas; using EventFlow.Subscribers; @@ -35,10 +34,10 @@ using EventFlow.TestHelpers.Aggregates.Sagas; using EventFlow.TestHelpers.Aggregates.Sagas.Events; using EventFlow.TestHelpers.Aggregates.ValueObjects; -using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using Moq; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.IntegrationTests.Sagas { @@ -54,7 +53,7 @@ public async Task InitialSagaStateIsNew() var thingySaga = await LoadSagaAsync(A()); // Assert - thingySaga.State.Should().Be(SagaState.New); + thingySaga.State.ShouldBe(SagaState.New); } [Test] @@ -68,7 +67,7 @@ public async Task PublishingEventWithoutStartingSagaLeavesItNew() // Assert var thingySaga = await LoadSagaAsync(thingyId); - thingySaga.State.Should().Be(SagaState.New); + thingySaga.State.ShouldBe(SagaState.New); } [Test] @@ -82,7 +81,7 @@ public async Task PublishingEventWithoutStartingDoesntPublishToMainAggregate() // Assert var thingyAggregate = await LoadAggregateAsync(thingyId); - thingyAggregate.Messages.Should().BeEmpty(); + thingyAggregate.Messages.ShouldBeEmpty(); } [Test] @@ -96,7 +95,7 @@ public async Task PublishingCompleteEventWithoutStartingSagaLeavesItNew() // Assert var thingySaga = await LoadSagaAsync(thingyId); - thingySaga.State.Should().Be(SagaState.New); + thingySaga.State.ShouldBe(SagaState.New); } [Test] @@ -110,7 +109,7 @@ public async Task PublishingStartTiggerEventStartsSaga() // Assert var thingySaga = await LoadSagaAsync(thingyId); - thingySaga.State.Should().Be(SagaState.Running); + thingySaga.State.ShouldBe(SagaState.Running); } [Test] @@ -125,7 +124,7 @@ public async Task PublishingStartAndCompleteTiggerEventsCompletesSaga() // Assert var thingySaga = await LoadSagaAsync(thingyId); - thingySaga.State.Should().Be(SagaState.Completed); + thingySaga.State.ShouldBe(SagaState.Completed); } [Test] @@ -158,18 +157,19 @@ public async Task PublishingStartAndCompleteWithPingsResultInCorrectMessages() // Assert - saga var thingySaga = await LoadSagaAsync(thingyId); - thingySaga.State.Should().Be(SagaState.Completed); - thingySaga.PingIdsSinceStarted.Should().BeEquivalentTo(pingsWithRunningSaga); + thingySaga.State.ShouldBe(SagaState.Completed); + thingySaga.PingIdsSinceStarted.ShouldBe(pingsWithRunningSaga, ignoreOrder: true); // Assert - aggregate var thingyAggregate = await LoadAggregateAsync(thingyId); - thingyAggregate.PingsReceived.Should().BeEquivalentTo( - pingsWithNewSaga.Concat(pingsWithRunningSaga).Concat(pingsWithCompletedSaga)); + thingyAggregate.PingsReceived.ShouldBe( + pingsWithNewSaga.Concat(pingsWithRunningSaga).Concat(pingsWithCompletedSaga), + ignoreOrder: true); var receivedSagaPingIds = thingyAggregate.Messages .Select(m => PingId.With(m.Message)) .ToList(); - receivedSagaPingIds.Should().HaveCount(3); - receivedSagaPingIds.Should().BeEquivalentTo(pingsWithRunningSaga); + receivedSagaPingIds.Count.ShouldBe(3); + receivedSagaPingIds.ShouldBe(pingsWithRunningSaga, ignoreOrder: true); } protected override IServiceProvider Configure(IEventFlowOptions eventFlowOptions) diff --git a/Source/EventFlow.Tests/IntegrationTests/Sagas/AlternativeSagaStoreTestClasses.cs b/Source/EventFlow.Tests/IntegrationTests/Sagas/AlternativeSagaStoreTestClasses.cs index f3cb9be51..e3947748c 100644 --- a/Source/EventFlow.Tests/IntegrationTests/Sagas/AlternativeSagaStoreTestClasses.cs +++ b/Source/EventFlow.Tests/IntegrationTests/Sagas/AlternativeSagaStoreTestClasses.cs @@ -28,12 +28,11 @@ using EventFlow.Aggregates; using EventFlow.Aggregates.ExecutionResults; using EventFlow.Commands; -using EventFlow.Configuration; using EventFlow.Core; using EventFlow.Sagas; using EventFlow.ValueObjects; -using FluentAssertions; using Microsoft.Extensions.DependencyInjection; +using Shouldly; namespace EventFlow.Tests.IntegrationTests.Sagas { @@ -61,7 +60,7 @@ public InMemorySagaStore( public void UpdateShouldNotHaveBeenCalled() { - this._hasUpdateBeenCalled.Should().BeFalse(); + this._hasUpdateBeenCalled.ShouldBeFalse(); } public override async Task UpdateAsync( diff --git a/Source/EventFlow.Tests/IntegrationTests/Sagas/AlternativeSagaStoreTests.cs b/Source/EventFlow.Tests/IntegrationTests/Sagas/AlternativeSagaStoreTests.cs index ea6dd833f..f040a2bc2 100644 --- a/Source/EventFlow.Tests/IntegrationTests/Sagas/AlternativeSagaStoreTests.cs +++ b/Source/EventFlow.Tests/IntegrationTests/Sagas/AlternativeSagaStoreTests.cs @@ -27,9 +27,9 @@ using EventFlow.Extensions; using EventFlow.Sagas; using EventFlow.TestHelpers; -using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.IntegrationTests.Sagas { @@ -87,9 +87,9 @@ await _commandBus.PublishAsync( var testAggregate = await _aggregateStore.LoadAsync( aggregateId, CancellationToken.None); - testAggregate.As.Should().Be(1); - testAggregate.Bs.Should().Be(1); - testAggregate.Cs.Should().Be(1); + testAggregate.As.ShouldBe(1); + testAggregate.Bs.ShouldBe(1); + testAggregate.Cs.ShouldBe(1); } [Test] @@ -107,9 +107,9 @@ await _commandBus.PublishAsync( var testAggregate = await _aggregateStore.LoadAsync( aggregateId, CancellationToken.None); - testAggregate.As.Should().Be(0); - testAggregate.Bs.Should().Be(1); - testAggregate.Cs.Should().Be(0); + testAggregate.As.ShouldBe(0); + testAggregate.Bs.ShouldBe(1); + testAggregate.Cs.ShouldBe(0); } [Test] diff --git a/Source/EventFlow.Tests/IntegrationTests/Sagas/SagaErrorHandlerTests.cs b/Source/EventFlow.Tests/IntegrationTests/Sagas/SagaErrorHandlerTests.cs index dcbf666b9..efcd5281c 100644 --- a/Source/EventFlow.Tests/IntegrationTests/Sagas/SagaErrorHandlerTests.cs +++ b/Source/EventFlow.Tests/IntegrationTests/Sagas/SagaErrorHandlerTests.cs @@ -20,19 +20,18 @@ // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -using EventFlow.Configuration; using EventFlow.Sagas; using EventFlow.TestHelpers; using EventFlow.TestHelpers.Aggregates; using EventFlow.TestHelpers.Aggregates.Commands; using EventFlow.TestHelpers.Aggregates.Sagas; -using FluentAssertions; using Moq; using NUnit.Framework; using System; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; +using Shouldly; namespace EventFlow.Tests.IntegrationTests.Sagas { @@ -57,8 +56,8 @@ await CommandBus.PublishAsync(new ThingyThrowExceptionInSagaCommand(thingyId), C }; // Assert - commandPublishAction.Should().Throw() - .WithMessage("Exception thrown (as requested by ThingySagaExceptionRequestedEvent)"); + var exception = await Should.ThrowAsync(commandPublishAction); + exception.Message.ShouldContain("Exception thrown (as requested by ThingySagaExceptionRequestedEvent)"); } [Test] @@ -83,7 +82,7 @@ await CommandBus.PublishAsync(new ThingyThrowExceptionInSagaCommand(thingyId), C }; // Assert - commandPublishAction.Should().NotThrow(); + await Should.NotThrowAsync(commandPublishAction); } protected override IServiceProvider Configure(IEventFlowOptions eventFlowOptions) diff --git a/Source/EventFlow.Tests/IntegrationTests/SeparationTests.cs b/Source/EventFlow.Tests/IntegrationTests/SeparationTests.cs index e2b379dc4..6d138cb16 100644 --- a/Source/EventFlow.Tests/IntegrationTests/SeparationTests.cs +++ b/Source/EventFlow.Tests/IntegrationTests/SeparationTests.cs @@ -31,9 +31,9 @@ using EventFlow.TestHelpers.Aggregates.Queries; using EventFlow.TestHelpers.Aggregates.ValueObjects; using EventFlow.TestHelpers.Extensions; -using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.IntegrationTests { @@ -60,7 +60,7 @@ await resolver1.GetRequiredService().PublishAsync( thingyId, CancellationToken.None) .ConfigureAwait(false); - aggregate.IsNew.Should().BeTrue(); + aggregate.IsNew.ShouldBeTrue(); } } diff --git a/Source/EventFlow.Tests/IntegrationTests/ServiceProviderTests.cs b/Source/EventFlow.Tests/IntegrationTests/ServiceProviderTests.cs index f024fc34c..673b0456e 100644 --- a/Source/EventFlow.Tests/IntegrationTests/ServiceProviderTests.cs +++ b/Source/EventFlow.Tests/IntegrationTests/ServiceProviderTests.cs @@ -29,9 +29,9 @@ using EventFlow.TestHelpers.Aggregates; using EventFlow.TestHelpers.Aggregates.Commands; using EventFlow.TestHelpers.Aggregates.Queries; -using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.IntegrationTests { @@ -64,10 +64,8 @@ public async Task ResolverAggregatesFactoryCanResolve() var serviceDependentAggregate = await aggregateFactory.CreateNewAggregateAsync(ThingyId.New).ConfigureAwait(false); // Assert - serviceDependentAggregate.Service.Should() - .NotBeNull() - .And - .BeOfType(); + serviceDependentAggregate.Service.ShouldNotBeNull(); + serviceDependentAggregate.Service.ShouldBeOfType(); } } diff --git a/Source/EventFlow.Tests/IntegrationTests/UnicodeTests.cs b/Source/EventFlow.Tests/IntegrationTests/UnicodeTests.cs index cdb727310..0e8a420c6 100644 --- a/Source/EventFlow.Tests/IntegrationTests/UnicodeTests.cs +++ b/Source/EventFlow.Tests/IntegrationTests/UnicodeTests.cs @@ -31,10 +31,10 @@ using EventFlow.EventStores; using EventFlow.Extensions; using EventFlow.TestHelpers; -using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NUnit.Framework; +using Shouldly; // ReSharper disable IdentifierTypo // ReSharper disable StringLiteralTypo @@ -51,7 +51,7 @@ public void UpperCaseIdentityThrows() Action action = () => new Identität1("Identität1-00000000-0000-0000-0000-000000000000"); // Assert - action.Should().Throw(); + action.ShouldThrow(); } [Test] @@ -61,7 +61,7 @@ public void LowerCaseIdentityWorks() var id = new Identität1("identität1-00000000-0000-0000-0000-000000000000"); // Assert - id.GetGuid().Should().BeEmpty(); + id.GetGuid().ShouldBe(Guid.Empty); } [Test] @@ -71,7 +71,7 @@ public void UnicodeIdentities() var identität = Identität1.New.Value; // Assert - identität.Should().StartWith("identität1-"); + identität.ShouldStartWith("identität1-"); } [Test] @@ -86,7 +86,7 @@ public void UnicodeCommands() Action action = () => commandDefinitions.Load(typeof(Cömmand)); // Assert - action.Should().NotThrow(); + action.ShouldNotThrow(); } [Test] @@ -102,7 +102,7 @@ public void UnicodeEvents() Action action = () => eventDefinitionService.Load(typeof(Püng1Event)); // Assert - action.Should().NotThrow(); + action.ShouldNotThrow(); } [Test] diff --git a/Source/EventFlow.Tests/ReadMeExamples.cs b/Source/EventFlow.Tests/ReadMeExamples.cs index 3e9101593..4159a145a 100644 --- a/Source/EventFlow.Tests/ReadMeExamples.cs +++ b/Source/EventFlow.Tests/ReadMeExamples.cs @@ -29,9 +29,9 @@ using EventFlow.Extensions; using EventFlow.Queries; using EventFlow.ReadStores; -using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests { @@ -69,7 +69,7 @@ await commandBus.PublishAsync( new ReadModelByIdQuery(exampleId), CancellationToken.None); // Verify that the read model has the expected magic number - exampleReadModel.MagicNumber.Should().Be(42); + exampleReadModel.MagicNumber.ShouldBe(42); } } diff --git a/Source/EventFlow.Tests/UnitTests/ValueObjects/SingleValueObjectTests.cs b/Source/EventFlow.Tests/UnitTests/ValueObjects/SingleValueObjectTests.cs index 12d1bf954..7376fc0cc 100644 --- a/Source/EventFlow.Tests/UnitTests/ValueObjects/SingleValueObjectTests.cs +++ b/Source/EventFlow.Tests/UnitTests/ValueObjects/SingleValueObjectTests.cs @@ -24,9 +24,9 @@ using System.Linq; using EventFlow.TestHelpers; using EventFlow.ValueObjects; -using FluentAssertions; using Newtonsoft.Json; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.ValueObjects { @@ -57,16 +57,14 @@ public void Ordering() // Arrange var values = Many(10); var orderedValues = values.OrderBy(s => s).ToList(); - values.Should().NotEqual(orderedValues); // Data test + values.ShouldNotBe(orderedValues); // Data test var singleValueObjects = values.Select(s => new StringSingleValue(s)).ToList(); // Act var orderedSingleValueObjects = singleValueObjects.OrderBy(v => v).ToList(); // Assert - orderedSingleValueObjects.Select(v => v.Value).Should().BeEquivalentTo( - orderedValues, - o => o.WithStrictOrdering()); + orderedSingleValueObjects.Select(v => v.Value).ShouldBe(orderedValues, ignoreOrder: false); } [Test] @@ -75,16 +73,14 @@ public void EnumOrdering() // Arrange var values = Many(10); var orderedValues = values.OrderBy(s => s).ToList(); - values.Should().NotEqual(orderedValues); // Data test + values.ShouldNotBe(orderedValues); // Data test var singleValueObjects = values.Select(s => new MagicEnumSingleValue(s)).ToList(); // Act var orderedSingleValueObjects = singleValueObjects.OrderBy(v => v).ToList(); // Assert - orderedSingleValueObjects.Select(v => v.Value).Should().BeEquivalentTo( - orderedValues, - o => o.WithStrictOrdering()); + orderedSingleValueObjects.Select(v => v.Value).ShouldBe(orderedValues, ignoreOrder: false); } [Test] @@ -93,7 +89,7 @@ public void ProtectAgainsInvalidEnumValues() // Act + Assert // ReSharper disable once ObjectCreationAsStatement var exception = Assert.Throws(() => new MagicEnumSingleValue((MagicEnum)42)); - exception.Message.Should().Be("The value '42' isn't defined in enum 'MagicEnum'"); + exception.Message.ShouldBe("The value '42' isn't defined in enum 'MagicEnum'"); } [Test] @@ -115,15 +111,13 @@ public void EnumOrderingManual() .ToList(); // Assert - orderedValues.Should().BeEquivalentTo( - new [] + orderedValues.ShouldBe(new [] { MagicEnum.Zero, MagicEnum.One, MagicEnum.Two, MagicEnum.Three, - }, - o => o.WithStrictOrdering()); + }, ignoreOrder: false); } [Test] @@ -135,7 +129,7 @@ public void NullEquals() // Assert // ReSharper disable once ExpressionIsAlwaysNull - obj.Equals(null_).Should().BeFalse(); + obj.Equals(null_).ShouldBeFalse(); } [Test] @@ -147,8 +141,8 @@ public void EqualsForSameValues() var obj2 = new StringSingleValue(value); // Assert - (obj1 == obj2).Should().BeTrue(); - obj1.Equals(obj2).Should().BeTrue(); + (obj1 == obj2).ShouldBeTrue(); + obj1.Equals(obj2).ShouldBeTrue(); } [Test] @@ -161,8 +155,8 @@ public void EqualsForDifferentValues() var obj2 = new StringSingleValue(value2); // Assert - (obj1 == obj2).Should().BeFalse(); - obj1.Equals(obj2).Should().BeFalse(); + (obj1 == obj2).ShouldBeFalse(); + obj1.Equals(obj2).ShouldBeFalse(); } private static readonly JsonSerializerSettings Settings = new JsonSerializerSettings @@ -198,8 +192,8 @@ public void DeserializeNullableIntWithoutValue() var with = JsonConvert.DeserializeObject(json); // Assert - with.Should().NotBeNull(); - with.I.Should().BeNull(); + with.ShouldNotBeNull(); + with.I.ShouldBeNull(); } [Test] @@ -212,8 +206,8 @@ public void DeserializeNullableIntWithNullValue() var with = JsonConvert.DeserializeObject(json); // Assert - with.Should().NotBeNull(); - with.I.Should().BeNull(); + with.ShouldNotBeNull(); + with.I.ShouldBeNull(); } [Test] @@ -227,8 +221,8 @@ public void DeserializeNullableIntWithValue() var with = JsonConvert.DeserializeObject(json); // Assert - with.Should().NotBeNull(); - with.I.Value.Should().Be(i); + with.ShouldNotBeNull(); + with.I.Value.ShouldBe(i); } [Test] @@ -241,7 +235,7 @@ public void SerializeNullableIntWithoutValue() var json = JsonConvert.SerializeObject(with, Settings); // Assert - json.Should().Be("{}"); + json.ShouldBe("{}"); } [Test] @@ -254,7 +248,7 @@ public void SerializeNullableIntWithValue() var json = JsonConvert.SerializeObject(with, Settings); // Assert - json.Should().Be("{\"I\":42}"); + json.ShouldBe("{\"I\":42}"); } } } From f978c3e0393e10cdda4d4a5c7748d672f1ee9eb4 Mon Sep 17 00:00:00 2001 From: Focus Date: Sat, 14 Jun 2025 13:44:36 +0300 Subject: [PATCH 07/13] tests --- .../UnitTests/Commands/CommandTests.cs | 8 ++++---- .../Commands/DistinctCommandTests.cs | 4 ++-- .../NamespaceAndClassNameStrategyTest.cs | 4 ++-- .../NamespaceAndNameStrategyTest.cs | 5 ++--- .../EventNamingStrategy/VoidStrategyTest.cs | 4 ++-- .../Serialization/JsonOptionsTests.cs | 12 +++++------ .../UnitTests/Core/CircularBufferTests.cs | 10 +++++----- .../ReadModelDomainEventApplierTests.cs | 20 +++++++++---------- .../ReadStores/ReadModelFactoryTests.cs | 10 +++++----- .../SingleAggregateReadStoreManagerTests.cs | 20 ++++++++++--------- 10 files changed, 49 insertions(+), 48 deletions(-) diff --git a/Source/EventFlow.Tests/UnitTests/Commands/CommandTests.cs b/Source/EventFlow.Tests/UnitTests/Commands/CommandTests.cs index 3d23150a8..e93498877 100644 --- a/Source/EventFlow.Tests/UnitTests/Commands/CommandTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Commands/CommandTests.cs @@ -25,9 +25,9 @@ using EventFlow.Commands; using EventFlow.TestHelpers; using EventFlow.TestHelpers.Aggregates; -using FluentAssertions; using Newtonsoft.Json; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Commands { @@ -55,9 +55,9 @@ public void SerializeDeserialize() var deserialized = JsonConvert.DeserializeObject(json); // Assert - deserialized.CriticalData.Should().Be(criticalCommand.CriticalData); - deserialized.SourceId.Should().Be(criticalCommand.SourceId); - deserialized.AggregateId.Should().Be(criticalCommand.AggregateId); + deserialized.CriticalData.ShouldBe(criticalCommand.CriticalData); + deserialized.SourceId.ShouldBe(criticalCommand.SourceId); + deserialized.AggregateId.ShouldBe(criticalCommand.AggregateId); } } } diff --git a/Source/EventFlow.Tests/UnitTests/Commands/DistinctCommandTests.cs b/Source/EventFlow.Tests/UnitTests/Commands/DistinctCommandTests.cs index 052b73513..879f90584 100644 --- a/Source/EventFlow.Tests/UnitTests/Commands/DistinctCommandTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Commands/DistinctCommandTests.cs @@ -27,8 +27,8 @@ using EventFlow.Extensions; using EventFlow.TestHelpers; using EventFlow.TestHelpers.Aggregates; -using FluentAssertions; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Commands { @@ -66,7 +66,7 @@ public void Arguments(string aggregateId, int magicNumber, string expectedSouceI var sourceId = command.SourceId; // Assert - sourceId.Value.Should().Be(expectedSouceId); + sourceId.Value.ShouldBe(expectedSouceId); } } } diff --git a/Source/EventFlow.Tests/UnitTests/Configuration/EventNamingStrategy/NamespaceAndClassNameStrategyTest.cs b/Source/EventFlow.Tests/UnitTests/Configuration/EventNamingStrategy/NamespaceAndClassNameStrategyTest.cs index 52119fb32..49ba644b7 100644 --- a/Source/EventFlow.Tests/UnitTests/Configuration/EventNamingStrategy/NamespaceAndClassNameStrategyTest.cs +++ b/Source/EventFlow.Tests/UnitTests/Configuration/EventNamingStrategy/NamespaceAndClassNameStrategyTest.cs @@ -22,8 +22,8 @@ using EventFlow.Configuration.EventNamingStrategy; using EventFlow.TestHelpers; -using FluentAssertions; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Configuration.EventNamingStrategy { @@ -42,7 +42,7 @@ public void EventNameShouldBeNamespaceAndClassName() var name = strategy.CreateEventName(1, typeof(Any), "OriginalName"); // Assert - name.Should().Be(GetType().Namespace + ".Any"); + name.ShouldBe(GetType().Namespace + ".Any"); } } } \ No newline at end of file diff --git a/Source/EventFlow.Tests/UnitTests/Configuration/EventNamingStrategy/NamespaceAndNameStrategyTest.cs b/Source/EventFlow.Tests/UnitTests/Configuration/EventNamingStrategy/NamespaceAndNameStrategyTest.cs index b144cb51c..8bcb5b3ab 100644 --- a/Source/EventFlow.Tests/UnitTests/Configuration/EventNamingStrategy/NamespaceAndNameStrategyTest.cs +++ b/Source/EventFlow.Tests/UnitTests/Configuration/EventNamingStrategy/NamespaceAndNameStrategyTest.cs @@ -21,9 +21,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. using EventFlow.Configuration.EventNamingStrategy; -using EventFlow.EventStores; -using FluentAssertions; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Configuration.EventNamingStrategy { @@ -41,7 +40,7 @@ public void EventNameShouldBeNamespaceAndClassName() var name = strategy.CreateEventName(1, typeof(Any), "NameFromAttribute"); // Assert - name.Should().Be(GetType().Namespace + ".NameFromAttribute"); + name.ShouldBe(GetType().Namespace + ".NameFromAttribute"); } } } \ No newline at end of file diff --git a/Source/EventFlow.Tests/UnitTests/Configuration/EventNamingStrategy/VoidStrategyTest.cs b/Source/EventFlow.Tests/UnitTests/Configuration/EventNamingStrategy/VoidStrategyTest.cs index 3fee98f5a..2a74e678e 100644 --- a/Source/EventFlow.Tests/UnitTests/Configuration/EventNamingStrategy/VoidStrategyTest.cs +++ b/Source/EventFlow.Tests/UnitTests/Configuration/EventNamingStrategy/VoidStrategyTest.cs @@ -22,8 +22,8 @@ using EventFlow.Configuration.EventNamingStrategy; using EventFlow.TestHelpers; -using FluentAssertions; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Configuration.EventNamingStrategy { @@ -42,7 +42,7 @@ public void EventNameShouldBeUnchanged() var name = strategy.CreateEventName(1, typeof(Any), "OriginalName"); // Assert - name.Should().Be("OriginalName"); + name.ShouldBe("OriginalName"); } } } \ No newline at end of file diff --git a/Source/EventFlow.Tests/UnitTests/Configuration/Serialization/JsonOptionsTests.cs b/Source/EventFlow.Tests/UnitTests/Configuration/Serialization/JsonOptionsTests.cs index acf6948fa..38d447024 100644 --- a/Source/EventFlow.Tests/UnitTests/Configuration/Serialization/JsonOptionsTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Configuration/Serialization/JsonOptionsTests.cs @@ -24,10 +24,10 @@ using EventFlow.Extensions; using EventFlow.TestHelpers; using EventFlow.ValueObjects; -using FluentAssertions; using Newtonsoft.Json; using NUnit.Framework; using System; +using Shouldly; namespace EventFlow.Tests.UnitTests.Configuration.Serialization { @@ -77,11 +77,11 @@ public void JsonOptionsCanBeUsedToConstructJsonSerializerSettings() var svoDeserialized = JsonConvert.DeserializeObject(svoSerialized); // Assert - myClassSerialized.Should().Be("1000000"); - myClassDeserialized.DateTime.Ticks.Should().Be(1000000); - myClassDeserialized.DateTime.Ticks.Should().NotBe(10); - svoDeserialized.Should().Be(new MySingleValueObject(new DateTime(1970, 1, 1))); - svoDeserialized.Should().NotBe(new MySingleValueObject(new DateTime(2001, 1, 1))); + myClassSerialized.ShouldBe("1000000"); + myClassDeserialized.DateTime.Ticks.ShouldBe(1000000); + myClassDeserialized.DateTime.Ticks.ShouldNotBe(10); + svoDeserialized.ShouldBe(new MySingleValueObject(new DateTime(1970, 1, 1))); + svoDeserialized.ShouldNotBe(new MySingleValueObject(new DateTime(2001, 1, 1))); } } } diff --git a/Source/EventFlow.Tests/UnitTests/Core/CircularBufferTests.cs b/Source/EventFlow.Tests/UnitTests/Core/CircularBufferTests.cs index 3c318c2b6..8d52f5a5a 100644 --- a/Source/EventFlow.Tests/UnitTests/Core/CircularBufferTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Core/CircularBufferTests.cs @@ -23,8 +23,8 @@ using System.Linq; using EventFlow.Core; using EventFlow.TestHelpers; -using FluentAssertions; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Core { @@ -50,7 +50,7 @@ public void Put(params int[] numbers) // Assert var shouldContain = numbers.Reverse().Take(capacity).ToList(); - sut.Should().Contain(shouldContain); + sut.ShouldBe(shouldContain); } [Test] @@ -67,7 +67,7 @@ public void OrderAboveCapacity() var numbers = sut.ToArray(); // Assert - numbers.Should().ContainInOrder(2, 3, 4); + numbers.ShouldBe(new[] {2, 3, 4}, ignoreOrder: false); } [Test] @@ -83,7 +83,7 @@ public void OrderAtCapacity() var numbers = sut.ToArray(); // Assert - numbers.Should().ContainInOrder(1, 2, 3); + numbers.ShouldBe( new[] {1, 2, 3}, ignoreOrder: false); } [Test] @@ -98,7 +98,7 @@ public void OrderBelowCapacity() var numbers = sut.ToArray(); // Assert - numbers.Should().ContainInOrder(1, 2); + numbers.ShouldBe(new[] {1, 2}, ignoreOrder: false); } } } \ No newline at end of file diff --git a/Source/EventFlow.Tests/UnitTests/ReadStores/ReadModelDomainEventApplierTests.cs b/Source/EventFlow.Tests/UnitTests/ReadStores/ReadModelDomainEventApplierTests.cs index 760026d17..13a777519 100644 --- a/Source/EventFlow.Tests/UnitTests/ReadStores/ReadModelDomainEventApplierTests.cs +++ b/Source/EventFlow.Tests/UnitTests/ReadStores/ReadModelDomainEventApplierTests.cs @@ -27,8 +27,8 @@ using EventFlow.TestHelpers; using EventFlow.TestHelpers.Aggregates; using EventFlow.TestHelpers.Aggregates.Events; -using FluentAssertions; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.ReadStores { @@ -109,7 +109,7 @@ public async Task ReadModelDoesNotReceiveOtherEvents() await Sut.UpdateReadModelAsync(readModel, events, A(), CancellationToken.None).ConfigureAwait(false); // Assert - readModel.PingEventsReceived.Should().BeFalse(); + readModel.PingEventsReceived.ShouldBeFalse(); } [Test] @@ -138,8 +138,8 @@ await Sut.UpdateReadModelAsync( .ConfigureAwait(false); // Assert - pingReadModel.PingEventsReceived.Should().BeTrue(); - theOtherPingReadModel.PingEventsReceived.Should().BeTrue(); + pingReadModel.PingEventsReceived.ShouldBeTrue(); + theOtherPingReadModel.PingEventsReceived.ShouldBeTrue(); } [Test] @@ -169,8 +169,8 @@ await Sut.UpdateReadModelAsync( .ConfigureAwait(false); // Assert - pingReadModel.PingEventsReceived.Should().BeTrue(); - domainErrorAfterFirstReadModel.DomainErrorAfterFirstEventsReceived.Should().BeTrue(); + pingReadModel.PingEventsReceived.ShouldBeTrue(); + domainErrorAfterFirstReadModel.DomainErrorAfterFirstEventsReceived.ShouldBeTrue(); } [Test] @@ -190,7 +190,7 @@ public async Task UpdateReturnsFalseIfNoEventsWasApplied() CancellationToken.None); // Assert - appliedAny.Should().BeFalse(); + appliedAny.ShouldBeFalse(); } [Test] @@ -210,7 +210,7 @@ public async Task UpdateReturnsTrueIfEventsWereApplied() CancellationToken.None); // Assert - appliedAny.Should().BeTrue(); + appliedAny.ShouldBeTrue(); } [Test] @@ -232,7 +232,7 @@ await Sut.UpdateReadModelAsync( .ConfigureAwait(false); // Assert - readModel.PingEventsReceived.Should().BeTrue(); + readModel.PingEventsReceived.ShouldBeTrue(); } [Test] @@ -254,7 +254,7 @@ await Sut.UpdateReadModelAsync( .ConfigureAwait(false); // Assert - readModel.PingEventsReceived.Should().BeTrue(); + readModel.PingEventsReceived.ShouldBeTrue(); } } } diff --git a/Source/EventFlow.Tests/UnitTests/ReadStores/ReadModelFactoryTests.cs b/Source/EventFlow.Tests/UnitTests/ReadStores/ReadModelFactoryTests.cs index 8d91cbee6..8614186a8 100644 --- a/Source/EventFlow.Tests/UnitTests/ReadStores/ReadModelFactoryTests.cs +++ b/Source/EventFlow.Tests/UnitTests/ReadStores/ReadModelFactoryTests.cs @@ -25,10 +25,10 @@ using System.Threading.Tasks; using EventFlow.ReadStores; using EventFlow.TestHelpers; -using FluentAssertions; using NUnit.Framework; using EventFlow.Extensions; using Microsoft.Extensions.DependencyInjection; +using Shouldly; // ReSharper disable MemberCanBePrivate.Global // ReSharper disable ClassNeverInstantiated.Global @@ -61,9 +61,9 @@ public async Task ReadModelFactoryCanBeConfigured() var readModelC = await resolver.GetRequiredService>().CreateAsync(A(), CancellationToken.None); // Assert - readModelA.MagicNumber.Should().Be(expectedMagicNumberForReadModelA); - readModelB.MagicNumber.Should().Be(expectedMagicNumberForReadModelB); - readModelC.MagicNumber.Should().Be(expectedMagicNumberForReadModelC); + readModelA.MagicNumber.ShouldBe(expectedMagicNumberForReadModelA); + readModelB.MagicNumber.ShouldBe(expectedMagicNumberForReadModelB); + readModelC.MagicNumber.ShouldBe(expectedMagicNumberForReadModelC); } } @@ -76,7 +76,7 @@ public void ThrowsExceptionForNoEmptyConstructors() // Assert // ReSharper disable once PossibleNullReferenceException - exception.InnerException.Message.Should().Contain("doesn't have an empty constructor"); + exception.InnerException.Message.ShouldContain("doesn't have an empty constructor"); } public class ReadModelWithConstructorArguments : IReadModel diff --git a/Source/EventFlow.Tests/UnitTests/ReadStores/SingleAggregateReadStoreManagerTests.cs b/Source/EventFlow.Tests/UnitTests/ReadStores/SingleAggregateReadStoreManagerTests.cs index 08ba5408b..a6f3926bf 100644 --- a/Source/EventFlow.Tests/UnitTests/ReadStores/SingleAggregateReadStoreManagerTests.cs +++ b/Source/EventFlow.Tests/UnitTests/ReadStores/SingleAggregateReadStoreManagerTests.cs @@ -32,9 +32,9 @@ using EventFlow.TestHelpers.Aggregates; using EventFlow.TestHelpers.Aggregates.Events; using EventFlow.TestHelpers.Extensions; -using FluentAssertions; using Moq; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.ReadStores { @@ -71,8 +71,8 @@ public async Task EventsAreApplied() await Sut.UpdateReadStoresAsync(emittedEvents, CancellationToken.None).ConfigureAwait(false); // Assert - AppliedDomainEvents.Should().HaveCount(emittedEvents.Length); - AppliedDomainEvents.Should().BeEquivalentTo(emittedEvents); + AppliedDomainEvents.Count.ShouldBe(emittedEvents.Length); + AppliedDomainEvents.ShouldBe(emittedEvents); } [Test] @@ -93,8 +93,8 @@ public async Task AlreadyAppliedEventsAreNotApplied() await Sut.UpdateReadStoresAsync(emittedEvents, CancellationToken.None).ConfigureAwait(false); // Assert - AppliedDomainEvents.Should().BeEmpty(); - resultingReadModelUpdates.Single().IsModified.Should().BeFalse(); + AppliedDomainEvents.ShouldBeEmpty(); + resultingReadModelUpdates.Single().IsModified.ShouldBeFalse(); } [Test] @@ -115,7 +115,7 @@ public async Task OutdatedEventsAreNotApplied() await Sut.UpdateReadStoresAsync(emittedEvents, CancellationToken.None); // Assert - AppliedDomainEvents.Should().BeEmpty(); + AppliedDomainEvents.ShouldBeEmpty(); } [Test] @@ -146,8 +146,8 @@ public async Task StoredEventsAreAppliedIfThereAreMissingEvents() await Sut.UpdateReadStoresAsync(emittedEvents, CancellationToken.None).ConfigureAwait(false); // Assert - AppliedDomainEvents.Should().HaveCount(storedEvents.Length); - AppliedDomainEvents.Should().BeEquivalentTo(storedEvents); + AppliedDomainEvents.Count.ShouldBe(storedEvents.Length); + AppliedDomainEvents.ShouldBe(storedEvents); } [Test] @@ -159,7 +159,9 @@ public void ThrowsIfReadModelSubscribesNoEvents() ReadModelWithoutEvents>(null, null, null, null, null, null); }; - a.Should().Throw().WithInnerException().WithMessage("*does not implement any*"); + var exception = Should.Throw(a); + exception.InnerException.ShouldNotBeNull(); + exception.InnerException.Message.ShouldContain("does not implement any"); } private class ReadModelWithoutEvents : IReadModel From 58ec279aa321a8363361d2f10fe351b5305608bb Mon Sep 17 00:00:00 2001 From: Focus Date: Sat, 14 Jun 2025 13:57:50 +0300 Subject: [PATCH 08/13] tests --- .../Aggregates/AggregateFactoryTests.cs | 12 +-- .../UnitTests/Aggregates/AggregateIdTests.cs | 14 +-- .../AggregateRootApplyEventTests.cs | 4 +- .../Aggregates/AggregateRootNameTests.cs | 4 +- .../Aggregates/AggregateRootTests.cs | 41 +++++---- .../Aggregates/AggregateStateTests.cs | 4 +- .../UnitTests/Aggregates/MetadataTests.cs | 32 +++---- .../ConcurrentFilesEventPersistanceTests.cs | 8 +- ...ConcurrentInMemoryEventPersistanceTests.cs | 4 +- .../EventDefinitionServiceTests.cs | 15 ++-- .../EventStores/EventUpgradeManagerTests.cs | 12 +-- .../AggregateSagas/AggregateSagaTests.cs | 88 +++++++++---------- .../UnitTests/Sagas/DispatchToSagasTests.cs | 5 +- .../Sagas/SagaDefinitionServiceTests.cs | 10 +-- .../Snapshots/SnapshotAggregateRootTests.cs | 12 +-- .../Snapshots/SnapshotMetadataTests.cs | 28 +++--- .../Snapshots/SnapshotSerializerTests.cs | 18 ++-- .../Snapshots/SnapshotSerilizerTests.cs | 18 ++-- .../Snapshots/SnapshotUpgradeServiceTests.cs | 8 +- .../SnapshotEveryFewVersionsStrategyTests.cs | 6 +- 20 files changed, 169 insertions(+), 174 deletions(-) diff --git a/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateFactoryTests.cs b/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateFactoryTests.cs index 370b6a9dd..77fdf18ae 100644 --- a/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateFactoryTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateFactoryTests.cs @@ -25,9 +25,9 @@ using EventFlow.Aggregates; using EventFlow.Core; using EventFlow.TestHelpers; -using FluentAssertions; using Moq; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Aggregates { @@ -52,8 +52,8 @@ public async Task CanCreateIdOnlyAggregateRootAsync() var idOnlyAggregateRoot = await Sut.CreateNewAggregateAsync(aggregateId).ConfigureAwait(false); // Assert - idOnlyAggregateRoot.Should().NotBeNull(); - idOnlyAggregateRoot.Id.Should().Be(aggregateId); + idOnlyAggregateRoot.ShouldNotBeNull(); + idOnlyAggregateRoot.Id.ShouldBe(aggregateId); } [Test] @@ -68,9 +68,9 @@ public async Task CanCreateAggregateWithServices() var aggregateWithServices = await Sut.CreateNewAggregateAsync(aggregateId).ConfigureAwait(false); // Assert - aggregateWithServices.Should().NotBeNull(); - aggregateWithServices.Id.Should().Be(aggregateId); - aggregateWithServices.Service.Should().BeSameAs(serviceMock.Object); + aggregateWithServices.ShouldNotBeNull(); + aggregateWithServices.Id.ShouldBe(aggregateId); + aggregateWithServices.Service.ShouldBeSameAs(serviceMock.Object); } diff --git a/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateIdTests.cs b/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateIdTests.cs index 6bd395ed1..1902bbee7 100644 --- a/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateIdTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateIdTests.cs @@ -22,8 +22,8 @@ using EventFlow.TestHelpers; using EventFlow.TestHelpers.Aggregates; -using FluentAssertions; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Aggregates { @@ -40,7 +40,7 @@ public void ManuallyCreatedIsOk() var testId = ThingyId.With(value); // Test - testId.Value.Should().Be(value); + testId.Value.ShouldBe(value); } [Test] @@ -51,7 +51,7 @@ public void CreatedIsDifferent() var id2 = ThingyId.New; // Assert - id1.Value.Should().NotBe(id2.Value); + id1.Value.ShouldNotBe(id2.Value); } [Test] @@ -63,8 +63,8 @@ public void SameIdsAreEqual() var id2 = ThingyId.With(value); // Assert - id1.Equals(id2).Should().BeTrue(); - (id1 == id2).Should().BeTrue(); + id1.Equals(id2).ShouldBeTrue(); + (id1 == id2).ShouldBeTrue(); } [Test] @@ -75,8 +75,8 @@ public void DifferentAreNotEqual() var id2 = ThingyId.With("thingy-d15b1562-11f2-4645-8b1a-f8b946b566d3"); // Assert - id1.Equals(id2).Should().BeFalse(); - (id1 == id2).Should().BeFalse(); + id1.Equals(id2).ShouldBeFalse(); + (id1 == id2).ShouldBeFalse(); } } } \ No newline at end of file diff --git a/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateRootApplyEventTests.cs b/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateRootApplyEventTests.cs index 2505551bc..214f8b673 100644 --- a/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateRootApplyEventTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateRootApplyEventTests.cs @@ -23,8 +23,8 @@ using EventFlow.Aggregates; using EventFlow.Core; using EventFlow.TestHelpers; -using FluentAssertions; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Aggregates { @@ -41,7 +41,7 @@ public void EventApplier() myAggregate.Count(42); // Assert - myAggregate.State.Count.Should().Be(42); + myAggregate.State.Count.ShouldBe(42); } diff --git a/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateRootNameTests.cs b/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateRootNameTests.cs index 73f6861ee..1bb90e212 100644 --- a/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateRootNameTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateRootNameTests.cs @@ -24,8 +24,8 @@ using EventFlow.Aggregates; using EventFlow.TestHelpers; using EventFlow.TestHelpers.Aggregates; -using FluentAssertions; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Aggregates { @@ -57,7 +57,7 @@ public void AggregateName(Type aggregateType, string expectedName) var aggregate = (IAggregateRoot) Activator.CreateInstance(aggregateType, ThingyId.New); // Assert - aggregate.Name.Value.Should().Be(expectedName); + aggregate.Name.Value.ShouldBe(expectedName); } } } \ No newline at end of file diff --git a/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateRootTests.cs b/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateRootTests.cs index 7786637c2..eac930c40 100644 --- a/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateRootTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateRootTests.cs @@ -27,8 +27,8 @@ using EventFlow.TestHelpers.Aggregates; using EventFlow.TestHelpers.Aggregates.Events; using EventFlow.TestHelpers.Aggregates.ValueObjects; -using FluentAssertions; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Aggregates { @@ -40,9 +40,9 @@ public class AggregateRootTests : TestsFor public void InitialVersionIsZero() { // Assert - Sut.Version.Should().Be(0); - Sut.IsNew.Should().BeTrue(); - Sut.UncommittedEvents.Count().Should().Be(0); + Sut.Version.ShouldBe(0); + Sut.IsNew.ShouldBeTrue(); + Sut.UncommittedEvents.Count().ShouldBe(0); } [Test] @@ -52,10 +52,10 @@ public void ApplyingEventIncrementsVersion() Sut.Ping(PingId.New); // Assert - Sut.Version.Should().Be(1); - Sut.IsNew.Should().BeFalse(); - Sut.UncommittedEvents.Count().Should().Be(1); - Sut.PingsReceived.Count.Should().Be(1); + Sut.Version.ShouldBe(1); + Sut.IsNew.ShouldBeFalse(); + Sut.UncommittedEvents.Count().ShouldBe(1); + Sut.PingsReceived.Count.ShouldBe(1); } [Test] @@ -73,10 +73,10 @@ public void EventsCanBeApplied() Sut.ApplyEvents(domainEvents); // Assert - Sut.IsNew.Should().BeFalse(); - Sut.Version.Should().Be(2); - Sut.PingsReceived.Count.Should().Be(2); - Sut.UncommittedEvents.Count().Should().Be(0); + Sut.IsNew.ShouldBeFalse(); + Sut.Version.ShouldBe(2); + Sut.PingsReceived.Count.ShouldBe(2); + Sut.UncommittedEvents.Count().ShouldBe(0); } [Test] @@ -86,7 +86,7 @@ public void EmptyListCanBeApplied() Sut.ApplyEvents(new IDomainEvent[]{}); // Assert - Sut.Version.Should().Be(0); + Sut.Version.ShouldBe(0); } [Test] @@ -96,7 +96,7 @@ public void ApplyIsInvoked() Sut.DomainErrorAfterFirst(); // Assert - Sut.DomainErrorAfterFirstReceived.Should().BeTrue(); + Sut.DomainErrorAfterFirstReceived.ShouldBeTrue(); } [Test] @@ -106,7 +106,7 @@ public void ApplyIsInvokedForExplicitImplementations() Sut.Delete(); // Assert - Sut.IsDeleted.Should().BeTrue(); + Sut.IsDeleted.ShouldBeTrue(); } [Test] @@ -119,7 +119,8 @@ public void UncommittedEventIdsShouldBeDistinct() // Assert Sut.UncommittedEvents .Select(e => e.Metadata.EventId).Distinct() - .Should().HaveCount(2); + .Count() + .ShouldBe(2); } [Test] @@ -139,12 +140,10 @@ public void UncommittedEventIdsShouldBeDeterministic() // GuidFactories.Deterministic.Namespaces.Events, $"{thingyId.Value}-v1" eventIdGuids[0] - .Should() - .Be("event-3dde5ccb-b594-59b4-ad0a-4d432ffce026"); + .ShouldBe("event-3dde5ccb-b594-59b4-ad0a-4d432ffce026"); // GuidFactories.Deterministic.Namespaces.Events, $"{thingyId.Value}-v2" eventIdGuids[1] - .Should() - .Be("event-2e79868f-6ef7-5c88-a941-12ae7ae801c7"); + .ShouldBe("event-2e79868f-6ef7-5c88-a941-12ae7ae801c7"); } [Test] @@ -158,7 +157,7 @@ public void ApplyEventWithOutOfOrderSequenceNumberShouldThrow() Action applyingEvents = () => Sut.ApplyEvents(new []{ domainEvent }); // Assert - applyingEvents.Should().Throw(); + applyingEvents.ShouldThrow(); } } } \ No newline at end of file diff --git a/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateStateTests.cs b/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateStateTests.cs index 6c96afbc2..591f0bd86 100644 --- a/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateStateTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Aggregates/AggregateStateTests.cs @@ -26,8 +26,8 @@ using EventFlow.TestHelpers.Aggregates; using EventFlow.TestHelpers.Aggregates.Events; using EventFlow.TestHelpers.Aggregates.ValueObjects; -using FluentAssertions; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Aggregates { @@ -44,7 +44,7 @@ public void ApplyIsInvoked() Sut.Apply(null, new ThingyPingEvent(pingId)); // Assert - Sut.PingIds.Should().Contain(pingId); + Sut.PingIds.ShouldContain(pingId); } public class TestAggregateState : AggregateState, diff --git a/Source/EventFlow.Tests/UnitTests/Aggregates/MetadataTests.cs b/Source/EventFlow.Tests/UnitTests/Aggregates/MetadataTests.cs index ed74f4eaf..5166353a6 100644 --- a/Source/EventFlow.Tests/UnitTests/Aggregates/MetadataTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Aggregates/MetadataTests.cs @@ -24,9 +24,9 @@ using System.Collections.Generic; using EventFlow.Aggregates; using EventFlow.TestHelpers; -using FluentAssertions; using Newtonsoft.Json; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Aggregates { @@ -46,7 +46,7 @@ public void TimestampIsSerializedCorrectly() }; // Assert - sut.Timestamp.Should().Be(timestamp); + sut.Timestamp.ShouldBe(timestamp); } [Test] @@ -62,7 +62,7 @@ public void EventNameIsSerializedCorrectly() }; // Assert - sut.EventName.Should().Be(eventName); + sut.EventName.ShouldBe(eventName); } [Test] @@ -78,7 +78,7 @@ public void EventVersionIsSerializedCorrectly() }; // Assert - sut.EventVersion.Should().Be(eventVersion); + sut.EventVersion.ShouldBe(eventVersion); } [Test] @@ -94,7 +94,7 @@ public void AggregateSequenceNumberIsSerializedCorrectly() }; // Assert - sut.AggregateSequenceNumber.Should().Be(aggregateSequenceNumber); + sut.AggregateSequenceNumber.ShouldBe(aggregateSequenceNumber); } [Test] @@ -111,12 +111,12 @@ public void CloneWithCanMerge() var metadata2 = metadata1.CloneWith(new KeyValuePair(key2, value2)); // Assert - metadata1.ContainsKey(key2).Should().BeFalse(); + metadata1.ContainsKey(key2).ShouldBeFalse(); - metadata2.ContainsKey(key1).Should().BeTrue(); - metadata2.ContainsKey(key2).Should().BeTrue(); - metadata2[key1].Should().Be(value1); - metadata2[key2].Should().Be(value2); + metadata2.ContainsKey(key1).ShouldBeTrue(); + metadata2.ContainsKey(key2).ShouldBeTrue(); + metadata2[key1].ShouldBe(value1); + metadata2[key2].ShouldBe(value2); } [Test] @@ -138,10 +138,10 @@ public void SerializeDeserializeWithValues() var metadata = JsonConvert.DeserializeObject(json); // Assert - metadata.Count.Should().Be(3); - metadata.AggregateName.Should().Be(aggregateName); - metadata.AggregateSequenceNumber.Should().Be(aggregateSequenceNumber); - metadata.Timestamp.Should().Be(timestamp); + metadata.Count.ShouldBe(3); + metadata.AggregateName.ShouldBe(aggregateName); + metadata.AggregateSequenceNumber.ShouldBe(aggregateSequenceNumber); + metadata.Timestamp.ShouldBe(timestamp); } [Test] @@ -155,8 +155,8 @@ public void SerializeDeserializeEmpty() var metadata = JsonConvert.DeserializeObject(json); // Assert - json.Should().Be("{}"); - metadata.Count.Should().Be(0); + json.ShouldBe("{}"); + metadata.Count.ShouldBe(0); } } } diff --git a/Source/EventFlow.Tests/UnitTests/EventStores/ConcurrentFilesEventPersistanceTests.cs b/Source/EventFlow.Tests/UnitTests/EventStores/ConcurrentFilesEventPersistanceTests.cs index 6c2a2e84b..685aa11a6 100644 --- a/Source/EventFlow.Tests/UnitTests/EventStores/ConcurrentFilesEventPersistanceTests.cs +++ b/Source/EventFlow.Tests/UnitTests/EventStores/ConcurrentFilesEventPersistanceTests.cs @@ -38,9 +38,9 @@ using EventFlow.TestHelpers.Aggregates; using EventFlow.TestHelpers.Aggregates.Events; using EventFlow.TestHelpers.Aggregates.ValueObjects; -using FluentAssertions; using Microsoft.Extensions.Logging; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.EventStores { @@ -103,7 +103,7 @@ public void MultipleInstancesWithSamePathFail() Action action = () => Task.WaitAll(tasks.ToArray()); // Assert - action.Should().Throw("because of concurrent access to the same files."); + action.ShouldThrow("because of concurrent access to the same files."); } [Test] @@ -120,7 +120,7 @@ public void MultipleInstancesWithDifferentPathsWork() Action action = () => Task.WaitAll(tasks.ToArray()); // Assert - action.Should().NotThrow(); + action.ShouldNotThrow(); } [Test] @@ -137,7 +137,7 @@ public void SingleInstanceWorks() Action action = () => Task.WaitAll(tasks.ToArray()); // Assert - action.Should().NotThrow(); + action.ShouldNotThrow(); } private IFilesEventStoreConfiguration ConfigurePath(string storePath) diff --git a/Source/EventFlow.Tests/UnitTests/EventStores/ConcurrentInMemoryEventPersistanceTests.cs b/Source/EventFlow.Tests/UnitTests/EventStores/ConcurrentInMemoryEventPersistanceTests.cs index db64289a0..03a654718 100644 --- a/Source/EventFlow.Tests/UnitTests/EventStores/ConcurrentInMemoryEventPersistanceTests.cs +++ b/Source/EventFlow.Tests/UnitTests/EventStores/ConcurrentInMemoryEventPersistanceTests.cs @@ -38,8 +38,8 @@ using EventFlow.TestHelpers.Aggregates; using EventFlow.TestHelpers.Aggregates.Events; using EventFlow.TestHelpers.Aggregates.ValueObjects; -using FluentAssertions; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.EventStores { @@ -75,7 +75,7 @@ public async Task MultipleInstances() int.MaxValue, new EventUpgradeContext(), CancellationToken.None); - allEvents.DomainEvents.Count.Should().Be(NumberOfEvents * DegreeOfParallelism); + allEvents.DomainEvents.Count.ShouldBe(NumberOfEvents * DegreeOfParallelism); } private EventStoreBase CreateStore() diff --git a/Source/EventFlow.Tests/UnitTests/EventStores/EventDefinitionServiceTests.cs b/Source/EventFlow.Tests/UnitTests/EventStores/EventDefinitionServiceTests.cs index 471ed1366..ecfc1c5a8 100644 --- a/Source/EventFlow.Tests/UnitTests/EventStores/EventDefinitionServiceTests.cs +++ b/Source/EventFlow.Tests/UnitTests/EventStores/EventDefinitionServiceTests.cs @@ -24,14 +24,13 @@ using System.Collections.Generic; using System.Linq; using EventFlow.Aggregates; -using EventFlow.Configuration; using EventFlow.Configuration.EventNamingStrategy; using EventFlow.Core; using EventFlow.EventStores; using EventFlow.TestHelpers; using EventFlow.Tests.UnitTests.Core.VersionedTypes; -using FluentAssertions; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.EventStores { @@ -65,10 +64,10 @@ public void GetDefinitions_OnEventWithMultipleDefinitions_ReturnsThemAll() var eventDefinitions = Sut.GetDefinitions(typeof(MultiNamesEvent)); // Assert - eventDefinitions.Should().HaveCount(3); + eventDefinitions.Count.ShouldBe(3); eventDefinitions .Select(d => $"{d.Name}-V{d.Version}") - .Should().BeEquivalentTo(new []{"multi-names-event-V1", "MultiNamesEvent-V1", "MultiNamesEvent-V2"}); + .ShouldBeEquivalentTo(new []{"multi-names-event-V1", "MultiNamesEvent-V1", "MultiNamesEvent-V2"}); } [Test] @@ -82,13 +81,15 @@ public void GetDefinitions_OnEventWithMultipleDefinitionsAndNonDefaultNamingStra var eventDefinitions = Sut.GetDefinitions(typeof(MultiNamesEvent)); // Assert - eventDefinitions.Should().HaveCount(3); + eventDefinitions.Count.ShouldBe(3); eventDefinitions .Select(d => $"{d.Name}-V{d.Version}") - .Should().BeEquivalentTo( + .ShouldBe(new[] + { "EventFlow.Tests.UnitTests.EventStores.MultiNamesEvent-V1", "EventFlow.Tests.UnitTests.EventStores.MultiNamesEvent-V1", - "EventFlow.Tests.UnitTests.EventStores.MultiNamesEvent-V2"); + "EventFlow.Tests.UnitTests.EventStores.MultiNamesEvent-V2" + }, ignoreOrder: true); } [EventVersion("Fancy", 42)] diff --git a/Source/EventFlow.Tests/UnitTests/EventStores/EventUpgradeManagerTests.cs b/Source/EventFlow.Tests/UnitTests/EventStores/EventUpgradeManagerTests.cs index 8d3a4a939..53a705c22 100644 --- a/Source/EventFlow.Tests/UnitTests/EventStores/EventUpgradeManagerTests.cs +++ b/Source/EventFlow.Tests/UnitTests/EventStores/EventUpgradeManagerTests.cs @@ -31,9 +31,9 @@ using EventFlow.TestHelpers.Aggregates; using EventFlow.TestHelpers.Aggregates.Events; using EventFlow.TestHelpers.Aggregates.ValueObjects; -using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.EventStores { @@ -64,7 +64,7 @@ public async Task EmptyListReturnsEmptyList() var upgradedEvents = await Sut.UpgradeAsync(events.ToAsyncEnumerable(), CancellationToken.None).ToArrayAsync(); // Assert - upgradedEvents.Should().BeEmpty(); + upgradedEvents.ShouldBeEmpty(); } [Test] @@ -81,8 +81,8 @@ public async Task EventWithNoUpgradersIsReturned() var upgradedEvents = await Sut.UpgradeAsync(events.ToAsyncEnumerable(), CancellationToken.None).ToArrayAsync(); // Assert - upgradedEvents.Length.Should().Be(2); - upgradedEvents.Should().Contain(events); + upgradedEvents.Length.ShouldBe(2); + upgradedEvents.ShouldBe(events, ignoreOrder: true); } [Test] @@ -101,10 +101,10 @@ public async Task EventsAreUpgradedToLatestVersion() var upgradedEvents = await Sut.UpgradeAsync(events.ToAsyncEnumerable(), CancellationToken.None).ToArrayAsync(); // Assert - upgradedEvents.Length.Should().Be(3); + upgradedEvents.Length.ShouldBe(3); foreach (var upgradedEvent in upgradedEvents) { - upgradedEvent.Should().BeAssignableTo>(); + upgradedEvent.ShouldBeAssignableTo>(); } } diff --git a/Source/EventFlow.Tests/UnitTests/Sagas/AggregateSagas/AggregateSagaTests.cs b/Source/EventFlow.Tests/UnitTests/Sagas/AggregateSagas/AggregateSagaTests.cs index ef2e1aced..296418651 100644 --- a/Source/EventFlow.Tests/UnitTests/Sagas/AggregateSagas/AggregateSagaTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Sagas/AggregateSagas/AggregateSagaTests.cs @@ -30,13 +30,13 @@ using EventFlow.TestHelpers.Aggregates.Commands; using EventFlow.TestHelpers.Aggregates.Events; using EventFlow.TestHelpers.Aggregates.Sagas; -using FluentAssertions; using Moq; using NUnit.Framework; using System; using System.Reflection; using System.Threading; using System.Threading.Tasks; +using Shouldly; namespace EventFlow.Tests.UnitTests.Sagas.AggregateSagas { @@ -88,7 +88,7 @@ await Sut.PublishAsync( } // Assert - exception.Should().BeNull(); + exception.ShouldBeNull(); } [Test] @@ -119,7 +119,7 @@ await Sut.PublishAsync( } // Assert - exception.Should().BeNull(); + exception.ShouldBeNull(); } [Test] @@ -154,7 +154,7 @@ await Sut.PublishAsync( } // Assert - exception.Should().BeNull(); + exception.ShouldBeNull(); } [Test] @@ -186,19 +186,19 @@ await Sut.PublishAsync( } // Assert - exception.Should().NotBeNull(); - exception.Should().BeAssignableTo(); + exception.ShouldNotBeNull(); + exception.ShouldBeAssignableTo(); var sagaPublishException = exception as SagaPublishException; - sagaPublishException.InnerExceptions.Count.Should().Be(1); + sagaPublishException.InnerExceptions.Count.ShouldBe(1); var innerException = sagaPublishException.InnerExceptions[0]; - innerException.Should().BeAssignableTo(); + innerException.ShouldBeAssignableTo(); var commandException = innerException as CommandException; - commandException.Message.Should().Contain(message); - commandException.Message.Should().Contain(Sut.Id.ToString()); - commandException.CommandType.Should().Be(typeof(ThingyAddMessageCommand)); - commandException.ExecutionResult.Should().NotBeNull(); - commandException.ExecutionResult.IsSuccess.Should().BeFalse(); - commandException.ExecutionResult.ToString().Should().Contain(message); + commandException.Message.ShouldContain(message); + commandException.Message.ShouldContain(Sut.Id.ToString()); + commandException.CommandType.ShouldBe(typeof(ThingyAddMessageCommand)); + commandException.ExecutionResult.ShouldNotBeNull(); + commandException.ExecutionResult.IsSuccess.ShouldBeFalse(); + commandException.ExecutionResult.ToString().ShouldContain(message); } [Test] @@ -234,20 +234,20 @@ await Sut.PublishAsync( } // Assert - exception.Should().NotBeNull(); - exception.Should().BeAssignableTo(); + exception.ShouldNotBeNull(); + exception.ShouldBeAssignableTo(); var sagaPublishException = exception as SagaPublishException; - sagaPublishException.InnerExceptions.Count.Should().Be(2); + sagaPublishException.InnerExceptions.Count.ShouldBe(2); foreach (var innerException in sagaPublishException.InnerExceptions) { - innerException.Should().BeAssignableTo(); + innerException.ShouldBeAssignableTo(); var commandException = innerException as CommandException; - commandException.Message.Should().Contain(message); - commandException.Message.Should().Contain(Sut.Id.ToString()); - commandException.CommandType.Should().Be(typeof(ThingyAddMessageCommand)); - commandException.ExecutionResult.Should().NotBeNull(); - commandException.ExecutionResult.IsSuccess.Should().BeFalse(); - commandException.ExecutionResult.ToString().Should().Contain(message); + commandException.Message.ShouldContain(message); + commandException.Message.ShouldContain(Sut.Id.ToString()); + commandException.CommandType.ShouldBe(typeof(ThingyAddMessageCommand)); + commandException.ExecutionResult.ShouldNotBeNull(); + commandException.ExecutionResult.IsSuccess.ShouldBeFalse(); + commandException.ExecutionResult.ToString().ShouldContain(message); } } @@ -280,19 +280,19 @@ await Sut.PublishAsync( } // Assert - exception.Should().NotBeNull(); - exception.Should().BeAssignableTo(); + exception.ShouldNotBeNull(); + exception.ShouldBeAssignableTo(); var sagaPublishException = exception as SagaPublishException; - sagaPublishException.InnerExceptions.Count.Should().Be(1); + sagaPublishException.InnerExceptions.Count.ShouldBe(1); var innerException = sagaPublishException.InnerExceptions[0]; - innerException.Should().BeAssignableTo(); + innerException.ShouldBeAssignableTo(); var commandException = innerException as CommandException; - commandException.Message.Should().Contain(message); - commandException.Message.Should().Contain(Sut.Id.ToString()); - commandException.CommandType.Should().Be(typeof(ThingyAddMessageCommand)); - commandException.InnerException.Should().NotBeNull(); - commandException.InnerException.Should().BeAssignableTo(); - commandException.InnerException.Message.Should().Be(message); + commandException.Message.ShouldContain(message); + commandException.Message.ShouldContain(Sut.Id.ToString()); + commandException.CommandType.ShouldBe(typeof(ThingyAddMessageCommand)); + commandException.InnerException.ShouldNotBeNull(); + commandException.InnerException.ShouldBeAssignableTo(); + commandException.InnerException.Message.ShouldBe(message); } [Test] @@ -328,20 +328,20 @@ await Sut.PublishAsync( } // Assert - exception.Should().NotBeNull(); - exception.Should().BeAssignableTo(); + exception.ShouldNotBeNull(); + exception.ShouldBeAssignableTo(); var sagaPublishException = exception as SagaPublishException; - sagaPublishException.InnerExceptions.Count.Should().Be(2); + sagaPublishException.InnerExceptions.Count.ShouldBe(2); foreach (var innerException in sagaPublishException.InnerExceptions) { - innerException.Should().BeAssignableTo(); + innerException.ShouldBeAssignableTo(); var commandException = innerException as CommandException; - commandException.Message.Should().Contain(message); - commandException.Message.Should().Contain(Sut.Id.ToString()); - commandException.CommandType.Should().Be(typeof(ThingyAddMessageCommand)); - commandException.InnerException.Should().NotBeNull(); - commandException.InnerException.Should().BeAssignableTo(); - commandException.InnerException.Message.Should().Be(message); + commandException.Message.ShouldContain(message); + commandException.Message.ShouldContain(Sut.Id.ToString()); + commandException.CommandType.ShouldBe(typeof(ThingyAddMessageCommand)); + commandException.InnerException.ShouldNotBeNull(); + commandException.InnerException.ShouldBeAssignableTo(); + commandException.InnerException.Message.ShouldBe(message); } } } diff --git a/Source/EventFlow.Tests/UnitTests/Sagas/DispatchToSagasTests.cs b/Source/EventFlow.Tests/UnitTests/Sagas/DispatchToSagasTests.cs index 6f9b1a470..4204a107c 100644 --- a/Source/EventFlow.Tests/UnitTests/Sagas/DispatchToSagasTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Sagas/DispatchToSagasTests.cs @@ -24,15 +24,14 @@ using System.Threading; using System.Threading.Tasks; using EventFlow.Aggregates; -using EventFlow.Configuration; using EventFlow.Core; using EventFlow.Sagas; using EventFlow.TestHelpers; using EventFlow.TestHelpers.Aggregates.Events; using EventFlow.TestHelpers.Aggregates.Sagas; -using FluentAssertions; using Moq; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Sagas { @@ -143,7 +142,7 @@ public void UnhandledSagaErrorIsThrown() async () => await Sut.ProcessAsync(domainEvents, CancellationToken.None).ConfigureAwait(false)); // Assert - thrownException.Should().BeSameAs(expectedException); + thrownException.ShouldBeSameAs(expectedException); } private Exception Arrange_Faulty_SagaStore() diff --git a/Source/EventFlow.Tests/UnitTests/Sagas/SagaDefinitionServiceTests.cs b/Source/EventFlow.Tests/UnitTests/Sagas/SagaDefinitionServiceTests.cs index 22fc0eadf..365ec39f3 100644 --- a/Source/EventFlow.Tests/UnitTests/Sagas/SagaDefinitionServiceTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Sagas/SagaDefinitionServiceTests.cs @@ -26,8 +26,8 @@ using EventFlow.TestHelpers; using EventFlow.TestHelpers.Aggregates.Events; using EventFlow.TestHelpers.Aggregates.Sagas; -using FluentAssertions; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Sagas { @@ -45,8 +45,8 @@ public void GetSagaTypeDetails_WithSubscribedAggregateEvents(Type aggregateEvent var sagaTypeDetails = Sut.GetSagaDetails(aggregateEventType).ToList(); // Assert - sagaTypeDetails.Should().HaveCount(1); - sagaTypeDetails.Single().SagaType.Should().Be(typeof(ThingySaga)); + sagaTypeDetails.Count.ShouldBe(1); + sagaTypeDetails.Single().SagaType.ShouldBe(typeof(ThingySaga)); } [Test] @@ -58,7 +58,7 @@ public void LoadSagas_IgnoresMultipleLoads() // Assert var sagaDetails = Sut.GetSagaDetails(typeof(ThingySagaStartRequestedEvent)).ToList(); - sagaDetails.Should().HaveCount(1); + sagaDetails.Count.ShouldBe(1); } [TestCase(typeof(ThingyDomainErrorAfterFirstEvent))] @@ -72,7 +72,7 @@ public void GetSagaTypeDetails_WithUnknownAggregateEvents(Type aggregateEventTyp var sagaTypeDetails = Sut.GetSagaDetails(aggregateEventType).ToList(); // Assert - sagaTypeDetails.Should().BeEmpty(); + sagaTypeDetails.ShouldBeEmpty(); } } } \ No newline at end of file diff --git a/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotAggregateRootTests.cs b/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotAggregateRootTests.cs index 7989b8f65..38a39c012 100644 --- a/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotAggregateRootTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotAggregateRootTests.cs @@ -35,9 +35,9 @@ using EventFlow.TestHelpers.Aggregates.Events; using EventFlow.TestHelpers.Aggregates.Snapshots; using EventFlow.TestHelpers.Aggregates.ValueObjects; -using FluentAssertions; using Moq; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Snapshots { @@ -84,9 +84,9 @@ public async Task SnapshotIsLoaded(int eventsInStore) await Sut.LoadAsync(_eventStoreMock.Object, _snapshotStore.Object, CancellationToken.None); // Assert - Sut.Version.Should().Be(eventsInStore); - Sut.SnapshotVersion.GetValueOrDefault().Should().Be(ThingyAggregate.SnapshotEveryVersion); - Sut.PreviousSourceIds.Should().NotBeEmpty(); + Sut.Version.ShouldBe(eventsInStore); + Sut.SnapshotVersion.GetValueOrDefault().ShouldBe(ThingyAggregate.SnapshotEveryVersion); + Sut.PreviousSourceIds.ShouldNotBeEmpty(); } [SetUp] @@ -112,7 +112,7 @@ public async Task Test_Arrange_EventStore(int eventInStore, int fromEventSequenc CancellationToken.None); // Assert - domainEvents.Should().HaveCount(expectedNumberOfEvents); + domainEvents.Count.ShouldBe(expectedNumberOfEvents); } [Description("Mock test")] @@ -133,7 +133,7 @@ public async Task Test_Arrange_EventStore_SequenceRange(int eventInStore, int fr CancellationToken.None); // Assert - domainEvents.Should().HaveCount(expectedNumberOfEvents); + domainEvents.Count.ShouldBe(expectedNumberOfEvents); } private void Arrange_EventStore(IEnumerable> domainEvents) diff --git a/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotMetadataTests.cs b/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotMetadataTests.cs index 2efe4b8e7..82f7eafe5 100644 --- a/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotMetadataTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotMetadataTests.cs @@ -25,9 +25,9 @@ using EventFlow.Snapshots; using EventFlow.TestHelpers; using EventFlow.TestHelpers.Extensions; -using FluentAssertions; using Newtonsoft.Json; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Snapshots { @@ -52,12 +52,12 @@ public void DeserializesCorrectly() var snapshotMetadata = JsonConvert.DeserializeObject(json); // Assert - snapshotMetadata.AggregateId.Should().Be("thingy-42"); - snapshotMetadata.AggregateName.Should().Be("thingy"); - snapshotMetadata.AggregateSequenceNumber.Should().Be(42); - snapshotMetadata.SnapshotName.Should().Be("thingy"); - snapshotMetadata.SnapshotVersion.Should().Be(84); - snapshotMetadata.PreviousSourceIds.Select(s => s.Value).Should().BeEquivalentTo("cool", "magic"); + snapshotMetadata.AggregateId.ShouldBe("thingy-42"); + snapshotMetadata.AggregateName.ShouldBe("thingy"); + snapshotMetadata.AggregateSequenceNumber.ShouldBe(42); + snapshotMetadata.SnapshotName.ShouldBe("thingy"); + snapshotMetadata.SnapshotVersion.ShouldBe(84); + snapshotMetadata.PreviousSourceIds.Select(s => s.Value).ShouldBeEquivalentTo("cool", "magic"); } [Test] @@ -83,12 +83,12 @@ public void GettersAndSettersWork() var deserializedSnapshotMetadata = JsonConvert.DeserializeObject(json); // Assert - deserializedSnapshotMetadata.AggregateId.Should().Be("thingy-42"); - deserializedSnapshotMetadata.AggregateName.Should().Be("thingy"); - deserializedSnapshotMetadata.AggregateSequenceNumber.Should().Be(42); - deserializedSnapshotMetadata.SnapshotName.Should().Be("thingy"); - deserializedSnapshotMetadata.SnapshotVersion.Should().Be(84); - deserializedSnapshotMetadata.PreviousSourceIds.Select(s => s.Value).Should().BeEquivalentTo("cool", "magic"); + deserializedSnapshotMetadata.AggregateId.ShouldBe("thingy-42"); + deserializedSnapshotMetadata.AggregateName.ShouldBe("thingy"); + deserializedSnapshotMetadata.AggregateSequenceNumber.ShouldBe(42); + deserializedSnapshotMetadata.SnapshotName.ShouldBe("thingy"); + deserializedSnapshotMetadata.SnapshotVersion.ShouldBe(84); + deserializedSnapshotMetadata.PreviousSourceIds.Select(s => s.Value).ShouldBeEquivalentTo("cool", "magic"); } [Test] @@ -101,7 +101,7 @@ public void PreviousSourceIdsIsAllowedToBeEmpty() var previousSourceIds = snapshotMetadata.PreviousSourceIds; // Assert - previousSourceIds.Should().BeEmpty(); + previousSourceIds.ShouldBeEmpty(); } } } \ No newline at end of file diff --git a/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotSerializerTests.cs b/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotSerializerTests.cs index 8cbac5db3..79bb15390 100644 --- a/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotSerializerTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotSerializerTests.cs @@ -29,10 +29,10 @@ using EventFlow.TestHelpers; using EventFlow.TestHelpers.Aggregates; using EventFlow.TestHelpers.Aggregates.Snapshots; -using FluentAssertions; using Moq; using Newtonsoft.Json; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Snapshots { @@ -57,9 +57,9 @@ public async Task SerilizeAsync_ReturnsSomething() .ConfigureAwait(false); // Assert - serializedSnapshot.Should().NotBeNull(); - serializedSnapshot.SerializedData.Should().NotBeNullOrEmpty(); - serializedSnapshot.SerializedMetadata.Should().NotBeNullOrEmpty(); + serializedSnapshot.ShouldNotBeNull(); + serializedSnapshot.SerializedData.ShouldNotBeNullOrEmpty(); + serializedSnapshot.SerializedMetadata.ShouldNotBeNullOrEmpty(); } [Test] @@ -77,12 +77,10 @@ public async Task DeserializeAsync_ReturnsSomething() .ConfigureAwait(false); // Assert - snapshotContainer.Should().NotBeNull(); - snapshotContainer.Metadata.Should().NotBeNull(); - snapshotContainer.Snapshot.Should() - .NotBeNull() - .And - .BeOfType(); + snapshotContainer.ShouldNotBeNull(); + snapshotContainer.Metadata.ShouldNotBeNull(); + snapshotContainer.Snapshot.ShouldNotBeNull(); + snapshotContainer.Snapshot.ShouldBeOfType(); } [SetUp] diff --git a/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotSerilizerTests.cs b/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotSerilizerTests.cs index df4389062..0ca74d964 100644 --- a/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotSerilizerTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotSerilizerTests.cs @@ -29,10 +29,10 @@ using EventFlow.TestHelpers; using EventFlow.TestHelpers.Aggregates; using EventFlow.TestHelpers.Aggregates.Snapshots; -using FluentAssertions; using Moq; using Newtonsoft.Json; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Snapshots { @@ -58,9 +58,9 @@ public async Task SerilizeAsync_ReturnsSomething() .ConfigureAwait(false); // Assert - serializedSnapshot.Should().NotBeNull(); - serializedSnapshot.SerializedData.Should().NotBeNullOrEmpty(); - serializedSnapshot.SerializedMetadata.Should().NotBeNullOrEmpty(); + serializedSnapshot.ShouldNotBeNull(); + serializedSnapshot.SerializedData.ShouldNotBeNullOrEmpty(); + serializedSnapshot.SerializedMetadata.ShouldNotBeNullOrEmpty(); } [Test] @@ -78,12 +78,10 @@ public async Task DeserializeAsync_ReturnsSomething() .ConfigureAwait(false); // Assert - snapshotContainer.Should().NotBeNull(); - snapshotContainer.Metadata.Should().NotBeNull(); - snapshotContainer.Snapshot.Should() - .NotBeNull() - .And - .BeOfType(); + snapshotContainer.ShouldNotBeNull(); + snapshotContainer.Metadata.ShouldNotBeNull(); + snapshotContainer.Snapshot.ShouldNotBeNull(); + snapshotContainer.Snapshot.ShouldBeOfType(); } [SetUp] diff --git a/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotUpgradeServiceTests.cs b/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotUpgradeServiceTests.cs index c6fcaf3c0..f13f102dc 100644 --- a/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotUpgradeServiceTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotUpgradeServiceTests.cs @@ -30,10 +30,10 @@ using EventFlow.TestHelpers.Aggregates.Snapshots; using EventFlow.TestHelpers.Aggregates.Snapshots.Upgraders; using EventFlow.TestHelpers.Aggregates.ValueObjects; -using FluentAssertions; using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Snapshots { @@ -64,10 +64,10 @@ public async Task UpgradeAsync_UpgradesSnapshot() var snapshot = await Sut.UpgradeAsync(new ThingySnapshotV1(pingIds), CancellationToken.None); // Assert - snapshot.Should().BeOfType(); + snapshot.ShouldBeOfType(); var thingySnapshot = (ThingySnapshot) snapshot; - thingySnapshot.PingsReceived.Should().BeEquivalentTo(pingIds); - thingySnapshot.PreviousVersions.Should().BeEquivalentTo(new[] {ThingySnapshotVersion.Version1, ThingySnapshotVersion.Version2}); + thingySnapshot.PingsReceived.ShouldBeEquivalentTo(pingIds); + thingySnapshot.PreviousVersions.ShouldBeEquivalentTo(new[] {ThingySnapshotVersion.Version1, ThingySnapshotVersion.Version2}); } private void Arrange_All_Upgraders() diff --git a/Source/EventFlow.Tests/UnitTests/Snapshots/Strategies/SnapshotEveryFewVersionsStrategyTests.cs b/Source/EventFlow.Tests/UnitTests/Snapshots/Strategies/SnapshotEveryFewVersionsStrategyTests.cs index 6eefead09..ca32453b8 100644 --- a/Source/EventFlow.Tests/UnitTests/Snapshots/Strategies/SnapshotEveryFewVersionsStrategyTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Snapshots/Strategies/SnapshotEveryFewVersionsStrategyTests.cs @@ -25,9 +25,9 @@ using EventFlow.Snapshots; using EventFlow.Snapshots.Strategies; using EventFlow.TestHelpers; -using FluentAssertions; using Moq; using NUnit.Framework; +using Shouldly; namespace EventFlow.Tests.UnitTests.Snapshots.Strategies { @@ -47,7 +47,7 @@ public class SnapshotEveryFewVersionsStrategyTests public async Task ShouldCreateSnapshotAsync_ReturnsCorrect(int aggregateRootVersion, int? snapshotVersion, bool expectedShouldCreateSnapshot) { // Assumptions - SnapshotEveryFewVersionsStrategy.DefautSnapshotAfterVersions.Should().Be(100); + SnapshotEveryFewVersionsStrategy.DefautSnapshotAfterVersions.ShouldBe(100); // Arrange var sut = SnapshotEveryFewVersionsStrategy.Default; @@ -62,7 +62,7 @@ public async Task ShouldCreateSnapshotAsync_ReturnsCorrect(int aggregateRootVers .ConfigureAwait(false); // Assert - shouldCreateSnapshot.Should().Be(expectedShouldCreateSnapshot); + shouldCreateSnapshot.ShouldBe(expectedShouldCreateSnapshot); } } } \ No newline at end of file From 0de9b91557b8715ba6dc4bff60d07d4110e8e4ee Mon Sep 17 00:00:00 2001 From: Focus Date: Sat, 14 Jun 2025 14:27:49 +0300 Subject: [PATCH 09/13] more tests --- .../MsSql/EfMsSqlReadStoreIncludeTests.cs | 28 +++-- .../Integration/HangfireJobSchedulerTests.cs | 11 +- .../ReadStores/MongoDbReadModelStoreTests.cs | 5 +- .../EventFlowEventStoresMsSqlTests.cs | 8 +- .../IdentityIndexFragmentationTests.cs | 16 +-- .../ReadModels/MultipleMsSqlDatabasesTests.cs | 8 +- .../EventFlowSnapshotStoresMsSqlTests.cs | 6 +- .../EventFlowEventStoresPostgresSqlTests.cs | 8 +- ...EventFlowSnapshotStoresPostgresSqlTests.cs | 6 +- .../Integration/RabbitMqTests.cs | 12 +-- Source/EventFlow.TestHelpers/LoggerMock.cs | 13 ++- .../Suites/TestSuiteForEventStore.cs | 102 +++++++++--------- .../Suites/TestSuiteForReadModelStore.cs | 60 +++++------ .../Suites/TestSuiteForScheduler.cs | 5 +- .../Suites/TestSuiteForSnapshotStore.cs | 41 +++---- Source/EventFlow.Tests/LicenseHeaderTests.cs | 1 - 16 files changed, 173 insertions(+), 157 deletions(-) diff --git a/Source/EventFlow.EntityFramework.Tests/MsSql/EfMsSqlReadStoreIncludeTests.cs b/Source/EventFlow.EntityFramework.Tests/MsSql/EfMsSqlReadStoreIncludeTests.cs index a73f2d312..01ffeb90d 100644 --- a/Source/EventFlow.EntityFramework.Tests/MsSql/EfMsSqlReadStoreIncludeTests.cs +++ b/Source/EventFlow.EntityFramework.Tests/MsSql/EfMsSqlReadStoreIncludeTests.cs @@ -31,9 +31,9 @@ using EventFlow.Extensions; using EventFlow.TestHelpers; using EventFlow.TestHelpers.MsSql; -using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; +using Shouldly; namespace EventFlow.EntityFramework.Tests.MsSql { @@ -80,9 +80,9 @@ await CommandBus .ConfigureAwait(false); // Assert - readModel.Should().NotBeNull(); - readModel.Name.Should().Be("Bob"); - readModel.Addresses.Should().BeNullOrEmpty(); + readModel.ShouldNotBeNull(); + readModel.Name.ShouldBe("Bob"); + readModel.Addresses.ShouldBeNull(); } [Test] @@ -114,11 +114,21 @@ await CommandBus .ConfigureAwait(false); // Assert - readModel.Should().NotBeNull(); - readModel.NumberOfAddresses.Should().Be(2); - readModel.Addresses.Should().HaveCount(2); - readModel.Addresses.Should().ContainEquivalentOf(address1); - readModel.Addresses.Should().ContainEquivalentOf(address2); + readModel.ShouldNotBeNull(); + readModel.NumberOfAddresses.ShouldBe(2); + readModel.Addresses.Count.ShouldBe(2); + + readModel.Addresses.ShouldContain(a => + a.Street == address1.Street && + a.PostalCode == address1.PostalCode && + a.City == address1.City && + a.Country == address1.Country); + + readModel.Addresses.ShouldContain(a => + a.Street == address2.Street && + a.PostalCode == address2.PostalCode && + a.City == address2.City && + a.Country == address2.Country); } } } \ No newline at end of file diff --git a/Source/EventFlow.Hangfire.Tests/Integration/HangfireJobSchedulerTests.cs b/Source/EventFlow.Hangfire.Tests/Integration/HangfireJobSchedulerTests.cs index 277db2180..abbbf60b7 100644 --- a/Source/EventFlow.Hangfire.Tests/Integration/HangfireJobSchedulerTests.cs +++ b/Source/EventFlow.Hangfire.Tests/Integration/HangfireJobSchedulerTests.cs @@ -36,13 +36,12 @@ using EventFlow.TestHelpers.Aggregates.Commands; using EventFlow.TestHelpers.Aggregates.Events; using EventFlow.TestHelpers.Aggregates.ValueObjects; -using FluentAssertions; -using FluentAssertions.Common; using Hangfire; using Hangfire.Common; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using NUnit.Framework; +using Shouldly; namespace EventFlow.Hangfire.Tests.Integration { @@ -113,7 +112,7 @@ public async Task AsynchronousSubscribesGetInvoked() // Assert var receivedPingId = await Task.Run(() => _testAsynchronousSubscriber.PingIds.Take(), cts.Token).ConfigureAwait(false); - receivedPingId.Should().IsSameOrEqualTo(pingId); + receivedPingId.ShouldBeSameAs(pingId); } [Test] @@ -165,10 +164,10 @@ private async Task ValidateScheduleHappens(Func s.Name, s => s); // Assert - sqlScripts.Should().HaveCount(2); - sqlScripts.Should().ContainKey("EventStores.Scripts.0001 - Create table EventFlow.sql"); - sqlScripts.Should().ContainKey("EventStores.Scripts.0002 - Create eventdatamodel_list_type.sql"); + sqlScripts.Count.ShouldBe(2); + sqlScripts.ShouldContainKey("EventStores.Scripts.0001 - Create table EventFlow.sql"); + sqlScripts.ShouldContainKey("EventStores.Scripts.0002 - Create eventdatamodel_list_type.sql"); } } } \ No newline at end of file diff --git a/Source/EventFlow.MsSql.Tests/IntegrationTests/IdentityIndexFragmentationTests.cs b/Source/EventFlow.MsSql.Tests/IntegrationTests/IdentityIndexFragmentationTests.cs index 28b2d170e..d755e3f87 100644 --- a/Source/EventFlow.MsSql.Tests/IntegrationTests/IdentityIndexFragmentationTests.cs +++ b/Source/EventFlow.MsSql.Tests/IntegrationTests/IdentityIndexFragmentationTests.cs @@ -28,8 +28,8 @@ using EventFlow.MsSql.Tests.Extensions; using EventFlow.TestHelpers; using EventFlow.TestHelpers.MsSql; -using FluentAssertions; using NUnit.Framework; +using Shouldly; // ReSharper disable StringLiteralTypo @@ -56,7 +56,7 @@ public void VerifyIdentityHasThereLittleFragmentationUsingString() // Assert var fragmentation = GetIndexFragmentation("IndexFragmentationString"); - fragmentation.Should().BeLessThan(10); + fragmentation.ShouldBeLessThan(10); } @@ -77,7 +77,7 @@ public void SanityIntLowFragmentationStoredInGuid() // Assert var fragmentation = GetIndexFragmentation("IndexFragmentationString"); - fragmentation.Should().BeLessThan(10); + fragmentation.ShouldBeLessThan(10); } [Test] @@ -97,7 +97,7 @@ public void SanityIntAsHexLowFragmentationStoredInGuid() // Assert var fragmentation = GetIndexFragmentation("IndexFragmentationString"); - fragmentation.Should().BeLessThan(10); + fragmentation.ShouldBeLessThan(10); } @@ -109,7 +109,7 @@ public void SanityCombYieldsLowFragmentationStoredInGuid() // Assert var fragmentation = GetIndexFragmentation("IndexFragmentationGuid"); - fragmentation.Should().BeLessThan(10); + fragmentation.ShouldBeLessThan(10); } [Test] @@ -120,7 +120,7 @@ public void SanityCombYieldsHighFragmentationStoredInString() // Assert var fragmentation = GetIndexFragmentation("IndexFragmentationString"); - fragmentation.Should().BeGreaterThan(90); + fragmentation.ShouldBeGreaterThan(90); } [Test] @@ -131,7 +131,7 @@ public void SanityGuidIdentityYieldsHighFragmentationStoredInString() // Assert var fragmentation = GetIndexFragmentation("IndexFragmentationString"); - fragmentation.Should().BeGreaterThan(30); // closer to 100 in reality + fragmentation.ShouldBeGreaterThan(30); // closer to 100 in reality } [Test] @@ -142,7 +142,7 @@ public void SanityGuidIdentityYieldsHighFragmentationStoredInGuid() // Assert var fragmentation = GetIndexFragmentation("IndexFragmentationGuid"); - fragmentation.Should().BeGreaterThan(30); // closer to 100 in reality + fragmentation.ShouldBeGreaterThan(30); // closer to 100 in reality } public void InsertRows(Func generator, int count, string table) diff --git a/Source/EventFlow.MsSql.Tests/IntegrationTests/ReadStores/ReadModels/MultipleMsSqlDatabasesTests.cs b/Source/EventFlow.MsSql.Tests/IntegrationTests/ReadStores/ReadModels/MultipleMsSqlDatabasesTests.cs index b7ac561f5..1f0879522 100644 --- a/Source/EventFlow.MsSql.Tests/IntegrationTests/ReadStores/ReadModels/MultipleMsSqlDatabasesTests.cs +++ b/Source/EventFlow.MsSql.Tests/IntegrationTests/ReadStores/ReadModels/MultipleMsSqlDatabasesTests.cs @@ -35,9 +35,9 @@ using EventFlow.TestHelpers; using EventFlow.TestHelpers.Extensions; using EventFlow.TestHelpers.MsSql; -using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; +using Shouldly; namespace EventFlow.MsSql.Tests.IntegrationTests.ReadStores.ReadModels { @@ -120,10 +120,10 @@ public async Task MultipleDatabases() var fetchedMagicReadModels = _readModelDatabase.Query( "SELECT * FROM [ReadModel-Magic] WHERE [MagicId] = @Id", new { Id = magicId.Value }); - fetchedMagicReadModels.Should().HaveCount(1); + fetchedMagicReadModels.Count.ShouldBe(1); var fetchedMagicReadModel = fetchedMagicReadModels.Single(); - fetchedMagicReadModel.Message.Should().Be(expectedMessage); - fetchedMagicReadModel.Version.Should().Be(2); + fetchedMagicReadModel.Message.ShouldBe(expectedMessage); + fetchedMagicReadModel.Version.ShouldBe(2); } public class MagicId : Identity diff --git a/Source/EventFlow.MsSql.Tests/IntegrationTests/SnapshotStores/EventFlowSnapshotStoresMsSqlTests.cs b/Source/EventFlow.MsSql.Tests/IntegrationTests/SnapshotStores/EventFlowSnapshotStoresMsSqlTests.cs index a1cd853ae..44bc43224 100644 --- a/Source/EventFlow.MsSql.Tests/IntegrationTests/SnapshotStores/EventFlowSnapshotStoresMsSqlTests.cs +++ b/Source/EventFlow.MsSql.Tests/IntegrationTests/SnapshotStores/EventFlowSnapshotStoresMsSqlTests.cs @@ -23,8 +23,8 @@ using System.Linq; using EventFlow.MsSql.SnapshotStores; using EventFlow.TestHelpers; -using FluentAssertions; using NUnit.Framework; +using Shouldly; namespace EventFlow.MsSql.Tests.IntegrationTests.SnapshotStores { @@ -38,8 +38,8 @@ public void GetSqlScripts() var sqlScripts = EventFlowSnapshotStoresMsSql.GetSqlScripts().ToDictionary(s => s.Name, s => s); // Assert - sqlScripts.Should().HaveCount(1); - sqlScripts.Should().ContainKey("SnapshotStores.Scripts.0001 - Create EventFlowSnapshots.sql"); + sqlScripts.Count.ShouldBe(1); + sqlScripts.ShouldContainKey("SnapshotStores.Scripts.0001 - Create EventFlowSnapshots.sql"); } } } \ No newline at end of file diff --git a/Source/EventFlow.PostgreSql.Tests/IntegrationTests/EventStores/EventFlowEventStoresPostgresSqlTests.cs b/Source/EventFlow.PostgreSql.Tests/IntegrationTests/EventStores/EventFlowEventStoresPostgresSqlTests.cs index 4ebf0e448..50fe07979 100644 --- a/Source/EventFlow.PostgreSql.Tests/IntegrationTests/EventStores/EventFlowEventStoresPostgresSqlTests.cs +++ b/Source/EventFlow.PostgreSql.Tests/IntegrationTests/EventStores/EventFlowEventStoresPostgresSqlTests.cs @@ -23,8 +23,8 @@ using System.Linq; using EventFlow.PostgreSql.EventStores; using EventFlow.TestHelpers; -using FluentAssertions; using NUnit.Framework; +using Shouldly; namespace EventFlow.PostgreSql.Tests.IntegrationTests.EventStores { @@ -38,9 +38,9 @@ public void GetSqlScripts() var sqlScripts = EventFlowEventStoresPostgreSql.GetSqlScripts().ToDictionary(s => s.Name, s => s); // Assert - sqlScripts.Should().HaveCount(2); - sqlScripts.Should().ContainKey("EventStores.Scripts.0001 - Create table EventFlow.sql"); - sqlScripts.Should().ContainKey("EventStores.Scripts.0002 - Create eventdatamodel_list_type.sql"); + sqlScripts.Count.ShouldBe(2); + sqlScripts.ShouldContainKey("EventStores.Scripts.0001 - Create table EventFlow.sql"); + sqlScripts.ShouldContainKey("EventStores.Scripts.0002 - Create eventdatamodel_list_type.sql"); } } } \ No newline at end of file diff --git a/Source/EventFlow.PostgreSql.Tests/IntegrationTests/SnapshotStores/EventFlowSnapshotStoresPostgresSqlTests.cs b/Source/EventFlow.PostgreSql.Tests/IntegrationTests/SnapshotStores/EventFlowSnapshotStoresPostgresSqlTests.cs index b6abfaa6f..9ef62d52a 100644 --- a/Source/EventFlow.PostgreSql.Tests/IntegrationTests/SnapshotStores/EventFlowSnapshotStoresPostgresSqlTests.cs +++ b/Source/EventFlow.PostgreSql.Tests/IntegrationTests/SnapshotStores/EventFlowSnapshotStoresPostgresSqlTests.cs @@ -23,8 +23,8 @@ using System.Linq; using EventFlow.PostgreSql.SnapshotStores; using EventFlow.TestHelpers; -using FluentAssertions; using NUnit.Framework; +using Shouldly; namespace EventFlow.PostgreSql.Tests.IntegrationTests.SnapshotStores { @@ -38,8 +38,8 @@ public void GetSqlScripts() var sqlScripts = EventFlowSnapshotStoresPostgreSql.GetSqlScripts().ToDictionary(s => s.Name, s => s); // Assert - sqlScripts.Should().HaveCount(1); - sqlScripts.Should().ContainKey("SnapshotStores.Scripts.0001 - Create EventFlowSnapshots.sql"); + sqlScripts.Count.ShouldBe(1); + sqlScripts.ShouldContainKey("SnapshotStores.Scripts.0001 - Create EventFlowSnapshots.sql"); } } } \ No newline at end of file diff --git a/Source/EventFlow.RabbitMQ.Tests/Integration/RabbitMqTests.cs b/Source/EventFlow.RabbitMQ.Tests/Integration/RabbitMqTests.cs index 09759f67f..aef439d1c 100644 --- a/Source/EventFlow.RabbitMQ.Tests/Integration/RabbitMqTests.cs +++ b/Source/EventFlow.RabbitMQ.Tests/Integration/RabbitMqTests.cs @@ -36,11 +36,11 @@ using EventFlow.TestHelpers.Aggregates.Events; using EventFlow.TestHelpers.Aggregates.Queries; using EventFlow.TestHelpers.Aggregates.ValueObjects; -using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; using NUnit.Framework; +using Shouldly; namespace EventFlow.RabbitMQ.Tests.Integration { @@ -83,14 +83,14 @@ public async Task Scenario() await commandBus.PublishAsync(new ThingyPingCommand(ThingyId.New, pingId), _timeout.Token).ConfigureAwait(false); var rabbitMqMessage = consumer.GetMessages(TimeSpan.FromMinutes(1)).Single(); - rabbitMqMessage.Exchange.Value.Should().Be(exchange.Value); - rabbitMqMessage.RoutingKey.Value.Should().Be("eventflow.domainevent.thingy.thingy-ping.1"); + rabbitMqMessage.Exchange.Value.ShouldBe(exchange.Value); + rabbitMqMessage.RoutingKey.Value.ShouldBe("eventflow.domainevent.thingy.thingy-ping.1"); var pingEvent = (IDomainEvent)eventJsonSerializer.Deserialize( rabbitMqMessage.Message, new Metadata(rabbitMqMessage.Headers)); - pingEvent.AggregateEvent.PingId.Should().Be(pingId); + pingEvent.AggregateEvent.PingId.ShouldBe(pingId); } } @@ -116,8 +116,8 @@ public async Task PublisherPerformance() await Task.WhenAll(tasks).ConfigureAwait(false); var rabbitMqMessages = consumer.GetMessages(TimeSpan.FromMinutes(1), totalMessageCount); - rabbitMqMessages.Should().HaveCount(totalMessageCount); - exceptions.Should().BeEmpty(); + rabbitMqMessages.Count.ShouldBe(totalMessageCount); + exceptions.ShouldBeEmpty(); } } diff --git a/Source/EventFlow.TestHelpers/LoggerMock.cs b/Source/EventFlow.TestHelpers/LoggerMock.cs index bd99c161d..2bbc873a1 100644 --- a/Source/EventFlow.TestHelpers/LoggerMock.cs +++ b/Source/EventFlow.TestHelpers/LoggerMock.cs @@ -25,8 +25,8 @@ using System.Collections.Generic; using System.Linq; using EventFlow.Core; -using FluentAssertions; using Microsoft.Extensions.Logging; +using Shouldly; namespace EventFlow.TestHelpers { @@ -79,7 +79,7 @@ public void VerifyNoProblems() var messages = Logs(LogLevel.Critical, LogLevel.Error) .Select(m => m.Message) .ToList(); - messages.Should().BeEmpty(string.Join(", ", messages)); + messages.ShouldBeEmpty(string.Join(", ", messages)); } public void VerifyProblemLogged(params Exception[] expectedExceptions) @@ -87,7 +87,14 @@ public void VerifyProblemLogged(params Exception[] expectedExceptions) var exceptions = Logs(LogLevel.Error, LogLevel.Critical) .Select(m => m.Exception) .ToList(); - exceptions.Should().AllBeEquivalentTo(expectedExceptions); + + exceptions.Count.ShouldBe(expectedExceptions.Length); + + foreach (var exception in exceptions) + { + exception.ShouldNotBeNull(); + expectedExceptions.ShouldContain(ex => ex.GetType() == exception.GetType() && ex.Message == exception.Message); + } } public IReadOnlyCollection Logs(params LogLevel[] logLevels) diff --git a/Source/EventFlow.TestHelpers/Suites/TestSuiteForEventStore.cs b/Source/EventFlow.TestHelpers/Suites/TestSuiteForEventStore.cs index 73e7d43fe..ba271e134 100644 --- a/Source/EventFlow.TestHelpers/Suites/TestSuiteForEventStore.cs +++ b/Source/EventFlow.TestHelpers/Suites/TestSuiteForEventStore.cs @@ -37,10 +37,10 @@ using EventFlow.TestHelpers.Aggregates.Events; using EventFlow.TestHelpers.Aggregates.ValueObjects; using EventFlow.TestHelpers.Extensions; -using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using Moq; using NUnit.Framework; +using Shouldly; namespace EventFlow.TestHelpers.Suites { @@ -56,8 +56,8 @@ public async Task NewAggregateCanBeLoaded() var testAggregate = await LoadAggregateAsync(ThingyId.New); // Assert - testAggregate.Should().NotBeNull(); - testAggregate.IsNew.Should().BeTrue(); + testAggregate.ShouldNotBeNull(); + testAggregate.IsNew.ShouldBeTrue(); } [Test] @@ -72,16 +72,16 @@ public async Task EventsCanBeStored() var domainEvents = await testAggregate.CommitAsync(EventStore, SnapshotStore, SourceId.New, CancellationToken.None); // Assert - domainEvents.Count.Should().Be(1); + domainEvents.Count.ShouldBe(1); var pingEvent = domainEvents.Single() as IDomainEvent; - pingEvent.Should().NotBeNull(); - pingEvent.AggregateIdentity.Should().Be(id); - pingEvent.AggregateSequenceNumber.Should().Be(1); - pingEvent.AggregateType.Should().Be(typeof(ThingyAggregate)); - pingEvent.EventType.Should().Be(typeof(ThingyPingEvent)); - pingEvent.Timestamp.Should().NotBe(default); - pingEvent.Metadata.Count.Should().BeGreaterThan(0); - pingEvent.Metadata.SourceId.IsNone().Should().BeFalse(); + pingEvent.ShouldNotBeNull(); + pingEvent.AggregateIdentity.ShouldBe(id); + pingEvent.AggregateSequenceNumber.ShouldBe(1); + pingEvent.AggregateType.ShouldBe(typeof(ThingyAggregate)); + pingEvent.EventType.ShouldBe(typeof(ThingyPingEvent)); + pingEvent.Timestamp.ShouldNotBe(default); + pingEvent.Metadata.Count.ShouldBeGreaterThan(0); + pingEvent.Metadata.SourceId.IsNone().ShouldBeFalse(); } [Test] @@ -97,10 +97,10 @@ public async Task AggregatesCanBeLoaded() var loadedTestAggregate = await LoadAggregateAsync(id); // Assert - loadedTestAggregate.Should().NotBeNull(); - loadedTestAggregate.IsNew.Should().BeFalse(); - loadedTestAggregate.Version.Should().Be(1); - loadedTestAggregate.PingsReceived.Count.Should().Be(1); + loadedTestAggregate.ShouldNotBeNull(); + loadedTestAggregate.IsNew.ShouldBeFalse(); + loadedTestAggregate.Version.ShouldBe(1); + loadedTestAggregate.PingsReceived.Count.ShouldBe(1); } [Test] @@ -118,7 +118,7 @@ public async Task EventsCanContainUnicodeCharacters() var loadedTestAggregate = await LoadAggregateAsync(id); // Assert - loadedTestAggregate.Messages.Single().Message.Should().Be("😉"); + loadedTestAggregate.Messages.Single().Message.ShouldBe("😉"); } [Test] @@ -140,8 +140,8 @@ public async Task AggregateEventStreamsAreSeperate() aggregate2 = await LoadAggregateAsync(id2); // Assert - aggregate1.Version.Should().Be(1); - aggregate2.Version.Should().Be(2); + aggregate1.Version.ShouldBe(1); + aggregate2.Version.ShouldBe(2); } [Test] @@ -167,7 +167,7 @@ public async Task DomainEventCanBeLoaded() CancellationToken.None); // Assert - domainEvents.DomainEvents.Count.Should().BeGreaterOrEqualTo(2); + domainEvents.DomainEvents.Count.ShouldBeGreaterThanOrEqualTo(2); } [Test] @@ -181,10 +181,10 @@ public async Task LoadingOfEventsCanStartLater() var domainEvents = await EventStore.LoadEventsAsync(id, 3, CancellationToken.None); // Assert - domainEvents.Should().HaveCount(3); - domainEvents.ElementAt(0).AggregateSequenceNumber.Should().Be(3); - domainEvents.ElementAt(1).AggregateSequenceNumber.Should().Be(4); - domainEvents.ElementAt(2).AggregateSequenceNumber.Should().Be(5); + domainEvents.Count.ShouldBe(3); + domainEvents.ElementAt(0).AggregateSequenceNumber.ShouldBe(3); + domainEvents.ElementAt(1).AggregateSequenceNumber.ShouldBe(4); + domainEvents.ElementAt(2).AggregateSequenceNumber.ShouldBe(5); } [Test] @@ -198,9 +198,9 @@ public async Task LoadingOfEventsCanStartLaterAndStopEarlier() var domainEvents = await EventStore.LoadEventsAsync(id, 3, 4, CancellationToken.None); // Assert - domainEvents.Should().HaveCount(2); - domainEvents.ElementAt(0).AggregateSequenceNumber.Should().Be(3); - domainEvents.ElementAt(1).AggregateSequenceNumber.Should().Be(4); + domainEvents.Count.ShouldBe(2); + domainEvents.ElementAt(0).AggregateSequenceNumber.ShouldBe(3); + domainEvents.ElementAt(1).AggregateSequenceNumber.ShouldBe(4); } [Test] @@ -219,7 +219,7 @@ public async Task AggregateCanHaveMultipleCommits() aggregate = await LoadAggregateAsync(id); // Assert - aggregate.PingsReceived.Count.Should().Be(2); + aggregate.PingsReceived.Count.ShouldBe(2); } [Test] @@ -237,9 +237,9 @@ await CommandBus.PublishAsync( // Assert var aggregate = await LoadAggregateAsync(id); - aggregate.UpgradableEventV1Received.Should().Be(0); - aggregate.UpgradableEventV2Received.Should().Be(0); - aggregate.UpgradableEventV3Received.Should().Be(version1 + version2 + version3); + aggregate.UpgradableEventV1Received.ShouldBe(0); + aggregate.UpgradableEventV2Received.ShouldBe(0); + aggregate.UpgradableEventV3Received.ShouldBe(version1 + version2 + version3); } [Test] @@ -262,8 +262,8 @@ public async Task AggregateEventStreamsCanBeDeleted() // Assert aggregate1 = await LoadAggregateAsync(id1); aggregate2 = await LoadAggregateAsync(id2); - aggregate1.Version.Should().Be(1); - aggregate2.Version.Should().Be(0); + aggregate1.Version.ShouldBe(1); + aggregate2.Version.ShouldBe(0); } [Test] @@ -294,7 +294,7 @@ public async Task NextPositionIsIdOfNextEvent() CancellationToken.None); // Assert - domainEvents.NextGlobalPosition.Value.Should().NotBe(string.Empty); + domainEvents.NextGlobalPosition.Value.ShouldNotBe(string.Empty); } [Test] @@ -317,8 +317,8 @@ public async Task LoadingFirstPageShouldLoadCorrectEvents() CancellationToken.None); // Assert - domainEvents.DomainEvents.OfType>().Should().Contain(e => e.AggregateEvent.PingId == pingIds[0]); - domainEvents.DomainEvents.OfType>().Should().Contain(e => e.AggregateEvent.PingId == pingIds[1]); + domainEvents.DomainEvents.OfType>().ShouldContain(e => e.AggregateEvent.PingId == pingIds[0]); + domainEvents.DomainEvents.OfType>().ShouldContain(e => e.AggregateEvent.PingId == pingIds[1]); } [Test] @@ -353,13 +353,13 @@ public async Task AggregatesCanUpdatedAfterOptimisticConcurrency() // Act aggregate1 = await LoadAggregateAsync(id); - aggregate1.PingsReceived.Single().Should().Be(pingId1); + aggregate1.PingsReceived.Single().ShouldBe(pingId1); aggregate1.Ping(pingId2); await aggregate1.CommitAsync(EventStore, SnapshotStore, SourceId.New, CancellationToken.None); // Assert aggregate1 = await LoadAggregateAsync(id); - aggregate1.PingsReceived.Should().BeEquivalentTo(new[] {pingId1, pingId2}); + aggregate1.PingsReceived.ShouldBeEquivalentTo(new[] {pingId1, pingId2}); } [Test] @@ -388,7 +388,7 @@ await commandBus.PublishAsync( // Assert var aggregate = await LoadAggregateAsync(id); - aggregate.PingsReceived.Should().BeEquivalentTo(new []{pingId1, pingId2}); + aggregate.PingsReceived.ShouldBeEquivalentTo(new []{pingId1, pingId2}); } [Test] @@ -404,8 +404,8 @@ await CommandBus.PublishAsync( ; // Assert - PublishedDomainEvents.Count.Should().Be(10); - PublishedDomainEvents.Select(d => d.AggregateSequenceNumber).Should().BeEquivalentTo(Enumerable.Range(1, 10)); + PublishedDomainEvents.Count.ShouldBe(10); + PublishedDomainEvents.Select(d => d.AggregateSequenceNumber).ShouldBeEquivalentTo(Enumerable.Range(1, 10)); } [Test] @@ -425,8 +425,8 @@ await CommandBus.PublishAsync( ; // Assert - PublishedDomainEvents.Count.Should().Be(10); - PublishedDomainEvents.Select(d => d.AggregateSequenceNumber).Should().BeEquivalentTo(Enumerable.Range(11, 10)); + PublishedDomainEvents.Count.ShouldBe(10); + PublishedDomainEvents.Select(d => d.AggregateSequenceNumber).ShouldBeEquivalentTo(Enumerable.Range(11, 10)); } [Test] @@ -447,18 +447,20 @@ public virtual async Task LoadAllEventsAsyncFindsEventsAfterLargeGaps() var idsWithGap = ids.Where(i => !removedIds.Contains(i)); foreach (var id in removedIds) { - await EventPersistence.DeleteEventsAsync(id, CancellationToken.None) - ; + await EventPersistence.DeleteEventsAsync(id, CancellationToken.None); } // Act var result = await EventStore - .LoadAllEventsAsync(GlobalPosition.Start, 5, new EventUpgradeContext(), CancellationToken.None) - ; + .LoadAllEventsAsync(GlobalPosition.Start, 5, new EventUpgradeContext(), CancellationToken.None); // Assert - var domainEventIds = result.DomainEvents.Select(d => d.GetIdentity()); - domainEventIds.Should().Contain(idsWithGap); + var domainEventIds = result.DomainEvents.Select(d => d.GetIdentity()).ToList(); + + foreach (var id in idsWithGap) + { + domainEventIds.ShouldContain(id); + } } [SetUp] @@ -498,7 +500,7 @@ private static async Task ThrowsExceptionAsync(Func action) } } - wasCorrectException.Should().BeTrue("Action was expected to throw exception {0}", typeof(TException).PrettyPrint()); + wasCorrectException.ShouldBeTrue($"Action was expected to throw exception {typeof(TException).PrettyPrint()}"); } } } diff --git a/Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs b/Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs index 87844eeca..9d0d8c813 100644 --- a/Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs +++ b/Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs @@ -36,10 +36,10 @@ using AutoFixture; using EventFlow.Extensions; using EventFlow.TestHelpers.Aggregates.Events; -using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NUnit.Framework; +using Shouldly; using EventId = EventFlow.Aggregates.EventId; namespace EventFlow.TestHelpers.Suites @@ -56,7 +56,7 @@ public async Task NonExistingReadModelReturnsNull() var readModel = await QueryProcessor.ProcessAsync(new ThingyGetQuery(id)).ConfigureAwait(false); // Assert - readModel.Should().BeNull(); + readModel.ShouldBeNull(); } [Test] @@ -70,8 +70,8 @@ public async Task ReadModelReceivesEvent() var readModel = await QueryProcessor.ProcessAsync(new ThingyGetQuery(id)).ConfigureAwait(false); // Assert - readModel.Should().NotBeNull(); - readModel.PingsReceived.Should().Be(5); + readModel.ShouldNotBeNull(); + readModel.PingsReceived.ShouldBe(5); } [Test] @@ -84,7 +84,7 @@ public async Task InitialReadModelVersionIsNull() var version = await QueryProcessor.ProcessAsync(new ThingyGetVersionQuery(thingyId)).ConfigureAwait(false); // Assert - version.Should().NotHaveValue(); + version.ShouldBeNull(); } [Test] @@ -99,7 +99,7 @@ public async Task ReadModelVersionShouldMatchAggregate() var version = await QueryProcessor.ProcessAsync(new ThingyGetVersionQuery(thingyId)).ConfigureAwait(false); // Assert - version.Should().Be((long)version); + version.ShouldBe((long)version); } [Test] @@ -115,8 +115,8 @@ public async Task CanStoreMultipleMessages() var returnedThingyMessages = await QueryProcessor.ProcessAsync(new ThingyGetMessagesQuery(thingyId)).ConfigureAwait(false); // Assert - returnedThingyMessages.Should().HaveCount(thingyMessages.Count); - returnedThingyMessages.Should().BeEquivalentTo(thingyMessages); + returnedThingyMessages.Count.ShouldBe(thingyMessages.Count); + returnedThingyMessages.ShouldBeEquivalentTo(thingyMessages); } [Test] @@ -137,8 +137,8 @@ await CommandBus.PublishAsync(new ThingyImportCommand( var thingy = await QueryProcessor.ProcessAsync(new ThingyGetQuery(thingyId)).ConfigureAwait(false); // Assert - thingy.PingsReceived.Should().Be(pingIds.Count); - returnedThingyMessages.Should().BeEquivalentTo(thingyMessages); + thingy.PingsReceived.ShouldBe(pingIds.Count); + returnedThingyMessages.ShouldBeEquivalentTo(thingyMessages); } [Test] @@ -153,7 +153,7 @@ public async Task PurgeRemovesReadModels() var readModel = await QueryProcessor.ProcessAsync(new ThingyGetQuery(id)).ConfigureAwait(false); // Assert - readModel.Should().BeNull(); + readModel.ShouldBeNull(); } [Test] @@ -166,8 +166,8 @@ public async Task DeleteRemovesSpecificReadModel() await PublishPingCommandAsync(id2).ConfigureAwait(false); var readModel1 = await QueryProcessor.ProcessAsync(new ThingyGetQuery(id1)).ConfigureAwait(false); var readModel2 = await QueryProcessor.ProcessAsync(new ThingyGetQuery(id2)).ConfigureAwait(false); - readModel1.Should().NotBeNull(); - readModel2.Should().NotBeNull(); + readModel1.ShouldNotBeNull(); + readModel2.ShouldNotBeNull(); // Act await ReadModelPopulator.DeleteAsync( @@ -179,8 +179,8 @@ await ReadModelPopulator.DeleteAsync( // Assert readModel1 = await QueryProcessor.ProcessAsync(new ThingyGetQuery(id1)).ConfigureAwait(false); readModel2 = await QueryProcessor.ProcessAsync(new ThingyGetQuery(id2)).ConfigureAwait(false); - readModel1.Should().BeNull(); - readModel2.Should().NotBeNull(); + readModel1.ShouldBeNull(); + readModel2.ShouldNotBeNull(); } [Test] @@ -200,8 +200,8 @@ public async Task RePopulateHandlesManyAggregates() var readModel1 = await QueryProcessor.ProcessAsync(new ThingyGetQuery(id1)).ConfigureAwait(false); var readModel2 = await QueryProcessor.ProcessAsync(new ThingyGetQuery(id2)).ConfigureAwait(false); - readModel1.PingsReceived.Should().Be(3); - readModel2.PingsReceived.Should().Be(5); + readModel1.PingsReceived.ShouldBe(3); + readModel2.PingsReceived.ShouldBe(5); } [Test] @@ -220,7 +220,7 @@ public async Task RePopulateHandlesDeletedAggregate() // Assert var readModel = await QueryProcessor.ProcessAsync(new ThingyGetQuery(id2)).ConfigureAwait(false); - readModel.PingsReceived.Should().Be(5); + readModel.PingsReceived.ShouldBe(5); } [Test] @@ -236,8 +236,8 @@ public async Task PopulateCreatesReadModels() var readModel = await QueryProcessor.ProcessAsync(new ThingyGetQuery(id)).ConfigureAwait(false); // Assert - readModel.Should().NotBeNull(); - readModel.PingsReceived.Should().Be(2); + readModel.ShouldNotBeNull(); + readModel.PingsReceived.ShouldBe(2); } [Test] @@ -257,7 +257,7 @@ await PublishPingCommandAsync(id).ConfigureAwait(false) // Assert var readModel = await QueryProcessor.ProcessAsync(new ThingyGetQuery(id)).ConfigureAwait(false); - readModel.PingsReceived.Should().Be(pingIds.Count); + readModel.PingsReceived.ShouldBe(pingIds.Count); } } @@ -290,7 +290,7 @@ public virtual async Task OptimisticConcurrencyCheck() // Assert var readModel = await QueryProcessor.ProcessAsync(new ThingyGetQuery(id), cts.Token).ConfigureAwait(false); - readModel.PingsReceived.Should().Be(3); + readModel.PingsReceived.ShouldBe(3); } } @@ -304,8 +304,8 @@ public async Task MarkingForDeletionRemovesSpecificReadModel() await PublishPingCommandAsync(id2).ConfigureAwait(false); var readModel1 = await QueryProcessor.ProcessAsync(new ThingyGetQuery(id1)).ConfigureAwait(false); var readModel2 = await QueryProcessor.ProcessAsync(new ThingyGetQuery(id2)).ConfigureAwait(false); - readModel1.Should().NotBeNull(); - readModel2.Should().NotBeNull(); + readModel1.ShouldNotBeNull(); + readModel2.ShouldNotBeNull(); // Act await CommandBus.PublishAsync(new ThingyDeleteCommand(id1), CancellationToken.None); @@ -313,8 +313,8 @@ public async Task MarkingForDeletionRemovesSpecificReadModel() // Assert readModel1 = await QueryProcessor.ProcessAsync(new ThingyGetQuery(id1)).ConfigureAwait(false); readModel2 = await QueryProcessor.ProcessAsync(new ThingyGetQuery(id2)).ConfigureAwait(false); - readModel1.Should().BeNull(); - readModel2.Should().NotBeNull(); + readModel1.ShouldBeNull(); + readModel2.ShouldNotBeNull(); } [Test] @@ -330,8 +330,8 @@ public async Task CanStoreMessageHistory() var returnedThingyMessages = await QueryProcessor.ProcessAsync(new ThingyGetMessagesQuery(thingyId)).ConfigureAwait(false); // Assert - returnedThingyMessages.Should().HaveCount(thingyMessages.Count); - returnedThingyMessages.Should().BeEquivalentTo(thingyMessages); + returnedThingyMessages.Count.ShouldBe(thingyMessages.Count); + returnedThingyMessages.ShouldBeEquivalentTo(thingyMessages); } [TestCase(true, true)] @@ -372,9 +372,9 @@ await readStoreManager.UpdateReadStoresAsync( // Assert var returnedThingyMessages = await QueryProcessor.ProcessAsync(new ThingyGetMessagesQuery(thingyId)).ConfigureAwait(false); - returnedThingyMessages.Should().HaveCount(1); + returnedThingyMessages.Count.ShouldBe(1); var readModel = await QueryProcessor.ProcessAsync(new ThingyGetQuery(thingyId)).ConfigureAwait(false); - readModel.PingsReceived.Should().Be(1); + readModel.PingsReceived.ShouldBe(1); } private class WaitState diff --git a/Source/EventFlow.TestHelpers/Suites/TestSuiteForScheduler.cs b/Source/EventFlow.TestHelpers/Suites/TestSuiteForScheduler.cs index 1b988ef71..f58998abc 100644 --- a/Source/EventFlow.TestHelpers/Suites/TestSuiteForScheduler.cs +++ b/Source/EventFlow.TestHelpers/Suites/TestSuiteForScheduler.cs @@ -33,10 +33,9 @@ using EventFlow.TestHelpers.Aggregates.Commands; using EventFlow.TestHelpers.Aggregates.Events; using EventFlow.TestHelpers.Aggregates.ValueObjects; -using FluentAssertions; -using FluentAssertions.Common; using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; +using Shouldly; namespace EventFlow.TestHelpers.Suites { @@ -81,7 +80,7 @@ public async Task AsynchronousSubscribesGetInvoked() // Assert var receivedPingId = await Task.Run(() => _testAsynchronousSubscriber.PingIds.Take(), cts.Token).ConfigureAwait(false); - receivedPingId.Should().IsSameOrEqualTo(pingId); + receivedPingId.ShouldBeSameAs(pingId); } } diff --git a/Source/EventFlow.TestHelpers/Suites/TestSuiteForSnapshotStore.cs b/Source/EventFlow.TestHelpers/Suites/TestSuiteForSnapshotStore.cs index 91e1d94fb..195560f04 100644 --- a/Source/EventFlow.TestHelpers/Suites/TestSuiteForSnapshotStore.cs +++ b/Source/EventFlow.TestHelpers/Suites/TestSuiteForSnapshotStore.cs @@ -32,9 +32,9 @@ using EventFlow.TestHelpers.Aggregates.Commands; using EventFlow.TestHelpers.Aggregates.Snapshots; using EventFlow.TestHelpers.Aggregates.ValueObjects; -using FluentAssertions; using Newtonsoft.Json; using NUnit.Framework; +using Shouldly; namespace EventFlow.TestHelpers.Suites { @@ -51,7 +51,7 @@ public async Task GetSnapshotAsync_NoneExistingSnapshotReturnsNull() .ConfigureAwait(false); // Assert - committedSnapshot.Should().BeNull(); + committedSnapshot.ShouldBeNull(); } [Test] @@ -89,7 +89,7 @@ public async Task NoSnapshotsAreCreatedWhenCommittingFewEvents() var thingySnapshot = await LoadSnapshotAsync(thingyId).ConfigureAwait(false); // Assert - thingySnapshot.Should().BeNull(); + thingySnapshot.ShouldBeNull(); } [Test] @@ -104,8 +104,8 @@ public async Task SnapshotIsCreatedWhenCommittingManyEvents() var thingySnapshot = await LoadSnapshotAsync(thingyId).ConfigureAwait(false); // Assert - thingySnapshot.Should().NotBeNull(); - thingySnapshot.PingsReceived.Count.Should().Be(ThingyAggregate.SnapshotEveryVersion); + thingySnapshot.ShouldNotBeNull(); + thingySnapshot.PingsReceived.Count.ShouldBe(ThingyAggregate.SnapshotEveryVersion); } [TestCase(1)] @@ -121,7 +121,7 @@ public async Task DuplicateOperationExceptionIsThrown(int index) // Validate var thingySnapshot = await LoadSnapshotAsync(thingyId).ConfigureAwait(false); - thingySnapshot.PingsReceived.Should().HaveCount(ThingyAggregate.SnapshotEveryVersion); + thingySnapshot.PingsReceived.Count.ShouldBe(ThingyAggregate.SnapshotEveryVersion); // Act var command = new ThingyPingCommand(thingyId, sourceIds[index], PingId.New); @@ -140,8 +140,8 @@ public async Task LoadedAggregateHasCorrectVersionsWhenSnapshotIsApplied() var thingyAggregate = await LoadAggregateAsync(thingyId).ConfigureAwait(false); // Assert - thingyAggregate.Version.Should().Be(pingsSent); - thingyAggregate.SnapshotVersion.GetValueOrDefault().Should().Be(ThingyAggregate.SnapshotEveryVersion); + thingyAggregate.Version.ShouldBe(pingsSent); + thingyAggregate.SnapshotVersion.GetValueOrDefault().ShouldBe(ThingyAggregate.SnapshotEveryVersion); } [Test] @@ -151,9 +151,9 @@ public async Task LoadingNoneExistingSnapshottedAggregateReturnsVersionZeroAndNu var thingyAggregate = await LoadAggregateAsync(A()).ConfigureAwait(false); // Assert - thingyAggregate.Should().NotBeNull(); - thingyAggregate.Version.Should().Be(0); - thingyAggregate.SnapshotVersion.Should().NotHaveValue(); + thingyAggregate.ShouldNotBeNull(); + thingyAggregate.Version.ShouldBe(0); + thingyAggregate.SnapshotVersion.ShouldBeNull(); } [Test] @@ -173,12 +173,12 @@ public async Task OldSnapshotsAreUpgradedToLatestVersionAndHaveCorrectMetadata() .ConfigureAwait(false); // Assert - snapshotContainer.Snapshot.Should().BeOfType(); - snapshotContainer.Metadata.AggregateId.Should().Be(thingyId.Value); - snapshotContainer.Metadata.AggregateName.Should().Be("ThingyAggregate"); - snapshotContainer.Metadata.AggregateSequenceNumber.Should().Be(expectedVersion); - snapshotContainer.Metadata.SnapshotName.Should().Be("thingy"); - snapshotContainer.Metadata.SnapshotVersion.Should().Be(1); + snapshotContainer.Snapshot.ShouldBeOfType(); + snapshotContainer.Metadata.AggregateId.ShouldBe(thingyId.Value); + snapshotContainer.Metadata.AggregateName.ShouldBe("ThingyAggregate"); + snapshotContainer.Metadata.AggregateSequenceNumber.ShouldBe(expectedVersion); + snapshotContainer.Metadata.SnapshotName.ShouldBe("thingy"); + snapshotContainer.Metadata.SnapshotVersion.ShouldBe(1); } [Test] @@ -221,9 +221,10 @@ public async Task OldSnapshotsAreUpgradedToLatestVersionAndAppliedToAggregate() var thingyAggregate = await LoadAggregateAsync(thingyId).ConfigureAwait(false); // Assert - thingyAggregate.Version.Should().Be(expectedVersion); - thingyAggregate.PingsReceived.Should().BeEquivalentTo(pingIds); - thingyAggregate.SnapshotVersions.Should().Contain(new[] {ThingySnapshotVersion.Version1, ThingySnapshotVersion.Version2}); + thingyAggregate.Version.ShouldBe(expectedVersion); + thingyAggregate.PingsReceived.ShouldBe(pingIds, ignoreOrder: true); + thingyAggregate.SnapshotVersions.ShouldContain(ThingySnapshotVersion.Version1); + thingyAggregate.SnapshotVersions.ShouldContain(ThingySnapshotVersion.Version2); } protected override IEventFlowOptions Options(IEventFlowOptions eventFlowOptions) diff --git a/Source/EventFlow.Tests/LicenseHeaderTests.cs b/Source/EventFlow.Tests/LicenseHeaderTests.cs index b37536771..b1dc8a7ad 100644 --- a/Source/EventFlow.Tests/LicenseHeaderTests.cs +++ b/Source/EventFlow.Tests/LicenseHeaderTests.cs @@ -30,7 +30,6 @@ using NUnit.Framework; using Shouldly; -// ReSharper disable StringLiteralTypo // ReSharper disable StringLiteralTypo namespace EventFlow.Tests From 84556b246888fac552585b884790c5f8ec3b062e Mon Sep 17 00:00:00 2001 From: Focus Date: Sat, 14 Jun 2025 14:51:04 +0300 Subject: [PATCH 10/13] Fixed EventFlow.Tests --- Source/EventFlow.TestHelpers/LoggerMock.cs | 10 ++-------- .../Suites/TestSuiteForEventStore.cs | 8 ++++---- .../Suites/TestSuiteForScheduler.cs | 2 +- .../UnitTests/Core/CircularBufferTests.cs | 6 +++++- .../VersionedTypeDefinitionServiceTestSuite.cs | 10 ++++++++-- .../EventStores/EventDefinitionServiceTests.cs | 16 ++++++++++++++-- .../UnitTests/Snapshots/SnapshotMetadataTests.cs | 4 ++-- .../Snapshots/SnapshotUpgradeServiceTests.cs | 4 ++-- 8 files changed, 38 insertions(+), 22 deletions(-) diff --git a/Source/EventFlow.TestHelpers/LoggerMock.cs b/Source/EventFlow.TestHelpers/LoggerMock.cs index 2bbc873a1..0f66b3c5d 100644 --- a/Source/EventFlow.TestHelpers/LoggerMock.cs +++ b/Source/EventFlow.TestHelpers/LoggerMock.cs @@ -25,6 +25,7 @@ using System.Collections.Generic; using System.Linq; using EventFlow.Core; +using FluentAssertions; using Microsoft.Extensions.Logging; using Shouldly; @@ -87,14 +88,7 @@ public void VerifyProblemLogged(params Exception[] expectedExceptions) var exceptions = Logs(LogLevel.Error, LogLevel.Critical) .Select(m => m.Exception) .ToList(); - - exceptions.Count.ShouldBe(expectedExceptions.Length); - - foreach (var exception in exceptions) - { - exception.ShouldNotBeNull(); - expectedExceptions.ShouldContain(ex => ex.GetType() == exception.GetType() && ex.Message == exception.Message); - } + exceptions.Should().AllBeEquivalentTo(expectedExceptions); } public IReadOnlyCollection Logs(params LogLevel[] logLevels) diff --git a/Source/EventFlow.TestHelpers/Suites/TestSuiteForEventStore.cs b/Source/EventFlow.TestHelpers/Suites/TestSuiteForEventStore.cs index ba271e134..037449d2e 100644 --- a/Source/EventFlow.TestHelpers/Suites/TestSuiteForEventStore.cs +++ b/Source/EventFlow.TestHelpers/Suites/TestSuiteForEventStore.cs @@ -359,7 +359,7 @@ public async Task AggregatesCanUpdatedAfterOptimisticConcurrency() // Assert aggregate1 = await LoadAggregateAsync(id); - aggregate1.PingsReceived.ShouldBeEquivalentTo(new[] {pingId1, pingId2}); + aggregate1.PingsReceived.ShouldBe(new[] { pingId1, pingId2 }); } [Test] @@ -388,7 +388,7 @@ await commandBus.PublishAsync( // Assert var aggregate = await LoadAggregateAsync(id); - aggregate.PingsReceived.ShouldBeEquivalentTo(new []{pingId1, pingId2}); + aggregate.PingsReceived.ShouldBe(new[] { pingId1, pingId2 }); } [Test] @@ -405,7 +405,7 @@ await CommandBus.PublishAsync( // Assert PublishedDomainEvents.Count.ShouldBe(10); - PublishedDomainEvents.Select(d => d.AggregateSequenceNumber).ShouldBeEquivalentTo(Enumerable.Range(1, 10)); + PublishedDomainEvents.Select(d => d.AggregateSequenceNumber).ShouldBe(Enumerable.Range(1, 10)); } [Test] @@ -426,7 +426,7 @@ await CommandBus.PublishAsync( // Assert PublishedDomainEvents.Count.ShouldBe(10); - PublishedDomainEvents.Select(d => d.AggregateSequenceNumber).ShouldBeEquivalentTo(Enumerable.Range(11, 10)); + PublishedDomainEvents.Select(d => d.AggregateSequenceNumber).ShouldBe(Enumerable.Range(11, 10)); } [Test] diff --git a/Source/EventFlow.TestHelpers/Suites/TestSuiteForScheduler.cs b/Source/EventFlow.TestHelpers/Suites/TestSuiteForScheduler.cs index f58998abc..55dee81df 100644 --- a/Source/EventFlow.TestHelpers/Suites/TestSuiteForScheduler.cs +++ b/Source/EventFlow.TestHelpers/Suites/TestSuiteForScheduler.cs @@ -80,7 +80,7 @@ public async Task AsynchronousSubscribesGetInvoked() // Assert var receivedPingId = await Task.Run(() => _testAsynchronousSubscriber.PingIds.Take(), cts.Token).ConfigureAwait(false); - receivedPingId.ShouldBeSameAs(pingId); + receivedPingId.ShouldBe(pingId); } } diff --git a/Source/EventFlow.Tests/UnitTests/Core/CircularBufferTests.cs b/Source/EventFlow.Tests/UnitTests/Core/CircularBufferTests.cs index 8d52f5a5a..6527d1384 100644 --- a/Source/EventFlow.Tests/UnitTests/Core/CircularBufferTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Core/CircularBufferTests.cs @@ -50,7 +50,11 @@ public void Put(params int[] numbers) // Assert var shouldContain = numbers.Reverse().Take(capacity).ToList(); - sut.ShouldBe(shouldContain); + + foreach (var sc in shouldContain) + { + sut.ShouldContain(sc); + } } [Test] diff --git a/Source/EventFlow.Tests/UnitTests/Core/VersionedTypes/VersionedTypeDefinitionServiceTestSuite.cs b/Source/EventFlow.Tests/UnitTests/Core/VersionedTypes/VersionedTypeDefinitionServiceTestSuite.cs index 884d5291e..752f7ff66 100644 --- a/Source/EventFlow.Tests/UnitTests/Core/VersionedTypes/VersionedTypeDefinitionServiceTestSuite.cs +++ b/Source/EventFlow.Tests/UnitTests/Core/VersionedTypes/VersionedTypeDefinitionServiceTestSuite.cs @@ -200,12 +200,18 @@ public void GetAllDefinitions_WhenAllLoaded_ReturnsAll() var expectedTypes = Arrange_LoadAllTestTypes(); // Act - var result = Sut.GetAllDefinitions().Select(d => d.Type) + var result = Sut.GetAllDefinitions() + .Select(d => d.Type) .Distinct() + .OrderBy(t => t.FullName) .ToList(); // Assert - result.ShouldBeEquivalentTo(expectedTypes); + var expected = expectedTypes + .OrderBy(t => t.FullName) + .ToList(); + + result.ShouldBe(expected); } [Test] diff --git a/Source/EventFlow.Tests/UnitTests/EventStores/EventDefinitionServiceTests.cs b/Source/EventFlow.Tests/UnitTests/EventStores/EventDefinitionServiceTests.cs index ecfc1c5a8..a8e8b0e2d 100644 --- a/Source/EventFlow.Tests/UnitTests/EventStores/EventDefinitionServiceTests.cs +++ b/Source/EventFlow.Tests/UnitTests/EventStores/EventDefinitionServiceTests.cs @@ -65,9 +65,21 @@ public void GetDefinitions_OnEventWithMultipleDefinitions_ReturnsThemAll() // Assert eventDefinitions.Count.ShouldBe(3); - eventDefinitions + + var actualStrings = eventDefinitions .Select(d => $"{d.Name}-V{d.Version}") - .ShouldBeEquivalentTo(new []{"multi-names-event-V1", "MultiNamesEvent-V1", "MultiNamesEvent-V2"}); + .OrderBy(s => s) + .ToList(); + + var expectedStrings = new[] + { + "multi-names-event-V1", + "MultiNamesEvent-V1", + "MultiNamesEvent-V2" + }.OrderBy(s => s) + .ToList(); + + actualStrings.ShouldBe(expectedStrings); } [Test] diff --git a/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotMetadataTests.cs b/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotMetadataTests.cs index 82f7eafe5..55f652c00 100644 --- a/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotMetadataTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotMetadataTests.cs @@ -57,7 +57,7 @@ public void DeserializesCorrectly() snapshotMetadata.AggregateSequenceNumber.ShouldBe(42); snapshotMetadata.SnapshotName.ShouldBe("thingy"); snapshotMetadata.SnapshotVersion.ShouldBe(84); - snapshotMetadata.PreviousSourceIds.Select(s => s.Value).ShouldBeEquivalentTo("cool", "magic"); + snapshotMetadata.PreviousSourceIds.Select(s => s.Value).ShouldBe(new [] { "cool", "magic" }); } [Test] @@ -88,7 +88,7 @@ public void GettersAndSettersWork() deserializedSnapshotMetadata.AggregateSequenceNumber.ShouldBe(42); deserializedSnapshotMetadata.SnapshotName.ShouldBe("thingy"); deserializedSnapshotMetadata.SnapshotVersion.ShouldBe(84); - deserializedSnapshotMetadata.PreviousSourceIds.Select(s => s.Value).ShouldBeEquivalentTo("cool", "magic"); + deserializedSnapshotMetadata.PreviousSourceIds.Select(s => s.Value).ShouldBe(new [] { "cool", "magic" }); } [Test] diff --git a/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotUpgradeServiceTests.cs b/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotUpgradeServiceTests.cs index f13f102dc..713100eee 100644 --- a/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotUpgradeServiceTests.cs +++ b/Source/EventFlow.Tests/UnitTests/Snapshots/SnapshotUpgradeServiceTests.cs @@ -66,8 +66,8 @@ public async Task UpgradeAsync_UpgradesSnapshot() // Assert snapshot.ShouldBeOfType(); var thingySnapshot = (ThingySnapshot) snapshot; - thingySnapshot.PingsReceived.ShouldBeEquivalentTo(pingIds); - thingySnapshot.PreviousVersions.ShouldBeEquivalentTo(new[] {ThingySnapshotVersion.Version1, ThingySnapshotVersion.Version2}); + thingySnapshot.PingsReceived.ShouldBe(pingIds, ignoreOrder: true); + thingySnapshot.PreviousVersions.ShouldBe(new[] { ThingySnapshotVersion.Version1, ThingySnapshotVersion.Version2 }, ignoreOrder: true); } private void Arrange_All_Upgraders() From 247ff28a6804038eb1b771ae1199bf79eda631e4 Mon Sep 17 00:00:00 2001 From: Focus Date: Sat, 14 Jun 2025 15:00:39 +0300 Subject: [PATCH 11/13] Fixed Extensions Tests --- .../Integration/HangfireJobSchedulerTests.cs | 2 +- .../Suites/TestSuiteForEventStore.cs | 8 ++++---- .../Suites/TestSuiteForReadModelStore.cs | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/EventFlow.Hangfire.Tests/Integration/HangfireJobSchedulerTests.cs b/Source/EventFlow.Hangfire.Tests/Integration/HangfireJobSchedulerTests.cs index abbbf60b7..3f3a1ee45 100644 --- a/Source/EventFlow.Hangfire.Tests/Integration/HangfireJobSchedulerTests.cs +++ b/Source/EventFlow.Hangfire.Tests/Integration/HangfireJobSchedulerTests.cs @@ -112,7 +112,7 @@ public async Task AsynchronousSubscribesGetInvoked() // Assert var receivedPingId = await Task.Run(() => _testAsynchronousSubscriber.PingIds.Take(), cts.Token).ConfigureAwait(false); - receivedPingId.ShouldBeSameAs(pingId); + receivedPingId.ShouldBe(pingId); } [Test] diff --git a/Source/EventFlow.TestHelpers/Suites/TestSuiteForEventStore.cs b/Source/EventFlow.TestHelpers/Suites/TestSuiteForEventStore.cs index 037449d2e..db04442de 100644 --- a/Source/EventFlow.TestHelpers/Suites/TestSuiteForEventStore.cs +++ b/Source/EventFlow.TestHelpers/Suites/TestSuiteForEventStore.cs @@ -359,7 +359,7 @@ public async Task AggregatesCanUpdatedAfterOptimisticConcurrency() // Assert aggregate1 = await LoadAggregateAsync(id); - aggregate1.PingsReceived.ShouldBe(new[] { pingId1, pingId2 }); + aggregate1.PingsReceived.SequenceEqual(new[] { pingId1, pingId2 }).ShouldBeTrue(); } [Test] @@ -388,7 +388,7 @@ await commandBus.PublishAsync( // Assert var aggregate = await LoadAggregateAsync(id); - aggregate.PingsReceived.ShouldBe(new[] { pingId1, pingId2 }); + aggregate.PingsReceived.SequenceEqual(new[] { pingId1, pingId2 }).ShouldBeTrue(); } [Test] @@ -405,7 +405,7 @@ await CommandBus.PublishAsync( // Assert PublishedDomainEvents.Count.ShouldBe(10); - PublishedDomainEvents.Select(d => d.AggregateSequenceNumber).ShouldBe(Enumerable.Range(1, 10)); + PublishedDomainEvents.Select(d => d.AggregateSequenceNumber).SequenceEqual(Enumerable.Range(1, 10)).ShouldBeTrue(); } [Test] @@ -426,7 +426,7 @@ await CommandBus.PublishAsync( // Assert PublishedDomainEvents.Count.ShouldBe(10); - PublishedDomainEvents.Select(d => d.AggregateSequenceNumber).ShouldBe(Enumerable.Range(11, 10)); + PublishedDomainEvents.Select(d => d.AggregateSequenceNumber).SequenceEqual(Enumerable.Range(11, 10)).ShouldBeTrue(); } [Test] diff --git a/Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs b/Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs index 9d0d8c813..6f0fe40a7 100644 --- a/Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs +++ b/Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs @@ -116,7 +116,7 @@ public async Task CanStoreMultipleMessages() // Assert returnedThingyMessages.Count.ShouldBe(thingyMessages.Count); - returnedThingyMessages.ShouldBeEquivalentTo(thingyMessages); + returnedThingyMessages.ShouldBe(thingyMessages, ignoreOrder: true); } [Test] @@ -138,7 +138,7 @@ await CommandBus.PublishAsync(new ThingyImportCommand( // Assert thingy.PingsReceived.ShouldBe(pingIds.Count); - returnedThingyMessages.ShouldBeEquivalentTo(thingyMessages); + returnedThingyMessages.SequenceEqual(thingyMessages).ShouldBeTrue(); } [Test] @@ -331,7 +331,7 @@ public async Task CanStoreMessageHistory() // Assert returnedThingyMessages.Count.ShouldBe(thingyMessages.Count); - returnedThingyMessages.ShouldBeEquivalentTo(thingyMessages); + returnedThingyMessages.SequenceEqual(thingyMessages).ShouldBeTrue(); } [TestCase(true, true)] From 9247ce084b1cccf5de4f8efb6863f4ff373f7875 Mon Sep 17 00:00:00 2001 From: Focus Date: Sat, 14 Jun 2025 15:42:13 +0300 Subject: [PATCH 12/13] Fix 2 --- .../MsSql/EfMsSqlReadStoreIncludeTests.cs | 2 +- .../Suites/TestSuiteForReadModelStore.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/EventFlow.EntityFramework.Tests/MsSql/EfMsSqlReadStoreIncludeTests.cs b/Source/EventFlow.EntityFramework.Tests/MsSql/EfMsSqlReadStoreIncludeTests.cs index 01ffeb90d..9f7062eeb 100644 --- a/Source/EventFlow.EntityFramework.Tests/MsSql/EfMsSqlReadStoreIncludeTests.cs +++ b/Source/EventFlow.EntityFramework.Tests/MsSql/EfMsSqlReadStoreIncludeTests.cs @@ -82,7 +82,7 @@ await CommandBus // Assert readModel.ShouldNotBeNull(); readModel.Name.ShouldBe("Bob"); - readModel.Addresses.ShouldBeNull(); + readModel.Addresses.ShouldBeEmpty(); } [Test] diff --git a/Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs b/Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs index 6f0fe40a7..e7fee737a 100644 --- a/Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs +++ b/Source/EventFlow.TestHelpers/Suites/TestSuiteForReadModelStore.cs @@ -138,7 +138,7 @@ await CommandBus.PublishAsync(new ThingyImportCommand( // Assert thingy.PingsReceived.ShouldBe(pingIds.Count); - returnedThingyMessages.SequenceEqual(thingyMessages).ShouldBeTrue(); + returnedThingyMessages.ShouldBe(thingyMessages, ignoreOrder: true); } [Test] @@ -331,7 +331,7 @@ public async Task CanStoreMessageHistory() // Assert returnedThingyMessages.Count.ShouldBe(thingyMessages.Count); - returnedThingyMessages.SequenceEqual(thingyMessages).ShouldBeTrue(); + returnedThingyMessages.ShouldBe(thingyMessages, ignoreOrder: true); } [TestCase(true, true)] From 7eaad77000342783b0e347b82710acb3cc2d6985 Mon Sep 17 00:00:00 2001 From: Focus Date: Sat, 14 Jun 2025 16:17:01 +0300 Subject: [PATCH 13/13] Remove FluentAssertions, replace in LoggerMock, Examples --- .../DateTimeExtensions.cs | 12 ++++++++++++ .../IntegrationTests/Scenarios.cs | 1 - ...ransportLegsAreConnectedSpecificationTests.cs | 16 ++++++++-------- .../Routing/RoutingServiceTests.cs | 5 ++--- .../EventFlow.Examples.Shipping.Tests/Voyages.cs | 1 - .../EventFlow.TestHelpers.csproj | 1 - Source/EventFlow.TestHelpers/LoggerMock.cs | 7 +++++-- 7 files changed, 27 insertions(+), 16 deletions(-) create mode 100644 Source/EventFlow.Examples.Shipping.Tests/DateTimeExtensions.cs diff --git a/Source/EventFlow.Examples.Shipping.Tests/DateTimeExtensions.cs b/Source/EventFlow.Examples.Shipping.Tests/DateTimeExtensions.cs new file mode 100644 index 000000000..d15d8fdf9 --- /dev/null +++ b/Source/EventFlow.Examples.Shipping.Tests/DateTimeExtensions.cs @@ -0,0 +1,12 @@ +using System; + +namespace EventFlow.Examples.Shipping.Tests; + +public static class DateTimeExtensions +{ + public static DateTime October(this int day, int year) => new(year, 10, day); + public static DateTime November(this int day, int year) => new(year, 11, day); + public static DateTime January(this int day, int year) => new(year, 1, day); + + public static DateTime At(this DateTime date, int hours, int minutes) => new(date.Year, date.Month, date.Day, hours, minutes, 0); +} \ No newline at end of file diff --git a/Source/EventFlow.Examples.Shipping.Tests/IntegrationTests/Scenarios.cs b/Source/EventFlow.Examples.Shipping.Tests/IntegrationTests/Scenarios.cs index a0c6eaef5..b363c18f1 100644 --- a/Source/EventFlow.Examples.Shipping.Tests/IntegrationTests/Scenarios.cs +++ b/Source/EventFlow.Examples.Shipping.Tests/IntegrationTests/Scenarios.cs @@ -33,7 +33,6 @@ using EventFlow.Examples.Shipping.Domain.Model.VoyageModel.Commands; using EventFlow.Examples.Shipping.Queries.InMemory; using EventFlow.TestHelpers; -using FluentAssertions.Extensions; using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; diff --git a/Source/EventFlow.Examples.Shipping.Tests/UnitTests/Domain/Model/CargoModel/Speficications/TransportLegsAreConnectedSpecificationTests.cs b/Source/EventFlow.Examples.Shipping.Tests/UnitTests/Domain/Model/CargoModel/Speficications/TransportLegsAreConnectedSpecificationTests.cs index 28e1b4fcf..b6f6d3b06 100644 --- a/Source/EventFlow.Examples.Shipping.Tests/UnitTests/Domain/Model/CargoModel/Speficications/TransportLegsAreConnectedSpecificationTests.cs +++ b/Source/EventFlow.Examples.Shipping.Tests/UnitTests/Domain/Model/CargoModel/Speficications/TransportLegsAreConnectedSpecificationTests.cs @@ -20,14 +20,14 @@ // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +using System.Linq; using EventFlow.Examples.Shipping.Domain.Model.CargoModel.Entities; using EventFlow.Examples.Shipping.Domain.Model.CargoModel.Specifications; using EventFlow.Examples.Shipping.Domain.Model.VoyageModel; using EventFlow.Examples.Shipping.Domain.Model.VoyageModel.Entities; using EventFlow.TestHelpers; -using FluentAssertions; -using FluentAssertions.Extensions; using NUnit.Framework; +using Shouldly; namespace EventFlow.Examples.Shipping.Tests.UnitTests.Domain.Model.CargoModel.Speficications { @@ -50,8 +50,8 @@ public void Valid() var why = sut.WhyIsNotSatisfiedBy(transportLegs); // Assert - isSatisfiedBy.Should().BeTrue(); - why.Should().HaveCount(0); + isSatisfiedBy.ShouldBeTrue(); + why.Count().ShouldBe(0); } [Test] @@ -70,8 +70,8 @@ public void UnloadIsAfterLoad() var why = sut.WhyIsNotSatisfiedBy(transportLegs); // Assert - isSatisfiedBy.Should().BeFalse(); - why.Should().HaveCount(1); + isSatisfiedBy.ShouldBeFalse(); + why.Count().ShouldBe(1); } [Test] @@ -90,8 +90,8 @@ public void UnloadAndLoadLocationsAreDifferent() var why = sut.WhyIsNotSatisfiedBy(transportLegs); // Assert - isSatisfiedBy.Should().BeFalse(); - why.Should().HaveCount(1); + isSatisfiedBy.ShouldBeFalse(); + why.Count().ShouldBe(1); } } } \ No newline at end of file diff --git a/Source/EventFlow.Examples.Shipping.Tests/UnitTests/ExternalServices/Routing/RoutingServiceTests.cs b/Source/EventFlow.Examples.Shipping.Tests/UnitTests/ExternalServices/Routing/RoutingServiceTests.cs index df879ec46..1abf4ca8c 100644 --- a/Source/EventFlow.Examples.Shipping.Tests/UnitTests/ExternalServices/Routing/RoutingServiceTests.cs +++ b/Source/EventFlow.Examples.Shipping.Tests/UnitTests/ExternalServices/Routing/RoutingServiceTests.cs @@ -24,9 +24,8 @@ using EventFlow.Examples.Shipping.Domain.Model.VoyageModel; using EventFlow.Examples.Shipping.ExternalServices.Routing; using EventFlow.TestHelpers; -using FluentAssertions; -using FluentAssertions.Extensions; using NUnit.Framework; +using Shouldly; namespace EventFlow.Examples.Shipping.Tests.UnitTests.ExternalServices.Routing { @@ -51,7 +50,7 @@ public void Itinerary() // Assert // TODO: Assert list of legs - itineraries.Should().HaveCount(1); + itineraries.Count.ShouldBe(1); } } } \ No newline at end of file diff --git a/Source/EventFlow.Examples.Shipping.Tests/Voyages.cs b/Source/EventFlow.Examples.Shipping.Tests/Voyages.cs index 8055bed0e..10b04e802 100644 --- a/Source/EventFlow.Examples.Shipping.Tests/Voyages.cs +++ b/Source/EventFlow.Examples.Shipping.Tests/Voyages.cs @@ -23,7 +23,6 @@ using System.Collections.Generic; using EventFlow.Examples.Shipping.Domain.Model.VoyageModel; using EventFlow.Examples.Shipping.Domain.Model.VoyageModel.ValueObjects; -using FluentAssertions.Extensions; namespace EventFlow.Examples.Shipping.Tests { diff --git a/Source/EventFlow.TestHelpers/EventFlow.TestHelpers.csproj b/Source/EventFlow.TestHelpers/EventFlow.TestHelpers.csproj index d730be3d8..6bcd904fb 100644 --- a/Source/EventFlow.TestHelpers/EventFlow.TestHelpers.csproj +++ b/Source/EventFlow.TestHelpers/EventFlow.TestHelpers.csproj @@ -18,7 +18,6 @@ - diff --git a/Source/EventFlow.TestHelpers/LoggerMock.cs b/Source/EventFlow.TestHelpers/LoggerMock.cs index 0f66b3c5d..9741e5997 100644 --- a/Source/EventFlow.TestHelpers/LoggerMock.cs +++ b/Source/EventFlow.TestHelpers/LoggerMock.cs @@ -25,7 +25,6 @@ using System.Collections.Generic; using System.Linq; using EventFlow.Core; -using FluentAssertions; using Microsoft.Extensions.Logging; using Shouldly; @@ -88,7 +87,11 @@ public void VerifyProblemLogged(params Exception[] expectedExceptions) var exceptions = Logs(LogLevel.Error, LogLevel.Critical) .Select(m => m.Exception) .ToList(); - exceptions.Should().AllBeEquivalentTo(expectedExceptions); + + foreach (var exception in exceptions) + { + exception.ShouldBeOneOf(expectedExceptions); + } } public IReadOnlyCollection Logs(params LogLevel[] logLevels)