public async System.Threading.Tasks.Task TestFindFreeSlotsAsync() { var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); try { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseSqlite(connection) .Options; var operationalStoreOptionsMock = new Mock <OperationalStoreOptions>(); operationalStoreOptionsMock.Object.ConfigureDbContext = dbContext => dbContext.UseSqlite(connection); var iOptionsMock = Options.Create <OperationalStoreOptions>(operationalStoreOptionsMock.Object); // Create the schema in the database using (var context = new ApplicationDbContext(options, iOptionsMock)) { context.Database.EnsureCreated(); } // Run the test against one instance of the context using (var context = new ApplicationDbContext(options, iOptionsMock)) { var parkingLotController = new ParkingLotsController(context); ParkingLot newParkingLot = new ParkingLot() { ParkingDisplayName = "TestPL", LocationLocality = "Whitefield", LocationBuilding = "TestBuilding", LocationCity = "Bangalore", LocationPinCode = 560000 }; await parkingLotController.PostParkingLot(newParkingLot); context.SaveChanges(); BookingsController bookingController = new BookingsController(context); var location = new Location() { LocationLocality = "Whitefield", LocationBuilding = "TestBuilding" }; var parkingLots = bookingController.GetFreeParkingSlots(location); Assert.Single(parkingLots.Value); } } finally { connection.Close(); } }