public async Task GivenCommand_WhenIngredientDoesNotExist_ReturnFailure()
        {
            var result = await _systemUnderTests.Handle(_command);

            using (new AssertionScope())
            {
                result.IsFailure.Should().BeTrue();
                result.Message.Should().Be(FailMessages.DoesNotExist(nameof(Ingredient),
                                                                     nameof(UpdateIngredientCommand.Id), _command.Id.ToString()));
            }
        }
コード例 #2
0
        public async Task <Result> Handle(UpdateIngredientCommand command)
        {
            foreach (var validator in _validators)
            {
                var validationResult = validator.Validate(command);
                if (validationResult.IsFailure)
                {
                    return(validationResult);
                }
            }

            var ingredient = _ingredientRepository.GetById(command.Id);

            if (ingredient == null)
            {
                return(Result.Fail(ResultCode.NotFound, FailMessages.DoesNotExist(nameof(Ingredient),
                                                                                  nameof(UpdateIngredientCommand.Id), command.Id.ToString())));
            }

            ingredient.Update(command.Name, command.Allergens, command.Requirements, command.Shares);
            _eventPublisher.Rise();
            return(Result.Ok());
        }