public async Task CriarPedidoAsync() { var pedido = new PedidoFacade(_pedidoService, _clienteRepository, _pedidoRepository, _droneRepository, _pagamentoServiceFactory, _pedidoDroneRepository); _clienteRepository.GetByIdAsync(Arg.Any <int>()).Returns(SetupTests.GetCliente()); _pagamentoServiceFactory.GetPagamentoServico(ETipoPagamento.CARTAO).Returns(_pagamentoServico); _pagamentoServico.RequisitaPagamento(Arg.Any <Pagamento>()).Returns(SetupTests.GetPagamento()); var result = await pedido.CreatePedidoAsync(SetupTests.GetPedido()); Assert.NotNull(result); }
public async Task <Pedido> CreatePedidoAsync(Pedido pedido) { if (pedido.EValido()) { pedido.Cliente = await _clienteRepository.GetByIdAsync(pedido.ClienteId); pedido.DataHoraInclusao = DateTime.Now; pedido.Situacao = (int)StatusPedido.AGUARDANDO_PAGAMENTO; var servicoPagamento = _pagamentoServiceFactory.GetPagamentoServico(pedido.Pagamento.TipoPagamento); var responseGateway = await servicoPagamento.RequisitaPagamento(pedido.Pagamento); pedido.GatewayPagamentoId = responseGateway.Id.ToString(); await _pedidoRepository.AddAsync(pedido); return(pedido); } else { throw new Exception("Pedido inválido"); } }