public void Get_All_Cities() { var stateToSave = new State(); stateToSave.Name = "Buenos Aires"; var cityToSave = new City(); cityToSave.Name = "Mar del Plata"; cityToSave.State = stateToSave; var otherCityToSave = new City(); otherCityToSave.Name = "Balcarce"; otherCityToSave.State = stateToSave; var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "Get_All_Cities_for_database") .Options; using (var context = new ApplicationDbContext(options)) { var service = new CitiesService(context); service.AddCity(cityToSave); service.AddCity(otherCityToSave); } using (var context = new ApplicationDbContext(options)) { var service = new CitiesService(context); Assert.Equal(2, service.GetAllCities().Count); } }
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()); } }