Skip to content

Instantly share code, notes, and snippets.

@explorer14
Last active June 8, 2020 18:55
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/2f0d56812f79c20f74cbdaa7b17b3ef7 to your computer and use it in GitHub Desktop.
Save explorer14/2f0d56812f79c20f74cbdaa7b17b3ef7 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 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