diff --git a/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/ContributorVerifiedEventTests.cs b/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/ContributorVerifiedEventTests.cs index bb3ec2d..d582056 100644 --- a/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/ContributorVerifiedEventTests.cs +++ b/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/ContributorVerifiedEventTests.cs @@ -11,11 +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(); + saga.Completed.Should().BeTrue(); } } diff --git a/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/SagaScenarioTests.cs b/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/SagaScenarioTests.cs index f869510..0a7aa02 100644 --- a/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/SagaScenarioTests.cs +++ b/tests/NServiceBusTutorial.UnitTests/ContributorVerificationSagaTests/SagaScenarioTests.cs @@ -13,26 +13,44 @@ public class SagaScenarioTests [Fact] public async Task ShouldInitializeSagaAndMarkAsCompleted() { - int expectedContributorId = 1; - var startMessage = new StartContributorVerificationCommand() + int expectedContributorId = 4680; + var startCommand = new StartContributorVerificationCommand { ContributorId = expectedContributorId }; - var message = new ContributorVerifiedEvent() + var verifiedEvent = new ContributorVerifiedEvent { ContributorId = expectedContributorId }; var saga = new TestableSaga(); var context = new TestableMessageHandlerContext(); - var result = await saga.Handle(startMessage, context); + var startResult = await saga.Handle(startCommand, context); + var completeResult = await saga.Handle(verifiedEvent, context); using var assertionScope = new AssertionScope(); - result.SagaDataSnapshot.ContributorId.Should().Be(expectedContributorId); + startResult.SagaDataSnapshot.ContributorId.Should().Be(expectedContributorId); + completeResult.Completed.Should().BeTrue(); + } - result = await saga.Handle(message, context); - result.Completed.Should().BeTrue(); - var timeoutMessage = result.FindTimeoutMessage(); - timeoutMessage.Should().NotBeNull(); + [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(); } }