Follow these steps to write a unit test for our application:
- Let's create a unit test. Let's name it RestBuy.Test, as shown in the following screenshot:

- Rename UnitTest1.cs to EFTest and copy appsettings.json from your web project to the test project. But change the database name to RestBuy_Test.
Make sure you add references to all other projects from Test. You also need a reference to Microsoft.EntityFramework.Core, and then install Microsoft.Extensions.Configuration from NuGet.
Your project should look as shown here:
- Now, ensure your appsettings.json file resembles this:
{ "ConnectionStrings": { "DefaultConnection": ...