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