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 HttpPost API endpoint

Unit testing HttpPost API endpoint - ASP.NET Core Tutorial

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

Start my 1-month free trial

Unit testing HttpPost API endpoint

- [Instructor] So far, we have set up unit tests for getting books, either all of them or by a good ID. And now we are going to add a unit test for the http post, API endpoint. So, let us go to Visual Studio and see this in action. Before we write any test, let us go to the controller, then books controller, and scroll down to the http post API endpoint. And we see that in here we have two possible outcomes. The first one is a bad request when the model state is not valid. And the other one is a created at action, where we just return the book that we added to our collection. Now, let us go to our books controller test and start typing some code. Now, on the last clip, we use the inline data to pass parameters to our method. In this one we are going to arrange everything inside the method. So for that, we are going to use the fact attribute, instead of the theory one. Let us scroll to the bottom. In here write…

Contents