In Chapter 5, Data-Driven Unit Tests, we discussed data-driven unit testing using the xUnit framework, which allows us to create tests that run on data from different sources, such as flat files, databases, or inline data. Now, we will explain the concepts of mocking dependencies and explore how to use the Moq framework to isolate your class that is being tested from its dependencies, using mock objects created with Moq.
There are usually objects dependencies in the code base of software projects, whether for a simple or a complex project. This is because the various objects need to interact and share information across boundaries. However, to effectively unit test the objects and isolate their behaviors, each object must be tested in isolation, irrespective of the dependencies it has on other objects.
In order to achieve this, the dependent objects in a class...