Exemple #1
0
        public async Task <ActionResult <List <Venda> > > Simulate(
            [FromServices] ApplicationContext context,
            [FromBody] Venda model
            )
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var models = new List <Venda>();

                    var tiposVenda = await context.TiposVenda
                                     .AsNoTracking()
                                     .ToListAsync();

                    var meioPagamento = await context.MeiosPagamento
                                        .AsNoTracking()
                                        .Include(x => x.Taxa)
                                        .FirstOrDefaultAsync(x => x.Id == model.MeioPagamentoId);

                    var taxaParcela = await context.Taxas
                                      .FirstOrDefaultAsync(x => x.Id == model.TaxaParcelaId);

                    foreach (var tipo in tiposVenda)
                    {
                        model.TipoVenda     = tipo;
                        model.MeioPagamento = meioPagamento;
                        model.TaxaParcela   = taxaParcela;

                        var vendaService1 = new VendaService(model);
                        if (tipo.Nome == "PARCELADO_CLIENTE" && meioPagamento.Nome == "Débito")
                        {
                            model.Recebivel = 0.0m;
                        }
                        else
                        {
                            model.Recebivel = vendaService1.CalcularRecebivel();
                        }

                        context.Vendas.Add((Venda)model);
                        models.Add(model);
                    }
                    return(models);
                }
                catch (PagamentoException exc)
                {
                    ModelState.AddModelError("Meio de Pagamento", exc.Message);
                    return(BadRequest(ModelState));
                }
                catch (Exception exc)
                {
                    ModelState.AddModelError("Erro", exc.Message);
                    return(BadRequest(ModelState));
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
Exemple #2
0
        public void ProdutoSystemTestSetUp()
        {
            BaseSqlTest.SeedDeleteDatabase();
            BaseSqlTest.SeedInsertDatabase();

            _vendaRepository = new VendaRepository();
            _vendaService    = new VendaService(_vendaRepository);
            _vendaDefault    = VendaObjectMother.Default;
        }
        public async Task <ActionResult> Put(
            [FromServices] ApplicationContext context,
            [FromBody] Venda model,
            int id
            )
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var meioPagamento = await context.MeiosPagamento
                                        .Include(x => x.Taxa)
                                        .FirstOrDefaultAsync(x => x.Id == model.MeioPagamentoId);

                    var taxaParcela = await context.Taxas
                                      .FirstOrDefaultAsync(x => x.Id == model.TaxaParcelaId);

                    var tipoVenda = await context.TiposVenda
                                    .FirstOrDefaultAsync(x => x.Id == model.TipoVendaId);

                    model.MeioPagamento = meioPagamento;
                    model.TaxaParcela   = taxaParcela;
                    model.TipoVenda     = tipoVenda;
                    var vendaService = new VendaService(model);
                    model.Recebivel = vendaService.CalcularRecebivel();

                    model.Id = id;
                    context.Entry(model).State = EntityState.Modified;
                }
                catch (PagamentoException exc)
                {
                    ModelState.AddModelError("Meio de Pagamento", exc.Message);
                    return(BadRequest(ModelState));
                }

                try
                {
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!await VendaExistsAsync(id, context))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
            return(Ok(model));
        }
Exemple #4
0
        public void VendaService_GetAll_ShouldBeOk()
        {
            _mockRepository.Setup(m => m.GetAll()).Returns(new List <Venda>());

            VendaService service = new VendaService(_mockRepository.Object);

            IEnumerable <Venda> resultado = service.GetAll();

            resultado.Should().NotBeNull();
            _mockRepository.Verify(repository => repository.GetAll());
        }
Exemple #5
0
        public void PostService_Get_Invalid_Id_ShouldBeFail()
        {
            VendaService service = new VendaService(_mockRepository.Object);
            // Fim Cenario

            //Executa
            Action comparison = () => service.Get(0);

            //Saída
            comparison.Should().Throw <IdentifierUndefinedException>();
            _mockRepository.VerifyNoOtherCalls();
        }
Exemple #6
0
        public void VendaService_Add_ShouldBeFail()
        {
            Venda modelo = ObjectMotherVenda.getValidVenda();

            modelo.produtoVenda.DataValidade = DateTime.Now.AddDays(-9);

            VendaService service = new VendaService(_mockRepository.Object);

            Action comparison = () => service.Save(modelo);

            comparison.Should().Throw <ValidadeException>();
            _mockRepository.VerifyNoOtherCalls();
        }
Exemple #7
0
        public void VendaService_Update_Invalid_Id_ShouldBeFail()
        {
            Venda modelo = ObjectMotherVenda.getValidVenda();

            modelo.Id = 0;

            VendaService service = new VendaService(_mockRepository.Object);

            Action comparison = () => service.Update(modelo);

            comparison.Should().Throw <IdentifierUndefinedException>();
            _mockRepository.VerifyNoOtherCalls();
        }
Exemple #8
0
        public void VendaService_Get_ShouldBeOk()
        {
            Venda produto = ObjectMotherVenda.getValidVenda();

            produto.Id = 3;

            _mockRepository.Setup(m => m.Get(3)).Returns(produto);

            VendaService service   = new VendaService(_mockRepository.Object);
            Venda        resultado = service.Get(3);

            resultado.Should().NotBeNull();
            _mockRepository.Verify(repository => repository.Get(3));
        }
Exemple #9
0
        public void VendaService_Delete_ShouldBeOk()
        {
            Venda modelo = ObjectMotherVenda.getValidVenda();

            modelo.Id = 1;

            _mockRepository.Setup(m => m.Delete(modelo));


            VendaService service = new VendaService(_mockRepository.Object);

            service.Delete(modelo);

            _mockRepository.Verify(repository => repository.Delete(modelo));
        }
 public OrdemServicoService(OrdemServicoDAO dAO, UserRequest userRequest,
                            OrdemServicoProdutoDAO ordemServicoProdutoDAO, ProdutoDAO produtoDAO,
                            OrdemServicoServicoDAO ordemServicoServicoDAO, ServicoDAO servicoDAO,
                            VendaService vendaService, VendaDAO vendaDAO, UserDAO userDAO)
 {
     this.DAO                    = dAO ?? throw new ArgumentNullException(nameof(dAO));
     this.UserDAO                = userDAO ?? throw new ArgumentNullException(nameof(userDAO));
     this.VendaDAO               = vendaDAO ?? throw new ArgumentNullException(nameof(vendaDAO));
     this.ServicoDAO             = servicoDAO ?? throw new ArgumentNullException(nameof(servicoDAO));
     this.ProdutoDAO             = produtoDAO ?? throw new ArgumentNullException(nameof(produtoDAO));
     this.UserRequest            = userRequest ?? throw new ArgumentNullException(nameof(userRequest));
     this.VendaService           = vendaService ?? throw new ArgumentNullException(nameof(vendaService));
     this.OrdemServicoServicoDAO = ordemServicoServicoDAO ?? throw new ArgumentNullException(nameof(ordemServicoServicoDAO));
     this.OrdemServicoProdutoDAO = ordemServicoProdutoDAO ?? throw new ArgumentNullException(nameof(ordemServicoProdutoDAO));
 }
