Testing controller action methods

In this section, we are going to create tests for some question controller actions. Let's get started:

  1. First, we need to reference the QandA project from the Tests project. We do this by right-clicking on the Dependencies node in the Solution Explorer in the Tests project and choosing Add Reference...:

  1. Then, we need to tick the QandA project and click the OK button:

  1. Our controller has dependencies for a cache, a data repository, and a SignalR hub. Due to this, we'll need to mock these out in our tests. We are going to use a library called Moq to help us set up mocks in our tests. Let's install Moq into our test project using the NuGet Package Manager:

Great stuff—that's the first test on our web API completed!

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

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