Outline

Demo: Debugging

We know that we have a problem in our Create Article Method but we don't know where. So let's start at the beginning… No I'm not talking about the beginning of time, nor am I talking about going back to video 1 of this series. I'm talking about the start of the request to Create an Article.

Let's go into ArticlesController and into the Create Article Method. We'll put a break point right where we call the Article Repository to Create an Article and another where we catch the exception. The exception will have some information we need to figure out what's wrong.

We'll launch the application so we can reproduce the behavior but this time we'll step thru the code to determine where the error is happening.

First we'll login with our credentials. We'll copy the JSON Web Token so we can Authorize the call. Then let's try to create an article again. I know it's going to fail and that's the whole intent. We need to figure our where it's failing.

Once we reach our break point we'll Step Into the Method. It's safe to step over the GetLoggedInUserAsync method since we've used it successfully in that past. Since the Mapper code is from a third party we don't have a choice but to step over.

There it is! Let's look at details of the exception to get some additional clues on what's wrong. Clearly this is complaining about a missing Map between objects. We need to add some configuration to Map between ArticleCreateRequest and Editorial.

We'll make that configuration change in the Startup.cs file. We'll go into the AddAutoMapper section and add that mapping.

Let's try it again. I have the JSON Web Token in my buffer from the last I copied it so I'm going to skip the login and past it right into the authorize.

Once again we'll step into our code to ensure everything is working as expected. Excellent! We manage to map our objects successfully. We can see that by hovering over the editorial and inspecting the values.

Let's also step into the CreateSlug method so we can see what's doing. Let's check the value of s and we can see that there some random alpha-characters. We can try it again by simply grabbing the arrow-pointer and dragging it up to the previous line to execute it again. This is a nice little feature built into Visual Studio but it's not always available. However, when it is do take advantage of it!

Another method that we haven't had the opportunity to test is the GetArticleBySlugAsync. Let's step into it to make sure everything is working as it should be. These are all methods that we've used in the past so we shouldn't expect any problems.

Well that didn't work as expected! Looks like were missing another Map Configuration entry. This time it's for Editorial & Article mapping. Let's add that as well. We'll add it right above our previous entry.

We'll run it again and see if it's working as expected. Once again, I'll use the JSON Web Token that's in my cache buffer from the last time I copied it. Otherwise, please feel free to login as needed.

This time we'll remove the break points and just let it run. If you're worried about it breaking again remember that this is recorded and I already fixed it so I know it run successfully. :)

There's the 200 Ok Response along with the Article we just created. Up next is the Update Articles. I'll see you there.

 

I finished! On to the next chapter