예제 #1
0
        public async Task <bool> Handle(CriarPedidoCommand request, CancellationToken cancellationToken)
        {
            var tabelaCashbackVigente = await _mediator.Send(new ObterVigenteQuery());

            var novoPedido = _mapper.Map <PedidoEntity>(request);

            novoPedido.IdTabelaCashback = tabelaCashbackVigente.IdTabelaCashback;

            request.Itens.ForEach(item =>
            {
                var valoresProduto          = calcularValoresProduto(tabelaCashbackVigente, item.IdProduto);
                var novoItem                = _mapper.Map <Pedido_ItemEntity>(item);
                novoItem.ValorUnitario      = valoresProduto.ValorUnitario;
                novoItem.PercentualCashback = valoresProduto.PercentualCashback;
                novoPedido.Itens.Add(novoItem);
            });

            novoPedido.ValorPedido = novoPedido.Itens.Sum(a => a.ValorUnitario * a.Quantidade);

            if (novoPedido.Invalido)
            {
                _validation.AddRange(novoPedido.Mensagens);
                return(false);
            }

            var result = await _repository.CriarPedido(novoPedido);

            if (result > 0)
            {
                await _mediator.Publish(new PedidoCriadoNotification(result));
            }

            return(true);
        }
예제 #2
0
        public async Task DadoQueEsteDronePossuaUmPedidoPago()
        {
            //criar pedido
            var command = new CriarPedidoCommand(1000, 999);
            await _testsFixture.Client.PostAsJsonAsync("/api/pedidos", command);

            var response = await _testsFixture.Client.GetAsync("/api/pedidos");

            var data = await response.Content.ReadAsStringAsync();

            var pedidos = JsonConvert.DeserializeObject <PedidosTestDto>(data);

            var pedido = pedidos.Pedidos.FirstOrDefault();

            if (pedido == null)
            {
                throw new Exception("Para rodar os testes de integração é necessário que os dois microserviços sejam executados juntos");
            }

            var respPagamentoDto = new CriarRepostaPagamentoDtoTests
            {
                Id     = pedido.Id,
                Status = PedidoStatus.Pago
            };
            await _testsFixture.Client.PostAsJsonAsync("/api/pedidos/atualizarstatus", respPagamentoDto);
        }
예제 #3
0
        public async Task <IActionResult> CriarPedido([FromBody] CriarPedidoCommand comand)
        {
            _pedidoRepository.Add(comand.Map());
            var result = await _pedidoRepository.UnitOfWork.Commit();

            return(Ok());
        }
        public async Task <IActionResult> CriarAsync([FromBody] PedidoDto dto)
        {
            var command = new CriarPedidoCommand(dto.ComandaId, dto.Observacao, dto.Itens);
            await CommandDispatcher.HandleAsync(command);

            await UnitOfWork.CommitAsync();

            _hub.Clients.All.SendAsync("PedidoCriado");
            return(Ok());
        }
        public async Task DadoQueEuTenhaUmPedidoQueFoiPagoEEstejaAguardandoAprovacao()
        {
            var command = new CriarPedidoCommand(Guid.NewGuid(), 999);

            _context.Add("pedido", command);
            await _testsFixture.Client.PostAsJsonAsync("/api/pedidos", command);

            var commandPagamento = new CriarPagamentoCommand("4242424242424242", DateTime.Now.AddDays(1), 123);
            await _testsFixture.Client.PostAsJsonAsync($"/api/pagamentos/{command.Id}", commandPagamento);
        }
예제 #6
0
        public async Task DadoQueEuTenhaUmPedidoParaPagamentoRecebaUmNumeroCartaoVencimentoCodigoSeguranca(string p0, string p1, int p2)
        {
            var command = new CriarPedidoCommand(Guid.NewGuid(), 999);

            await _testsFixture.Client.PostAsJsonAsync("/api/pedidos", command);

            _context.Add("pedido", command);
            _context.Add("numeroCartao", p0);
            _context.Add("vencimento", Convert.ToDateTime(p1));
            _context.Add("codigoSeguranca", p2);
        }
예제 #7
0
        public async Task <IActionResult> Adicionar(CriarPedidoCommand command)
        {
            var response = await EventBus.SendCommand(command);

            if (response.HasFails)
            {
                return(BadRequest(response.Fails));
            }

            return(Ok());
        }
예제 #8
0
        public async Task Pedido_AoCriarumPedidoComComandoInvalido_RetornarNotificacoesComFalha()
        {
            // Arrange
            var command = new CriarPedidoCommand(0, 0);

            // Act
            var responseResult = await _handler.Handle(command, CancellationToken.None);

            // Assert
            Assert.True(responseResult.HasFails);
        }
