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 - ASP.NET Core Tutorial
From the course: Advanced ASP.NET Core: Unit Testing
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
ASP.NET Core MVC project overview5m
-
(Locked)
Set up MVC testing project2m 34s
-
(Locked)
Unit testing index ActionResult7m 55s
-
(Locked)
Challenge: Unit testing details ActionResult54s
-
(Locked)
Solution: Unit testing details ActionResult9m 54s
-
(Locked)
Unit testing create ActionResult7m 45s
-
(Locked)
Unit testing remove ActionResult5m 30s
-
(Locked)
-