Example #1
0
        public async Task <BaseResponse <PedidoResponse> > Handle(CreatePedidoCommand request, CancellationToken cancellationToken)
        {
            var response = new BaseResponse <PedidoResponse>();

            var pedido = _mapper.Map <PedidoMatch>(request.PedidoRequest);

            pedido.DataSolicitacao     = System.DateTime.Now;
            pedido.IdStatusSolicitacao = await _dbContext.StatusPedido.FindAsync(1);

            var pedidoPendente = _dbContext.PedidosMatch
                                 .Where(p => p.IdUserAprovador == request.PedidoRequest.IdUserAprovador)
                                 .Where(p => p.IdUserSolicitante == request.PedidoRequest.IdUserSolicitante)
                                 .Where(p => p.IdStatusSolicitacao.Id == 1);

            if (pedidoPendente.Any())
            {
                response.SetValidationErrors(new[] { "Já existe uma conexão ou pedido de match pendente para esse usuários" });
            }

            else
            {
                await _dbContext.PedidosMatch.AddAsync(pedido, cancellationToken);

                await _dbContext.SaveChangesAsync(cancellationToken);
            }

            _geoService.DeleteFromTimeLine(request.PedidoRequest.IdUserAprovador,
                                           request.PedidoRequest.IdUserSolicitante);
            response.SetIsOk(null);
            return(response);
        }
        public async Task Handle_success()
        {
            //arrange
            var pedido = new Pedido(
                new List <ItemPedido> {
                new ItemPedido("001", "produto 001", 1, 12.34m),
                new ItemPedido("002", "produto 002", 2, 23.45m)
            },
                "clienteId", "clienteNome", "*****@*****.**", "fone", "endereco", "complemento", "bairro", "municipio", "uf", "12345-678");

            CancellationToken   token   = default(CancellationToken);
            CreatePedidoCommand command = new CreatePedidoCommand(new List <CreatePedidoCommandItem>
            {
                new CreatePedidoCommandItem("001", "produto 001", 1, 12.34m),
                new CreatePedidoCommandItem("002", "produto 002", 2, 23.45m)
            }
                                                                  , "clienteId", "clienteNome", "*****@*****.**", "fone", "endereco", "complemento", "bairro", "municipio", "uf", "12345-678");
            IdentifiedCommand <CreatePedidoCommand, bool> request = new IdentifiedCommand <CreatePedidoCommand, bool>(command, Guid.NewGuid());

            pedidoRepositoryMock
            .Setup(r => r.CreateOrUpdate(It.IsAny <Pedido>()))
            .ReturnsAsync(pedido)
            .Verifiable();

            var handler = new CreatePedidoCommandHandler(loggerMock.Object, pedidoRepositoryMock.Object, busMock.Object, configurationMock.Object);

            //act
            bool result = await handler.Handle(request, token);

            //assert
            Assert.True(result);

            pedidoRepositoryMock.Verify();
        }
Example #3
0
        public async Task <IActionResult> CreatePedido([FromBody] CreatePedidoRequest createPedido)
        {
            var command = new CreatePedidoCommand(createPedido);
            var result  = await Mediator.Send(command);

            return(await ResponseBase(result));
        }
        public async Task Handle_items_is_empty()
        {
            //arrange
            CancellationToken   token   = default(CancellationToken);
            CreatePedidoCommand command = new CreatePedidoCommand();
            IdentifiedCommand <CreatePedidoCommand, bool> request = new IdentifiedCommand <CreatePedidoCommand, bool>(command, Guid.NewGuid());
            var handler = new CreatePedidoCommandHandler(loggerMock.Object, pedidoRepositoryMock.Object, busMock.Object, configurationMock.Object);

            //act
            //assert
            await Assert.ThrowsAsync <NoItemsException>(async() => await handler.Handle(request, token));
        }
