Skip to content

Commit

Permalink
Add scenario tests and cleanup invalid test
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleMcMaster committed Sep 27, 2024
1 parent 5e5de54 commit fba7e57
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -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<ContributorVerificationSaga, ContributorVerificationSagaData>();
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<ContributorVerificationSagaTimeout>();
timeoutMessage.Should().NotBeNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,4 @@ public async Task ShouldSendVerifyContributorCommand()
var sentMessage = context.FindSentMessage<VerifyContributorCommand>();
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);
}
}

0 comments on commit fba7e57

Please sign in to comment.