public void Delete_City_By_Id() { var stateToSave = new State(); stateToSave.Name = "Buenos Aires"; var cityToSave = new City(); cityToSave.Name = "Mar del Plata"; cityToSave.Id = 1; cityToSave.State = stateToSave; var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "Delete_City_by_Id") .Options; using (var context = new ApplicationDbContext(options)) { var service = new CitiesService(context); service.AddCity(cityToSave); } using (var context = new ApplicationDbContext(options)) { var service = new CitiesService(context); service.DeleteById(1); Assert.Empty(service.GetAllCities()); } }