-
-
Save explorer14/d44acd209b5df8ab59217d42852cf44a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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