Mocking libraries
There is no shortage of mocking libraries in .NET; however, the top two used libraries are NSubstitute and Moq. We have covered plenty of examples of NSubstitute in this book, so let’s see how Moq works.
Moq
Moq has the same role and same functionality, more or less, as NSubstitute. Given that the book was using NSubstitute, the fastest way to introduce Moq is to compare the two libraries. Let’s start with a snippet from NSubstitute:
private IOpenWeatherService _openWeatherServiceMock = Substitute.For<IOpenWeatherService>(); private WeatherAnalysisService _sut; private const decimal LAT = 2.2m; private const decimal LON = 1.1m; public WeatherAnalysisServiceTests() { _sut = new (_openWeatherServiceMock); } [Fact] public async Task GetForecastWeatherAnalysis_ LatAndLonPassed_ReceivedByOpenWeatherAccurately() { // Arrange ...