Skip to content

Instantly share code, notes, and snippets.

@explorer14
Last active Jun 8, 2020
Embed
What would you like to do?
[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 eventBusMock = new Mock<IEventBus>();
eventBusMock
.Setup(x=>x.Publish(It.IsAny<NewCustomerRegistered>()))
.ReturnsAsync(Task.CompletedTask)
.Verifiable();
// Create the system under test with a stub and a mock
var useCase = new CustomerRegistrationUseCase(
customerRepositoryStub,
eventBusMock.Object);
await useCase.RegisterCustomer(testCustomerRegistrationRequest);
eventBusMock.Verify(x=>x.Publish(It.IsAny<NewCustomerRegistered>()), Times.Once);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment