.NET Coded Unit and Integration Test with xUnit, MoQ and Repository Pattern - Share & earn cash
In the deliverables, you will find source code for the project and the supporting database backup file. You need to restore the database backup on Sql Server 2005 or higher. You will need Visual Studio 2017 or higher to load the project/solution see the code and run it.
The solution contains 3 projects -
. FoodSample [the project containing the core business logic to be tested, implemented with Repository Code Pattern]
. FoodSample.Tests [test project written with xUnit and MoQ]
. FoodSample.API [optional webAPI project upon which student can experiment, implement and run different webAPI requests to see for himself]
When we implement a Repository Pattern of data abstraction and loose coupling in applications, MoQ and xUnit become imperative, in order to 'Mock' that interface and its member methods. 'Mocking' is the only way and therein lies the importance of MoQ. In the project, you would find IDatSource as the interface containing the method, whose implementation is inside the FoodDataSource and that method is precisely the one which we want to test by supplying it various parameters. Find that part of the coded test in the FoodSampleTest class of the FoodSample.Tests project. Both xUnit and MoQ packages are added to the project, through the Nuget package manager.
In order to fully understand the solution, the student is requested to read and research a little bit on the following
- C# Repository Pattern
- concept of C# Coded Tests
- xUnit and Mocking of Interfaces
- concepts of nUnit Testing