There's more...

This recipe covers a typical behavioral unit test to make sure that your class's structure is correct. Different schools of thought have different opinions on how to unit test your code. Some might argue that you shouldn't know the internals of your class when unit testing. Without going too much into the broader unit testing debate, this recipe is here to illustrate the refactoring advantages and the structure of your code/unit testing. You can easily build other unit tests to verify your object's states, exception handling, and, as we will see in the next recipe, your data access layer's LINQ queries.

Regarding the choice of Moq: as we mentioned in the introduction, Moq is an easy-to-use mocking framework that has been around for a long time and is constantly being supported. There are many mocking frameworks out there that you can choose from, including Visual Studio fakes. If you want to know more about the power of Moq, visit https://github.com/Moq/moq4/wiki/Quickstart.

In this recipe, we touched on mocks and stubs and we also talked about behavioral verification as opposed to state verification. If you want to know more about the types of unit testing, and the different ways in which you can mock/stub your classes, read the timeless Martin Fowler article Mocks Aren't Stubs at https://martinfowler.com/articles/mocksArentStubs.html.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.19.174