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 create ActionResult - ASP.NET Core Tutorial
From the course: Advanced ASP.NET Core: Unit Testing
Unit testing create ActionResult
- [Narrator] One of the features that our app has, is the "add new book to library." So let us go to Visual Studio and write a unit test for this feature. And you'll go to the controllers folder, and open the books controller, scroll down to the create action result. And you are going to see that we have two cases, when the model state is not valid, we are returning a bad request and passing as a parameter of the model state. And when everything works as expected, we just redirect our users to the action named index. So let us go to the books controller test and write the unit test for the create action result. So I'll scroll down here to the bottom. And I'll just write fact, because I don't want to pass any parameters using the inline data attribute, and then just write, public void. I'm going to name this unit test, createTest. And then here we're going to arrange, act and then assert. I'll copy them one more time…
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)
-