public async System.Threading.Tasks.Task TestClosingABooking() { 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 bookingController = new BookingsController(context); var locationController = new LocationsController(context); var parkingLotController = new ParkingLotsController(context); Location location = new Location() { LocationLocality = "Whitefield", LocationBuilding = "TestBuilding", LocationCity = "Bangalore", LocationPinCode = 560000 }; await locationController.PostLocation(location); ParkingLot newParkingLot = new ParkingLot() { ParkingDisplayName = "TestPL", LocationLocality = "Whitefield", LocationBuilding = "TestBuilding", LocationCity = "Bangalore", LocationPinCode = 560000 }; await parkingLotController.PostParkingLot(newParkingLot); context.SaveChanges(); await bookingController.PostBooking(1); context.SaveChanges(); bookingController.CloseBooking(1); context.SaveChanges(); var booking = await bookingController.GetBooking(1); Assert.True(booking.Value.IsOccupied == false); } } finally { connection.Close(); } }