Exemple #11
0
        public void VendaService_Add_ShouldBeOK()
        {
            Venda produto = ObjectMotherVenda.getValidVenda();

            _mockRepository.Setup(m => m.Save(produto)).Returns(new Venda()
            {
                Id = 1
            });
            VendaService service = new VendaService(_mockRepository.Object);

            Venda resultado = service.Save(produto);

            resultado.Should().NotBeNull();
            resultado.Id.Should().BeGreaterThan(0);
            _mockRepository.Verify(repository => repository.Save(produto));
        }
        public void Inserir(Vendas venda)
        {
            _vendaService = new VendaService(conexao);
            venda.Data    = DateTime.Now;
            Clientes   cli  = conexao.Clientes.Find(venda.ClientesId);
            Vendedores vend = conexao.Vendedores.Find(venda.VendedoresId);

            venda.Clientes   = cli;
            venda.Vendedores = vend;
            _vendaService.Inserir(venda);

            int id = Connection.GetIdVenda(venda);

            // Deserializar JSON
            List <ItensVenda>     lista_itens = JsonConvert.DeserializeObject <List <ItensVenda> >(ListaProdutosVenda);
            List <VendasDetalhes> vd          = new List <VendasDetalhes>();
            var distintos = new HashSet <int>();
            var duplicado = new HashSet <int>();

            foreach (var item in lista_itens)
            {
                try {
                    VendasDetalhes details = new VendasDetalhes();
                    details.VendaId     = id;
                    details.ProdutoId   = int.Parse(item.CodigoProduto);
                    details.QtdProdutos = decimal.Parse(item.QtdProduto);
                    details.VlProduto   = decimal.Parse(item.ValorUnitario);

                    vd.Add(details);

                    var dup = vd.GroupBy(x => x.ProdutoId).Where(x => x.Count() > 1).Select(x => x.Key);
                    if (dup.Count() != 0)
                    {
                        throw new Exception();
                    }
                    else
                    {
                        _vendaService.Inserir(details);
                        Connection.UpdateQtdVendas(details.QtdProdutos, details.ProdutoId);
                    }
                }
                catch (Exception) {
                    throw;
                }
            }
        }
Exemple #13
0
        public void VendaService_Set()
        {
            _mock    = new Mock <IVendaRepository>();
            Alvo     = new VendaService(_mock.Object);
            _produto = new Produto();
            _cliente = new Cliente();

            _venda = new Venda()
            {
                Produto    = _produto,
                Id         = 1,
                Lucro      = _produto.PrecoVenda - _produto.PrecoCusto,
                Quantidade = 5,
                Cliente    = new Cliente
                {
                    Nome = "Fabricio"
                }
            };
        }
Exemple #14
0
        public VendaServiceTest()
        {
            clienteRepositoryMock
            .Setup(r => r.Existe(It.Is <Cliente>(c => c.Id == CLIENTE_ID_EXISTS)))
            .Returns(true);

            produtoRepositoryMock
            .Setup(r => r.Existe(It.Is <Produto>(p => p.Id == PRODUTO_ID_EXISTS_ONE || p.Id == PRODUTO_ID_EXISTS_TWO)))
            .Returns(true);

            vendaRepositoryMock
            .Setup(r => r.Existe(It.Is <Venda>(v => v.Id == VENDA_ID_EXISTS)))
            .Returns(true);

            vendaService = new VendaService(
                clienteRepositoryMock.Object,
                produtoRepositoryMock.Object,
                vendaRepositoryMock.Object);
        }
