This section updates the service tests for the updated ASP.NET Core service.
- [Instructor] The final change we need to make is to update the unit test for the API site. So, let's take the original unit test, drag them over into our Spy Store Service Test project. Go ahead and delete the sample test that was in the project. And we also have to drag the base unit test over. In the base unit test the only change we have to make is for the port number.
If we want to debug using Visual Studio we'll change that to 60910. That's the IIS Express port. Save that. And then a few other changes we need to make. If we open up the No Update Tests and scroll down to line 129.
This is actually the messageObject.error and messageObject.message. We need to make this same change in the next test here on line 152. This change is due to the exception filter that we added into the asp.net core application. It's bringing back three properties. Error, message, and stack trace.
So this the enhanced error handling that we added into the application. Okay, now that we have the properties corrected, we have to correct the actual message. So on line 152, it's actually an invalid quantity request. And it's the same message up above.
So copy that. Paste that into 129. And then we open up the shopping cart controller test delete partial class and we have to make the same change down on line 46 to error. Next we change concurrency error to concurrency issue and we save the file.
If we switch over to the SpyStoreAPI Solution, change it back to IIS Express and hit run this will confirm that everything is running. And once we see the values we pop back over to our test solution. Go to test, windows, test explorer. Build the project and run all of the tests. It's going to break on unhandled exceptions.
Just go ahead and hit continue. And when it completes everything should turn up green. Now this doesn't fully test the exception filter because we're not checking for the stack trace. So let's modify the test a little bit so we can verify that we are getting the stack trace information from the exception filter. So in the No Update Tests, let's add an assert. And we're just going to say True, not string.IsNullorEmpty.
And this is the messageObject.StackTrace.ToString. And we'll copy that from line 131 down to 155. Save it. Come back and run all tests again. Now I did this to demonstrate what'll happen with this particular setup. Because we're not using NuGet packages but actual live references to the Spy Store DAL and Spy Store models, when I try to rebuild the solution it failed because it can't overwrite the assemblies for these Spy Store DAL and Spy Store model projects.
So if I just rebuild the services project you would think that would work as well but I continue getting errors. It's an easy fix. You go into the Spy Store API, you stop the execution, go back, rebuild your project. All the tests show up once again. Run your asp.net MVC service. Once again we'll see Chrome pop up.
It's populating the database. Lots of heavy lifting going on. We see the values. We go back into our test project, run all tests, and we should still be green. And we're green across the board so we know that the stack trace is coming through, as well. And that completes unit testing the new and updated web API service.
- Creating the .NET Core project
- Adding Entity Framework
- Migrating the data access layer (DAL)
- Configuring services and the HTTP pipeline
- Adding remaining services to the dependency injection container
- Migrating controllers and actions
- Testing the services