Skip to content

Instantly share code, notes, and snippets.

@explorer14
Last active June 21, 2020 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save explorer14/d44acd209b5df8ab59217d42852cf44a to your computer and use it in GitHub Desktop.
Save explorer14/d44acd209b5df8ab59217d42852cf44a to your computer and use it in GitHub Desktop.
[Fact]
public async Task ShouldPublishNotificationForSuccessfulRegistration()
{
var customerRepositoryStub = CreateEmptyRepository();
// Notice, I don't really care about the values in the request
// because I am testing the collaboration with the event bus
var testCustomerRegistrationRequest = CreateTestRequest();
var registrationEvent = default(NewCustomerRegistered);
// Notice the use of a different kind of test double here - a SPY!
var eventBusSpy = new Mock<IEventBus>();
eventBusSpy
.Setup(x=>x.Publish(It.IsAny<NewCustomerRegistered>()))
.ReturnsAsync(Task.CompletedTask)
.Callback<NewCustomerRegistered>(payload=> registrationEvent = payload);
// Create the system under test with a stub and a spy
var useCase = new CustomerRegistrationUseCase(
customerRepositoryStub,
eventBusSpy.Object);
await useCase.RegisterCustomer(testCustomerRegistrationRequest);
registrationEvent.Should().NotBeNull();
registrationEvent.Email.Should().Be(testCustomerRegistrationRequest.Email);
registrationEvent.FirstName.Should().Be(testCustomerRegistrationRequest.FirstName);
registrationEvent.LastName.Should().Be(testCustomerRegistrationRequest.LastName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment