Ejemplo n.º 1
0
 private void AdicionarItens(VendaEntity venda, VendaDTO vendaDTO)
 {
     if (vendaDTO.Itens == null)
     {
         return;
     }
     foreach (var item in vendaDTO.Itens)
     {
         var vendaItem = new VendaItemEntity(item, new CalculadoraPrecoVendaItem());
         venda.AdicionarVendaItem(vendaItem);
     }
 }
Ejemplo n.º 2
0
        private VendaEntity VendaFactory(VendaDTO vendaDTO)
        {
            var venda = new VendaEntity(vendaDTO.Cliente, vendaDTO.FormaDePagamento);

            if (vendaDTO.Itens == null)
            {
                return(venda);
            }
            foreach (var item in vendaDTO.Itens)
            {
                var vendaItem = new VendaItemEntity(item, new CalculadoraPrecoVendaItem());
                venda.AdicionarVendaItem(vendaItem);
            }
            return(venda);
        }
Ejemplo n.º 3
0
        public void TestCapturaErrosDeVendaItem()
        {
            var vendaItemErros = new List <ValidationResult> {
                new ValidationResult("Erro no Item de venda")
            };
            var vendaItemMock = new Mock <VendaItemEntity>(MockBehavior.Strict);

            vendaItemMock
            .Setup(vi => vi.Validate())
            .Returns(vendaItemErros);
            vendaItemMock
            .Setup(vi => vi.ValorTotal(It.IsAny <FormaDePagamento>()))
            .Returns(10);
            VendaEntity venda = new VendaEntity(new ClienteDTO("Cliente"), FormaDePagamento.Dinheiro);

            venda.AdicionarVendaItem(vendaItemMock.Object);

            var listaErrosEncontrados = venda.Validate();

            Assert.Equal(vendaItemErros, listaErrosEncontrados);
        }
Ejemplo n.º 4
0
        public void TestCriarVendaComFormaDePagamento(FormaDePagamento formaDePagamento)
        {
            var cliente  = new ClienteDTO("Cliente");
            var vendaDTO = new VendaDTO()
            {
                Cliente          = cliente,
                FormaDePagamento = formaDePagamento,
                Itens            = new List <VendaItemDTO>()
            };

            VendaEntity venda = new VendaEntity(vendaDTO.Cliente, vendaDTO.FormaDePagamento);

            foreach (var item in vendaDTO.Itens)
            {
                var vendaItem = new VendaItemEntity(item, new CalculadoraPrecoVendaItem());
                venda.AdicionarVendaItem(vendaItem);
            }

            ClienteDTO clienteRetornado = venda.Cliente;

            Assert.Equal(formaDePagamento, venda.FormaDePagamento);
            Assert.Equal(cliente, clienteRetornado);
        }