The Moq framework, when used together with the xUnit.net framework, can deliver a smooth unit testing experience and make the overall TDD process worthwhile. Moq provides powerful features that, when used effectively, can simplify the creation of dependencies mocking for unit tests.
Mock objects created with Moq can allow you to substitute the concrete dependencies in your unit tests for the created mocks created by you in order to isolate different units in your code for testing and subsequent refactoring, which can facilitate crafting elegant production-ready code. Also, you can use mock objects to experiment and test features available in dependencies that otherwise might not be easily done by using the live dependencies.
In this chapter, we have explored the basics of mocking, and extensively used mocks in unit tests. Also, we configured mocks to set up methods and...