Skip to content

Commit

Permalink
Update ContributorVerifiedEventTests for upcoming Scenario tests, Add…
Browse files Browse the repository at this point in the history
… StartContributorVerificationCommand tests for saga
  • Loading branch information
KyleMcMaster committed Sep 27, 2024
1 parent 7ff4396 commit 5e5de54
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,29 +18,4 @@ public async Task ShouldMarkSagaAsCompleted()

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<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
@@ -0,0 +1,44 @@
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<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 5e5de54

Please sign in to comment.