public async Task PutIngredient_ThrowsUnmatchedIdsException(UpdateIngredientModel ingredient) { // ARRANGE var mockDifferentId = ingredient.Id.Value + 1; var controller = Initialize(); // ACT & ASSERT await Assert.ThrowsAsync <UnmatchedIdsException>(() => controller.PutIngredient(mockDifferentId, ingredient)); }
public async Task <ActionResult> PutIngredient([FromRoute] int id, [FromBody] UpdateIngredientModel ingredient) { if (id != ingredient.Id) { throw new UnmatchedIdsException(); } await _ingredientService.Update(ingredient); return(Ok()); }
public async Task Update(UpdateIngredientModel ingredient) { var editIngredient = await _ingredientRepository.GetByIdAsync(ingredient.Id.Value); if (editIngredient == null) { throw new EntityCantBeLoadedException <Ingredient>(ingredient.Id.ToString()); } _mapper.Map(ingredient, editIngredient); await _ingredientRepository.UpdateAsync(editIngredient); }
public async Task PutIngredient_ReturnsOk(UpdateIngredientModel ingredient) { // ARRANGE _mockIngredientService.Setup(service => service.Update(It.IsAny <UpdateIngredientModel>())) .Returns(Task.FromResult(0)); var controller = Initialize(); // ACT var result = await controller.PutIngredient(ingredient.Id.Value, ingredient); // ASSERT _mockIngredientService.Verify(service => service.Update(ingredient), Times.Once()); Assert.IsType <OkResult>(result); }