In this section, we are going to create tests for some question controller actions. Let's get started:
- 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...:
- Then, we need to tick the QandA project and click the OK button:
- 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!