Integration Testing Using WebApplicationFactory

When the .NET Core team started to envision how the .NET Framework would look like as a modern web framework they set out to expand the testing capabilities of the framework. If you come from the world of .NET MVC 5 you probably know that one of the best ways to test an HTTP request in MVC 5 was to use Phil’s HttpSimulator. That is no longer the case in .NET Core thanks to the power of the WebApplicationFactory class. This class creates a local instance of TestServer, TestServer creates a local kestrel web server. Since we are dealing with an actual web server, not a fake web server, there is no need to stub, fake, or mock anything. The HTTP request that are made to the local kestrel web server are legitimate HTTP request, this gives you the power to test your application’s functionality from visual studio, build server, or wherever you are executing your Unit Test as if the app where hosted on a live server. ...

December 5, 2020 · Yunier

Dream Machine - Turn On/Off LED Light Switch

I want to step away from software for this post to talk about some hardware. Over the years I’ve owned a few routers, some have been really really good and some have been really bad. So far the best router I have owned is my current router, the UniFi Dream Machine. While I was mostly happy with my last router, the NighHawk AC1900, it did dropped the WiFi signal a lot, I think that at one point it was dropping the WiFi signal once a week. That prompted me to start looking for a new router. After doing some research, and seeing Troy Hunt presentation on bad IOT devices and NetworkChuck’s review on the Dream Machine, I was sold on the Dream Machine. ...

November 21, 2020 · Yunier

JSON:API - Exposing The Customer Resource

This will be my third blog post on JSON:API in .NET Core. I plant to add Customer as an API resource, but before we get too deep on the code, I would like to review the Chinook database project. To do that I’m going to import Chinook.db into DB Browser for SQLite to see all available entities. As you can see we have quite a few entities, for this blog post I will concentrate on the customers entity. To accomplish adding customers as an API resource I will need to create a new service model that represents the customers entity in both JsonApiFramework and EF Core. I will scaffold the SQLite database using EF Core’s reverse engineering capabilities. ...

October 30, 2020 · Yunier

JSON:API - Exception Handling Middleware

On my second post on JSON:API in .NET Core I wanted to create an exception handling middleware. This middleware would be responsible for catching all exceptions and for generating a JSON:API Errors Documents. I’ll start by adding a middleware folder on the Chinook.Web project, for now it will only have the exception handling middleware, but, eventually it will have additional middleware. Folder has been added, now I will add the middleware class to the project in here. ...

October 19, 2020 · Yunier

SQLite - No Such Table Error

Are you using SQLite as an in-memory provider for EF Core on your Unit/Integration test? If you are, you may come across the following exception when creating the in-memory database. As you can see from the exception, the error is “SQLite Error 1: ’no such table vPet’” which is odd because vPet is defined as a SQL view on my DbContext, not a SQL table. Here is my PetsDbContext. ...

September 19, 2020 · Yunier