diff --git a/.editorconfig b/.editorconfig index 7ea9b64..cf4d021 100644 --- a/.editorconfig +++ b/.editorconfig @@ -146,6 +146,10 @@ csharp_style_expression_bodied_local_functions = false:silent ############################### # VB Coding Conventions # ############################### + +# IDE0005: Using directive is unnecessary. +dotnet_diagnostic.IDE0005.severity = warning + [*.vb] # Modifier preferences visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async:suggestion \ No newline at end of file diff --git a/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/ContributorVerifiedEventTests.cs b/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/ContributorVerifiedEventTests.cs index 4839ac0..d582056 100644 --- a/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/ContributorVerifiedEventTests.cs +++ b/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/ContributorVerifiedEventTests.cs @@ -1,8 +1,5 @@ using FluentAssertions; -using FluentAssertions.Execution; using NServiceBus.Testing; -using NServiceBusTutorial.Core.ContributorAggregate; -using NServiceBusTutorial.Core.ContributorAggregate.Commands; using NServiceBusTutorial.Core.ContributorAggregate.Events; using NServiceBusTutorial.Saga; using Xunit; @@ -14,36 +11,11 @@ public class ContributorVerifiedEventTests public async Task ShouldMarkSagaAsCompleted() { var message = new ContributorVerifiedEvent(); - var saga = new TestableSaga(); + var saga = new ContributorVerificationSaga(); var context = new TestableMessageHandlerContext(); - var result = await saga.Handle(message, context); + await saga.Handle(message, context); - result.Completed.Should().BeTrue(); - } - - [Fact] - public async Task ShouldInitializeSagaAndMarkAsCompleted() - { - int expectedContributorId = 1; - var startMessage = new StartContributorVerificationCommand() - { - ContributorId = expectedContributorId - }; - var message = new ContributorVerifiedEvent() - { - ContributorId = expectedContributorId - }; - var saga = new TestableSaga(); - var context = new TestableMessageHandlerContext(); - - var result = await saga.Handle(startMessage, context); - using var assertionScope = new AssertionScope(); - result.SagaDataSnapshot.ContributorId.Should().Be(expectedContributorId); - - result = await saga.Handle(message, context); - result.Completed.Should().BeTrue(); - var timeoutMessage = result.FindTimeoutMessage(); - timeoutMessage.Should().NotBeNull(); + saga.Completed.Should().BeTrue(); } } diff --git a/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/SagaScenarioTests.cs b/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/SagaScenarioTests.cs new file mode 100644 index 0000000..0a7aa02 --- /dev/null +++ b/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/SagaScenarioTests.cs @@ -0,0 +1,56 @@ +using FluentAssertions; +using FluentAssertions.Execution; +using NServiceBus.Testing; +using NServiceBusTutorial.Core.ContributorAggregate.Commands; +using NServiceBusTutorial.Core.ContributorAggregate.Events; +using NServiceBusTutorial.Saga; +using Xunit; + +namespace NServiceBusTutorial.UnitTests.ContributorVerificationSagaTests; + +public class SagaScenarioTests +{ + [Fact] + public async Task ShouldInitializeSagaAndMarkAsCompleted() + { + int expectedContributorId = 4680; + var startCommand = new StartContributorVerificationCommand + { + ContributorId = expectedContributorId + }; + var verifiedEvent = new ContributorVerifiedEvent + { + ContributorId = expectedContributorId + }; + var saga = new TestableSaga(); + var context = new TestableMessageHandlerContext(); + + var startResult = await saga.Handle(startCommand, context); + var completeResult = await saga.Handle(verifiedEvent, context); + + using var assertionScope = new AssertionScope(); + startResult.SagaDataSnapshot.ContributorId.Should().Be(expectedContributorId); + completeResult.Completed.Should().BeTrue(); + } + + [Fact] + public async Task ShouldTimeoutWhenTimeAdvancesOverLimit() + { + int expectedContributorId = 4680; + var startCommand = new StartContributorVerificationCommand + { + ContributorId = expectedContributorId + }; + var saga = new TestableSaga(); + var context = new TestableMessageHandlerContext(); + + var startResult = await saga.Handle(startCommand, context); + var timeouts = await saga.AdvanceTime(TimeSpan.FromHours(25)); + + using var assertionScope = new AssertionScope(); + startResult.SagaDataSnapshot.ContributorId.Should().Be(expectedContributorId); + var timeoutResult = timeouts.Single(); + timeoutResult.FindSentMessage().Should().NotBeNull(); + timeoutResult.Completed.Should().BeTrue(); + } +} diff --git a/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/StartContributorVerificationCommandTests.cs b/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/StartContributorVerificationCommandTests.cs new file mode 100644 index 0000000..366401f --- /dev/null +++ b/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/StartContributorVerificationCommandTests.cs @@ -0,0 +1,26 @@ +using FluentAssertions; +using NServiceBus.Testing; +using NServiceBusTutorial.Core.ContributorAggregate.Commands; +using NServiceBusTutorial.Saga; +using Xunit; + +namespace NServiceBusTutorial.UnitTests.ContributorVerificationSagaTests; + +public class StartContributorVerificationCommandTests +{ + [Fact] + public async Task ShouldSendVerifyContributorCommand() + { + var message = new StartContributorVerificationCommand(); + var saga = new ContributorVerificationSaga + { + Data = new() + }; + var context = new TestableMessageHandlerContext(); + + await saga.Handle(message, context); + + var sentMessage = context.FindSentMessage(); + sentMessage.Should().NotBeNull(); + } +}