Example #5
0
        public void Dado_um_comando_invalido_o_pedido_nao_deve_ser_gerado()
        {
            var command = new CreatePedidoCommand();

            command.Aluno     = "";
            command.ZipCode   = "13411080";
            command.PromoCode = "12345678";
            command.Items.Add(new CreatePedidoItemCommand(Guid.NewGuid(), 1));
            command.Items.Add(new CreatePedidoItemCommand(Guid.NewGuid(), 1));
            command.validate();

            Assert.AreEqual(command.Valid, false);
        }
        public CommandResult Handle(CreatePedidoCommand command)
        {
            var cliente = new Cliente(command.NomeCliente);

            var pedido = cliente.FazerPedido();

            List <Item> itens = _ItemRepository.BuscaPedidos(command.NumerosItens);

            pedido.AdicionarItens(itens);
            _PedidoRepository.Salvar(pedido);

            return(new CommandResult {
                Mensagem = "Total pedido: " + cliente.Pedido.TotalPedido(), Sucesso = true
            });
        }
        public async Task Handle_invalid_item(string produtoCodigo, string produtoNome, int produtoQuantidade, decimal produtoPrecoUnitario)
        {
            //arrange
            CancellationToken   token   = default(CancellationToken);
            CreatePedidoCommand command = new CreatePedidoCommand(new List <CreatePedidoCommandItem>
            {
                new CreatePedidoCommandItem(produtoCodigo, produtoNome, produtoQuantidade, produtoPrecoUnitario)
            }
                                                                  , "clienteId", "clienteNome", "*****@*****.**", "fone", "endereco", "complemento", "bairro", "municipio", "uf", "12345-678");
            IdentifiedCommand <CreatePedidoCommand, bool> request = new IdentifiedCommand <CreatePedidoCommand, bool>(command, Guid.NewGuid());
            var handler = new CreatePedidoCommandHandler(loggerMock.Object, pedidoRepositoryMock.Object, busMock.Object, configurationMock.Object);

            //act
            //assert
            await Assert.ThrowsAsync <InvalidItemException>(async() => await handler.Handle(request, token));
        }
        public async Task Handle_invalid_user_data(string clienteId, string clienteNome, string clienteEmail, string clienteTelefone, string clienteEndereco, string clienteComplemento, string clienteBairro, string clienteMunicipio, string clienteUF, string clienteCEP)
        {
            //arrange
            CancellationToken   token   = default(CancellationToken);
            CreatePedidoCommand command = new CreatePedidoCommand(new List <CreatePedidoCommandItem>
            {
                new CreatePedidoCommandItem("001", "produto 001", 1, 12.34m)
            }
                                                                  , clienteId, clienteNome, clienteEmail, clienteTelefone, clienteEndereco, clienteComplemento, clienteBairro, clienteMunicipio, clienteUF, clienteCEP);
            IdentifiedCommand <CreatePedidoCommand, bool> request = new IdentifiedCommand <CreatePedidoCommand, bool>(command, Guid.NewGuid());
            var handler = new CreatePedidoCommandHandler(loggerMock.Object, pedidoRepositoryMock.Object, busMock.Object, configurationMock.Object);

            //act
            //assert
            await Assert.ThrowsAsync <InvalidUserDataException>(async() => await handler.Handle(request, token));
        }
        public void PedidoValido()
        {
            var command = new CreatePedidoCommand {
                Cliente = Guid.NewGuid()
            };
            var item = new CreatePedidoItemCommand
            {
                Produto    = Guid.NewGuid(),
                Quantidade = 2
            };

            command.ItensDoPedido.Add(item);


            command.EValido()
            .Should().BeTrue(ExtrairAsNotificacoes(command));
        }
        public override Task <PedidoResponse> FazerPedido(PedidoRequest request, ServerCallContext context)
        {
            var pedidoCommand = new CreatePedidoCommand
            {
                NomeCliente  = request.NomeCliente,
                NumeroMesa   = request.NumeroMesa,
                NumerosItens = request.NumerosItens.ToList()
            };

            var response = _pedidoHandler.Handle(pedidoCommand);

            return(Task.FromResult(new PedidoResponse
            {
                Mensagem = response.Mensagem,
                Sucesso = response.Sucesso
            }));
        }
 public static IEnumerable <Guid> ExtrairProdutosIds(this CreatePedidoCommand command)
 {
     return(command.ItensDoPedido
            .Select(x => x.Produto)
            .ToList());
 }