.NET

Quickest Way to Enable CORS for ASP.NET Core Web API application

Browser security does not allow other domain to make AJAX requests.This is called same-origin policy which prevents malicious attack from other sites. When you need to allow other sites to make cross-origin requests, we can enable Cross-origin resource sharing (CORS). There is a pretty good documentation about enabling CORS for …

.NET

Unit Testing Entity Framework Database Update logic with NSubstitute

In the previous post (UnitTesting ASP.NET Web API by Mocking DbContext with NSubstitute), we explored how to create a unit test for getting data from database with Entity Framework by mocking DbContext and DbSet.  We are going to build upon the API we created previously and add PUT logic where …

.NET

Unit Testing ASP.NET Web API by Mocking DbContext with NSubstitute

In the previous post, we created a simpleWeb API in 5 minutes. Now, let’s refactor the code so that it is unit testable with xUnit. The API we build previously was sourcing the data from MySQL database through DbContext. This is an external dependency that we need to replace in …

.NET

Creating Web APIs using ASP.NET and MySQL in 5 minutes

Creating a web API that interact with a database with C# is quite easy thanks to ASP.NET and Entity Framework. Building API with ASP.NET is essentially creating a MVC application without View. If you learn how to create a website with ASP.NET, you can apply the skills directly to API …