Exemple #15
0
        private VendaController CreateVendaController()
        {
            _mockVendaRepository.Setup(x => x.Criar(new Venda()));
            _mockPessoaRepository.Setup(x => x.ObterPorCodigo(1)).Returns(new Pessoa());
            _mockFormaPagamentoRepository.Setup(x => x.ObterPorCodigo(1)).Returns(new FormaPagamento());
            _mockCondicaoPagamentoRepository.Setup(x => x.ObterPorCodigo(1)).Returns(new CondicaoPagamento());

            var vendaService = new VendaService(_mockVendaRepository.Object, _mockItemVendaRepository.Object,
                                                _mockPessoaRepository.Object, _mockFormaPagamentoRepository.Object,
                                                _mockCondicaoPagamentoRepository.Object, _usuarioRepository.Object, _mockContaReceberRepository.Object,
                                                _estoqueRepository.Object, _produtoRepository.Object);

            var controller = new VendaController(vendaService)
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };

            return(controller);
        }
        public async Task <ActionResult <Venda> > Post(
            [FromServices] ApplicationContext context,
            [FromBody] Venda model
            )
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var meioPagamento = await context.MeiosPagamento
                                        .Include(x => x.Taxa)
                                        .FirstOrDefaultAsync(x => x.Id == model.MeioPagamentoId);

                    var taxaParcela = await context.Taxas
                                      .FirstOrDefaultAsync(x => x.Id == model.TaxaParcelaId);

                    var tipoVenda = await context.TiposVenda
                                    .FirstOrDefaultAsync(x => x.Id == model.TipoVendaId);

                    model.MeioPagamento = meioPagamento;
                    model.TaxaParcela   = taxaParcela;
                    model.TipoVenda     = tipoVenda;
                    var vendaService = new VendaService(model);
                    model.Recebivel = vendaService.CalcularRecebivel();
                    context.Vendas.Add(model);
                    var savedModel = await context.SaveChangesAsync();

                    return(model);
                }
                catch (PagamentoException exc)
                {
                    ModelState.AddModelError("Meio de Pagamento", exc.Message);
                    return(BadRequest(ModelState));
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
Exemple #17
0
        public void VendaService_Update_ShouldBeOK()
        {
            Venda produto = ObjectMotherVenda.getValidVenda();

            produto.Id = 2;

            _mockRepository.Setup(m => m.Update(produto)).Returns(new Venda()
            {
                Id         = 2,
                cliente    = "Pedro",
                quantidade = 1
            });

            VendaService service = new VendaService(_mockRepository.Object);


            Venda resultado = service.Update(produto);

            resultado.Should().NotBeNull();
            resultado.cliente.Should().Be("Pedro");
            _mockRepository.Verify(repository => repository.Update(produto));
        }
Exemple #18
0
 public void Setup()
 {
     BaseSqlTest.SeedDatabase();
     _repository = new VendaRepository();
     _service    = new VendaService(_repository);
 }
Exemple #19
0
 public VendaController(VendaService vendaService, IHttpContextAccessor httpContextAccessor)
 {
     _vendaService = vendaService;
     httpContext   = httpContextAccessor;
 }
Exemple #20
0
 public VendaController(VendaService vendaService, ComandaService comandaService)
 {
     _vendaService   = vendaService;
     _comandaService = comandaService;
 }
Exemple #21
0
 public VendaController()
 {
     _service        = new VendaService(new VendaRepository());
     _clienteService = new ClienteService(new ClienteRepository());
     _produtoService = new ProdutoService(new ProdutoRepository());
 }
Exemple #22
0
 public VendaController(VendaService servico)
 {
     _servico = servico;
 }
Exemple #23
0
 public void ProdutoServiceTestSetUp()
 {
     _vendaRepositoryMockObject = new Mock <IVendaRepository>();
     _vendaService      = new VendaService(_vendaRepositoryMockObject.Object);
     _vendaefaultWithId = VendaObjectMother.DefaultWithId;
 }
Exemple #24
0
 public VendasController(VendaService vendaService, VendedorService vendedorService, ProdutoService produtoService)
 {
     _vendaService    = vendaService;
     _vendedorService = vendedorService;
     _produtoService  = produtoService;
 }
Exemple #25
0
 public VendaController()
 {
     vendaService = new VendaService(NHibernateHelper.OpenSession());
 }
Exemple #26
0
 public VendaController(VendaService VendaService)
 {
     _VendaService = VendaService;
 }
Exemple #27
0
 public void TesteSetup()
 {
     _mockVendaRepository = new Mock <IVendaRepository>();
     _vendaService        = new VendaService(_mockVendaRepository.Object);
     _mockProduto         = new Mock <Produto>();
 }
Exemple #28
0
 public VendaController(VendaService service)
 {
     _service = service;
 }
 public VendaController(VendaDAO dAO, VendaService vendaService)
 {
     VendaService = vendaService ?? throw new ArgumentNullException(nameof(vendaService));
 }
Exemple #30
0
 public VendaController()
 {
     AutoMapperHelper.InitializeMapper();
     Service = new VendaService();
 }