public async Task DeleteNonExistingPurchaser() { // arrange HAVIdatabaseContext dbContext = CreateDbContext(); PurchaserRepository repository = new PurchaserRepository(dbContext); Purchaser purchaser = new Purchaser() { Id = 1, ProfileId = 0, CountryId = 0, Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 2 } }; // act Purchaser result = await repository.DeletePurchaserForProfile(purchaser.ProfileId); // assert Assert.IsTrue(result == null); dbContext.Dispose(); }
public async Task <ActionResult <Purchaser> > DeletePurchaserForProfile(int id) { try { var purchaserToDelete = await _purchaserRepository.GetPurchaserForProfile(id); if (purchaserToDelete == null) { return(NotFound($"Purchaser with id = {id} not found")); } return(await _purchaserRepository.DeletePurchaserForProfile(id)); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Error retrieving data from the database.")); } }