public async Task DeleteNonExistingCountry() { // arrange HAVIdatabaseContext dbContext = CreateDbContext(); CountryRepository repository = new CountryRepository(dbContext); Country country = new Country() { Id = 0, ProfileId = 0, CountryCode = "Code", CountryName = "Name", Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 0 } }; // act Country result = await repository.DeleteCountryAsync(country.Id); // assert Assert.IsTrue(result == null); dbContext.Dispose(); }
public async Task <ActionResult <Country> > DeleteCountry(int id) { try { var countryToDelete = await _countryRepository.GetCountry(id); if (countryToDelete == null) { return(NotFound($"Country with id = {id} not found")); } return(await _countryRepository.DeleteCountryAsync(id)); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Error retrieving data from the database.")); } }