示例#1
0
 public IngredientInfo(UpdateIngredientCommand command)
 {
     Map(command);
     this.Id = command.Id;
     InitCollections();
     this.InsertOrUpdateScopeValidate();
 }
        public virtual async Task <NotificationResult> UpdateAsync(UpdateIngredientCommand command)
        {
            BeginTransaction();
            var result = await _handler.UpdateAsync(command);

            return(Commit(result));
        }
        public async Task <IActionResult> Update(int id, UpdateIngredientCommand command)
        {
            command.Id = id;
            await Mediator.Send(command);

            return(NoContent());
        }
        public async Task <IActionResult> Put(int id, [FromBody] UpdateIngredientCommand command)
        {
            command.Id = id;
            var result = await _service.UpdateAsync(command);

            return(Ok(result));
        }
示例#5
0
        public async Task <ActionResult <Ingredient> > UpdateIngredient(Ingredient ingredient)
        {
            var updateCommand = new UpdateIngredientCommand(ingredient);
            var response      = await _mediator.Send(updateCommand);

            return(Ok(response));
        }
示例#6
0
 public async Task <IActionResult> Update(int id, [FromBody] UpdateIngredientCommand command)
 {
     if (id != command.Id)
     {
         return(BadRequest());
     }
     return(Ok(await mediator.Send(command)));
 }
示例#7
0
        public void IngredientDoesntExist_ShouldThrow()
        {
            // arrange
            this.MockUnitOfWork.Setup(m => m.IngredientRepository.Read(It.IsAny <int>())).Returns(() => null);
            var command = new UpdateIngredientCommand();

            // act
            Action act = () => this.DomainServices.RunCommand(command);

            // assert
            act.Should().Throw <IngredientNotFoundException>();
        }
 public void SetUp()
 {
     _command            = CommandFactory.EmptyUpdateIngredientCommand();
     _eventPublisherMock = new Mock <IEventPublisher>();
     _validator.Setup(x => x.Validate(It.IsAny <UpdateIngredientCommand>()))
     .Returns(Result.Ok);
     _validators = new List <ICommandValidator <UpdateIngredientCommand> >
     {
         _validator.Object
     };
     _ingredient       = FakeIngredientFactory.CreateValidIngredient("Ingredient", _ingredientRepositoryMock.Object);
     _systemUnderTests = new UpdateIngredientCommandHandler(_ingredientRepositoryMock.Object, _validators,
                                                            _eventPublisherMock.Object);
 }
        public void InvalidModel_ShouldThrow()
        {
            // arrange
            var createCommand = this.IngredientDataProvider.CreateCommand();

            this.RunCommand(createCommand);

            var updateCommand = new UpdateIngredientCommand
            {
                Id = createCommand.Id.Value
            };

            // act
            Action act = () => this.RunCommand(updateCommand);

            // assert
            act.Should().Throw <ValidationException>();
        }
        public void HappyPath()
        {
            // arrange
            var createCommand = this.IngredientDataProvider.CreateCommand();

            this.RunCommand(createCommand);

            var updateCommand = new UpdateIngredientCommand
            {
                Id   = createCommand.Id.Value,
                Name = "Test"
            };

            // act
            this.RunCommand(updateCommand);

            // assert
            var actual = this.RunQuery(new GetIngredientByIdQuery(updateCommand.Id));

            actual.Should().BeEquivalentTo(updateCommand);
        }
示例#11
0
        public async Task <IActionResult> UpdateIngredient([FromBody] UpdateIngredientCommand command)
        {
            var validationResult = _validators.ValidateUpdate(command);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult));
            }

            var result = await _mediator.Command(command);

            if (!result.IsFailure)
            {
                return(Ok(result));
            }

            if (result.ResultCode.Equals(ResultCode.NotFound))
            {
                return(NotFound(result));
            }

            return(BadRequest(result));
        }
        public virtual async Task <NotificationResult> UpdateAsync(UpdateIngredientCommand command)
        {
            var result = new NotificationResult();
            var item   = new IngredientInfo(command);

            result.Add(item.GetNotificationResult());
            if (!result.IsValid)
            {
                return(result);
            }
            result.Add(await _ingredientRepository.UpdateAsync(item));
            if (result.IsValid)
            {
                result.Data = item.Id;
                result.AddMessage(Shared.Domain.Resources.Handler.UpdateSuccess_Message);
            }
            else
            {
                result.AddErrorOnTop(Shared.Domain.Resources.Handler.UpdateError_Message);
            }

            return(result);
        }
 public ValidationResult ValidateUpdate(UpdateIngredientCommand command)
 => _updateValidator.Validate(command);