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 - ASP.NET Core Tutorial
From the course: Advanced ASP.NET Core: Unit Testing
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…
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 web API project overview2m 57s
-
(Locked)
Set up web API testing project3m 13s
-
(Locked)
Unit testing HttpGet API endpoint5m 29s
-
(Locked)
Challenge: Test HttpGet API endpoint with id51s
-
(Locked)
Solution: Test HttpGet API endpoint with id7m 35s
-
(Locked)
Unit testing HttpPost API endpoint6m 37s
-
(Locked)
Unit testing HttpDelete API endpoint4m 38s
-
(Locked)
-
-