From the course: Advanced ASP.NET Core: Unit Testing

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Unit testing index ActionResult

Unit testing index ActionResult - ASP.NET Core Tutorial

From the course: Advanced ASP.NET Core: Unit Testing

Start my 1-month free trial

Unit testing index ActionResult

- [Instructor] Now that we have set up the testing project, let us go to Visual Studio. The first unit test is going to be about the index action result. And in here we can see that this action result returns all the books to the view. So let us go to the BooksControllerTest and create our first unit test. Since this unit test will not take any parameters, we are going to use the fact attribute. So let us write in here fact. Next, let us write in here public void Index UnitTest. It doesn't take any parameters. And now inside here, let us create the arrange act and then the Assert. So let us first arrange everything using the mock framework. And mock is a mocking framework for .NET. So let us write in here var mockRepo is equal to new Mock and we pass as a parameter the file that we want to mock. So in here, I'll just write IBookService. And let us import the necessary namespace, which is…

Contents