예제 #9
0
        public async Task QuandoEuSolicitarACriacaoDeUmPedido()
        {
            var pedido = new CriarPedidoCommand(10000, 100);

            await _testsFixture.RealizarLoginApi();

            _testsFixture.Client.AddToken(_testsFixture.Token);

            var postResponse = await _testsFixture.Client.PostAsJsonAsync("/api/pedidos", pedido);

            _context.Set(postResponse);
        }
        public async Task DadoQueEsteDronePossuaUmPedidoPago()
        {
            //criar pedido
            var command = new CriarPedidoCommand(Guid.NewGuid(), 1000, 999);
            await _testsFixture.Client.PostAsJsonAsync("/api/pedidos", command);

            var respPagamentoDto = new CriarRepostaPagamentoDtoTests
            {
                Id     = command.Id,
                Status = PedidoStatus.Pago
            };
            await _testsFixture.Client.PostAsJsonAsync("/api/pedidos/atualizarstatus", respPagamentoDto);
        }
예제 #11
0
        public async Task CriarPedido_Sucesso()
        {
            _repository.Setup(m => m.CriarPedido(NovoPedido())).Returns(Task.FromResult(1));
            var command = new CriarPedidoCommand(1,
                                                 new List <CriarPedido_ItemCommand> {
                new CriarPedido_ItemCommand(0, 1, 10),
                new CriarPedido_ItemCommand(0, 2, 10)
            });

            // Act
            var result = await _commandHandler.Handle(command, new CancellationToken(false));

            // Assert
            Assert.True(result);
        }
        public async Task DeveRetornarErroSeGarcomComandaNaoExisteNoBanco()
        {
            var handler = new PedidoCommandHandler(
                _pedidoRepository,
                _garcomRepository,
                _comandaRepository,
                _historicoPedidoRepository,
                _produtoPedidoRepository,
                _clienteRepository,
                _mediator);
            var command = new CriarPedidoCommand(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), _helperEntitiesTest.ProdutosPedido);

            var retorno = await handler.Handle(command, new CancellationToken());

            Assert.Equal(Guid.Empty, retorno);
        }
예제 #13
0
        public async Task Pedido_AoCriarUmPedido_RetornarSucesso()
        {
            // Arrange
            var command = new CriarPedidoCommand(1000, 1000);

            var usuarioId = Guid.NewGuid();

            //Usuario autenticado nao retorna nada
            _mocker.GetMock <IUsuarioAutenticado>()
            .Setup(p => p.GetCurrentId())
            .Returns(usuarioId);

            //Obter usuario
            var usuario = Usuario.Criar("test", "*****@*****.**", 0, 0, UsuarioRole.Cliente);

            _mocker.GetMock <IUnitOfWork>()
            .Setup(p => p.Usuarios.ObterPorIdAsync(usuarioId))
            .Returns(Task.FromResult(usuario));

            _mocker.GetMock <IPagamentoHttpFactory>()
            .Setup(p => p.EnviarPedidoParaPagamento(It.IsAny <PedidoCriadoEvent>()));

            //adicionar pedido
            _mocker.GetMock <IUnitOfWork>()
            .Setup(p => p.Pedidos.AdicionarAsync(It.IsAny <Pedido>()))
            .Returns(Task.CompletedTask);

            //Salvar operação
            _mocker.GetMock <IUnitOfWork>()
            .Setup(p => p.SaveAsync())
            .Returns(Task.CompletedTask);

            // Act
            var responseResult = await _handler.Handle(command, CancellationToken.None);

            // Assert
            Assert.False(responseResult.HasFails);
        }
        public async Task Pedido_CriarPedido_Retornar200OKSucesso()
        {
            // Arrange
            var drone = new CriarDroneCommand(12000, 3.333, 35, 100);

            await _testsFixture.RealizarLoginApi();

            _testsFixture.Client.AddToken(_testsFixture.Token);
            await _testsFixture.Client.PostAsJsonAsync("/api/drones", drone);

            // Arrange
            var pedido = new CriarPedidoCommand(10000, 100);

            await _testsFixture.RealizarLoginApi();

            _testsFixture.Client.AddToken(_testsFixture.Token);

            // Act
            var postResponse = await _testsFixture.Client.PostAsJsonAsync("/api/pedidos", pedido);

            // Assert
            postResponse.EnsureSuccessStatusCode();
        }
예제 #15
0
        public async Task Pedido_AoCriarumPedidoComClienteNaoAutenticado_RetornarNotificacoesComFalha()
        {
            // Arrange
            var command = new CriarPedidoCommand(1000, 1000);

            var usuarioId = Guid.NewGuid();

            //Usuario autenticado nao retorna nada
            _mocker.GetMock <IUsuarioAutenticado>()
            .Setup(p => p.GetCurrentId());

            //Obter usuario
            _mocker.GetMock <IUnitOfWork>()
            .Setup(p => p.Usuarios.ObterPorIdAsync(usuarioId));

            // Act
            var responseResult = await _handler.Handle(command, CancellationToken.None);

            // Assert
            Assert.True(responseResult.HasFails);
            Assert.True(responseResult.Fails.Count() == 1);
            Assert.NotNull(responseResult.Fails.Select(x => x.Message == Erros.ErroCliente_NaoEncontrado));
        }
예제 #16
0
        public void Criar(Pedido pedido)
        {
            CriarPedidoCommand command = new CriarPedidoCommand(pedido.Status, pedido.Entregue, pedido.Cancelado, pedido.Total, pedido.Id_loja, pedido.Id_pagamentoTipo, pedido.Cliente, pedido.Pedido_Produtos);

            _bus.SendCommand(command);
        }