Mocking dependencies with Moq and NSubstitute
So far, we’ve looked at a few libraries that improve the readability of your tests. In this section, we’ll look at mocking frameworks and see how libraries can help you more effectively test your code.
Understanding the need for mocking libraries
Let’s discuss why mocking frameworks are necessary by revisiting the FlightBookingManager
example we introduced in the previous chapter while discussing dependency injection:
public class FlightBookingManager { private readonly IEmailClient _email; public FlightBookingManager(IEmailClient email) { _email = email; } public bool BookFlight(Passenger passenger, FlightInfo flight, string seat) { if (!flight.IsSeatAvailable(seat)) { return false; } flight.AssignSeat(passenger...