示例#1
0
        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));
        }
示例#2
0
        public async Task <ActionResult> PutIngredient([FromRoute] int id, [FromBody] UpdateIngredientModel ingredient)
        {
            if (id != ingredient.Id)
            {
                throw new UnmatchedIdsException();
            }
            await _ingredientService.Update(ingredient);

            return(Ok());
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }