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

Solution: Test HttpGet API endpoint with id - ASP.NET Core Tutorial

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

Start my 1-month free trial

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…

Contents