From fba7e5707493e46248a9ab8b90e43a8af535ffc8 Mon Sep 17 00:00:00 2001 From: Kyle McMaster Date: Thu, 26 Sep 2024 22:22:54 -0400 Subject: [PATCH] Add scenario tests and cleanup invalid test --- .../SagaScenarioTests.cs | 38 +++++++++++++++++++ ...tartContributorVerificationCommandTests.cs | 18 --------- 2 files changed, 38 insertions(+), 18 deletions(-) create mode 100644 tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/SagaScenarioTests.cs diff --git a/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/SagaScenarioTests.cs b/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/SagaScenarioTests.cs new file mode 100644 index 0000000..f869510 --- /dev/null +++ b/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/SagaScenarioTests.cs @@ -0,0 +1,38 @@ +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 = 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(); + } +} diff --git a/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/StartContributorVerificationCommandTests.cs b/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/StartContributorVerificationCommandTests.cs index b344278..366401f 100644 --- a/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/StartContributorVerificationCommandTests.cs +++ b/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/StartContributorVerificationCommandTests.cs @@ -23,22 +23,4 @@ public async Task ShouldSendVerifyContributorCommand() var sentMessage = context.FindSentMessage(); sentMessage.Should().NotBeNull(); } - - [Fact] - public async Task ShouldSetContributorIdOnSagaState() - { - var message = new StartContributorVerificationCommand() - { - ContributorId = 4680 - }; - var saga = new ContributorVerificationSaga - { - Data = new() - }; - var context = new TestableMessageHandlerContext(); - - await saga.Handle(message, context); - - saga.Data.ContributorId.Should().Be(message.ContributorId); - } }