public async Task <ActionResult> UpdateLogItem(int id, ConsumeLogItem logItem) { if (id != logItem.Id) { ModelState.AddModelError("upd_err", "Id in the path does not match with model id!"); return(BadRequest()); } await _consumedDishService.UpdateLogItem(logItem); return(NoContent()); }
public async Task UpdateLogItemAsync_WhenItemDoesNotExist_ThrowsError() { //Prepare test ConsumedDish dish = null; var logItem = new ConsumeLogItem { Id = 1 }; _dishRepositoryMock.Setup(a => a.GetItemAsync(1, "")).ReturnsAsync(dish); //Do Test and assert and Test var exception = await Assert.ThrowsAsync <ArgumentException>(async() => await _dishService.UpdateLogItem(logItem)); Assert.Equal("Consumed dish with id 1 does not exist in database!", exception.Message); }