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

Unit testing create ActionResult - ASP.NET Core Tutorial

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

Start my 1-month free trial

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…

Contents