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.
Solution: Test HttpGet API endpoint with id - ASP.NET Core Tutorial
From the course: Advanced ASP.NET Core: Unit Testing
Solution: Test HttpGet API endpoint with id
(upbeat music) - [Narrator] I asked you to unit test the HttpGet by ID API endpoint and paste the par meter using the inline data attribute. Now, let us walk through my solution together. Before we write any code in here, let us go to the controller and check the API endpoint. So, inside here scroll down to the HttpGet that has an ID par meter. And here we see that we get this single book by using the Get by ID method, and we check if the book exists. If it doesn't exist we turn a not found. And if it exists, we returned an ok that has as a par meter, the book. Now when unit testing, we need to check both cases. We need to provide an invalid guid, which doesn't exist, so we can check if it returns a not found, and also a valid one to check if it returned an ok item. Let us go to our books controller test and start writing some code. We have said that instead of fact, we are going to use the theory attribute. So, for…
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)
-
-