You’re on the right lines with or a mockup
– you need to mock the IMediator
There’s a few mocking libraries out there:
- Moq
- FakeItEasy
- NSubstitute
Moq is one of the most popular, so, using your test as an example:
[Fact]
public async void UpdateCustomerCommand_CustomerDataUpdatedOnDatabase()
{
//Arrange
var mediator = new Mock<IMediator>();
UpdateCustomerCommand command = new UpdateCustomerCommand();
UpdateCustomerCommandHandler handler = new UpdateCustomerCommandHandler(mediator.Object);
//Act
Unit x = await handler.Handle(command, new System.Threading.CancellationToken());
//Assert
//Do the assertion
//something like:
mediator.Verify(x=>x.Publish(It.IsAny<CustomersChanged>()));
}