Moq will be demonstrated in this video. The student will learn how to install Moq (one of many mocking frameworks) using NuGet. They continue by mocking a collection of employees that will be used in place of the original source data using the lambs expressions part of the Moq syntax to get a sense of how to implement mocking in an existing solution.
- [Voiceover] Ok, before we wrap up,…I wanted to talk about one more thing…that we covered earlier on…which is moqing.…So in this video we want to go ahead and demonstrate that.…We are going to be using the moq framework…and to install it,…what we want to do is…go on over to the polymorphism project,…right click, and then go to manage NuGet Packages.…NuGet is an install in visual studio to allow you to easily…install third party software.…
If we make sure that browse is selected and type in…in the text box right below it m, o, q,…we should get some options,…and the very first one is moq.…It's already selected by default.…We can go on to the right hand side and chose install.…We'll be prompted to confirm that it's going to install…in the polymorphism project, that looks good, click ok,…and boom. At the bottom of the output window,…you should see that it's finished,…and if we look in the solution explorer, under references,…you'll see a new reference to moq.…
Looks good so far.…Let's navigate to our program file,…and if we scroll down, what we are going to want to do is…
In this course, Reynald Adolphe explains the principles of test-driven development and shows how to apply them to two different C# workflows. First, he creates a new test-driven project. He writes the test cases before the code to drive the design of the program. In the second scenario, he writes test cases for an existing C# project, to find bugs before it goes live. Along the way, Reynald uses Microsoft's MSTest, but he also introduces other testing tools (such as the unit testing framework xUnit and the mocking framework Moq) and theories (such as the red-green-refactor mantra and SOLID principles) that make test-driven development so efficient.
- Different approaches to testing
- Using testing tools and mocking frameworks
- Creating a simple C# test-driven project
- Adding a failing test
- Updating tests to pass
- Refactoring code
- Using Moq to test data