May 2018
Intermediate to advanced
334 pages
7h 25m
English
Let's take the application we developed in the previous section on unit testing. Follow the steps mentioned in the preceding section and add a new xUnit test project.
We are looking for fake objects or data for testing purposes, so we will not be hitting our actual database server. Instead, here we will use the InMemory database.
You need to add the Microsoft.EntityFrameworkCore.InMemory NuGet package to start the InMemory database.
We are not going to change anything here, but we will create fake data and records to test. To proceed, add the following code to the TestStartup.cs file in the ConfigureServices method:
//for tests use InMemory dbservices.AddDbContext<ProductContext>( o => o.UseInMemoryDatabase ( InitConfiguration().GetConnectionString ...