public async Task <GenericCommandResult <ProductEntity> > Active(
            [FromBody] ActiveProductCommand command,
            [FromServices] IProductHandler handler)
        {
            var result = (GenericCommandResult <ProductEntity>) await handler.HandleAsync(command);

            return(result);
        }
示例#2
0
        public ActiveProductCommandTests()
        {
            _commandWithInvalidId = _fixture
                                    .Build <ActiveProductCommand>()
                                    .Without(x => x.Id)
                                    .Create();

            _commandWithValidId = _fixture
                                  .Build <ActiveProductCommand>()
                                  .With(x => x.Id, Guid.NewGuid())
                                  .Create();
        }
        public Task <ActiveProductCommandResponse> Handle(ActiveProductCommand command)
        {
            var product = _repository.Find(command.Id);

            if (product == null)
            {
                throw new DomainException("محصول یافت نشد");
            }
            product.Active();
            _context.SaveChanges();
            return(Task.FromResult(new ActiveProductCommandResponse()));
        }
        public async Task <ICommandResult> HandleAsync(ActiveProductCommand command)
        {
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult <ProductEntity>(false, command.Notifications));
            }

            var product = await _repository.GetAsync(command.Id);

            product.Active();

            await _repository.UpdateAsync(product);

            return(new GenericCommandResult <ProductEntity>(true, product));
        }
示例#5
0
        public ActiveProductHandlerTests()
        {
            _productRepository = Substitute.For <IProductRepository>();
            _handler           = new ProductHandler(_productRepository);

            var productValid = _fixture.Create <ProductEntity>();

            _productRepository.GetAsync(productValid.Id).Returns(productValid);

            _commandWithoutId = _fixture
                                .Build <ActiveProductCommand>()
                                .Without(x => x.Id)
                                .Create();

            _commandWithId = _fixture
                             .Build <ActiveProductCommand>()
                             .With(x => x.Id, productValid.Id)
                             .Create();
        }
        public async Task <IHttpActionResult> Put(ActiveProductCommand command)
        {
            var response = await Bus.Send <ActiveProductCommand, ActiveProductCommandResponse>(command);

            return(Ok(response));
        }