Wednesday, 2 March 2016

RESTful Day #7: Unit Testing and Integration Testing in WebAPI using NUnit and Moq framework (Part 1)

Source Code at GitHub


We have been learning a lot in WebAPI. We covered almost all the techniques required to build a robust and a full stack REST service using ASP.NET WebAPI, from creating a service to making it a secure and ready-to-use boilerplate with enterprise level applications. In this article, we’ll learn on how to focus on test driven development and write unit tests for our service endpoints and business logic. I’ll use NUnit and Moq framework to write test cases for business logic layer and controller methods. I’ll cover less theory and focus more on practical implementations on how to use these frameworks to write unit tests. I have segregated the article into two parts. The first part focusses on testing business logic and class libraries created as BusinessServices in our code base. The second part will focus on testing a Web API. The purpose of segregation is simple; the scope of this article is very large and may turn up into a very large post which would be not easy to read in one go.


The following is the roadmap I have setup to learn WebAPI step by step: