public void QuandoOcorrerErroAoAtualizarUmaListaDeCondicoesDePagamentoDeveRetornarStatusDeErro()
        {
            var cadastroCondicaoPagamentoMock = new Mock <ICadastroCondicaoPagamento>(MockBehavior.Strict);

            cadastroCondicaoPagamentoMock.Setup(x => x.AtualizarCondicoesDePagamento(It.IsAny <IList <CondicaoDePagamentoCadastroVm> >()))
            .Throws(new Exception("Ocorreu um erro ao atualizar as condições de pagamento"));
            var condicaoPagamentoApiController = new CondicaoPagamentoApiController(cadastroCondicaoPagamentoMock.Object);
            var condicaoPagamentoCadastroVm    = new CondicaoDePagamentoCadastroVm()
            {
                Codigo    = "C001",
                Descricao = "CONDICAO 001"
            };

            condicaoPagamentoApiController.Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/CondicaoPagamentoApi/PostMultiplo");
            condicaoPagamentoApiController.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

            var resposta = condicaoPagamentoApiController.PostMultiplo(new ListaCondicaoPagamento()
            {
                condicaoPagamentoCadastroVm
            });
            var apiResponseMessage = (ApiResponseMessage)((ObjectContent)(resposta.Content)).Value;

            Assert.AreEqual(HttpStatusCode.OK, resposta.StatusCode);
            Assert.AreEqual("500", apiResponseMessage.Retorno.Codigo);
            cadastroCondicaoPagamentoMock.Verify(x => x.AtualizarCondicoesDePagamento(It.IsAny <IList <CondicaoDePagamentoCadastroVm> >()), Times.Once());
        }
 private void AtualizarCondicaoDePagamento(CondicaoDePagamentoCadastroVm condicaoDePagamentoCadastroVm)
 {
     CondicaoDePagamento condicaoDePagamento =
         _condicoesDePagamentoConsultadas.SingleOrDefault(x => x.Codigo == condicaoDePagamentoCadastroVm.Codigo);
     if (condicaoDePagamento != null)
     {
         condicaoDePagamento.AtualizarDescricao(condicaoDePagamentoCadastroVm.Descricao);
     }
     else
     {
         condicaoDePagamento = new CondicaoDePagamento(condicaoDePagamentoCadastroVm.Codigo,
                                                       condicaoDePagamentoCadastroVm.Descricao);
     }
     _condicoesDePagamento.Save(condicaoDePagamento);
 }
 public void Novo(CondicaoDePagamentoCadastroVm condicaoDePagamentoCadastroVm)
 {
     try
     {
         _unitOfWork.BeginTransaction();
         var condicaoDePagamento = new CondicaoDePagamento(condicaoDePagamentoCadastroVm.CodigoSap, condicaoDePagamentoCadastroVm.Descricao);
         _condicoesDePagamento.Save(condicaoDePagamento);                
         _unitOfWork.Commit();
     }
     catch (Exception)
     {
         _unitOfWork.RollBack();                
         throw;
     }
 }
Пример #4
0
        private void AtualizarCondicaoDePagamento(CondicaoDePagamentoCadastroVm condicaoDePagamentoCadastroVm)
        {
            CondicaoDePagamento condicaoDePagamento =
                _condicoesDePagamentoConsultadas.SingleOrDefault(x => x.Codigo == condicaoDePagamentoCadastroVm.Codigo);

            if (condicaoDePagamento != null)
            {
                condicaoDePagamento.AtualizarDescricao(condicaoDePagamentoCadastroVm.Descricao);
            }
            else
            {
                condicaoDePagamento = new CondicaoDePagamento(condicaoDePagamentoCadastroVm.Codigo,
                                                              condicaoDePagamentoCadastroVm.Descricao);
            }
            _condicoesDePagamento.Save(condicaoDePagamento);
        }
        public IList <CondicaoDePagamentoCadastroVm> Listar(PaginacaoVm paginacaoVm, CondicaoDePagamentoCadastroVm filtro)
        {
            if (!string.IsNullOrEmpty(filtro.Codigo))
            {
                _condicoesDePagamento.BuscaPeloCodigo(filtro.Codigo);
            }

            if (!string.IsNullOrEmpty(filtro.Descricao))
            {
                _condicoesDePagamento.FiltraPelaDescricao(filtro.Descricao);
            }
            int skip = (paginacaoVm.Page - 1) * paginacaoVm.PageSize;

            //paginacaoVm.TotalRecords = _condicoesDePagamento.Count();

            return(_builder.BuildList(_condicoesDePagamento.Skip(skip).Take(paginacaoVm.Take).List()));
        }
        public IList<CondicaoDePagamentoCadastroVm> Listar(PaginacaoVm paginacaoVm, CondicaoDePagamentoCadastroVm filtro)
        {
            if (!string.IsNullOrEmpty(filtro.Codigo))
            {
                _condicoesDePagamento.BuscaPeloCodigo(filtro.Codigo);

            }

            if (!string.IsNullOrEmpty(filtro.Descricao))
            {
                _condicoesDePagamento.FiltraPelaDescricao(filtro.Descricao);
            }
            int skip = (paginacaoVm.Page - 1) * paginacaoVm.PageSize;

            return _builder.BuildList(_condicoesDePagamento.Skip(skip).Take(paginacaoVm.Take).List());
            
        }
        public CadastroCondicaoPagamentoTests()
        {
            _condicoesRepositorio     = new List <CondicaoDePagamento>();
            _unitOfWorkMock           = CommonMocks.DefaultUnitOfWorkMock();
            _condicoesDePagamentoMock = new Mock <ICondicoesDePagamento>(MockBehavior.Strict);
            _condicoesDePagamentoMock.Setup(x => x.Save(It.IsAny <CondicaoDePagamento>()))
            .Callback((CondicaoDePagamento condicaoDePagamento) =>
            {
                Assert.IsNotNull(condicaoDePagamento);
                //callback assegura que a transação foi iniciada  e não foi fechada antes de salvar
                _unitOfWorkMock.Verify(x => x.BeginTransaction(), Times.Once());
                _unitOfWorkMock.Verify(x => x.Commit(), Times.Never());
            });
            _condicoesDePagamentoMock.Setup(x => x.FiltraPorListaDeCodigos(It.IsAny <string[]>()))
            //callback assegura que a transação foi iniciada e não foi fechada antes de consultar
            .Callback((string[] codigos) =>
            {
                _unitOfWorkMock.Verify(x => x.BeginTransaction(), Times.Once());
                _unitOfWorkMock.Verify(x => x.Commit(), Times.Never());
                if (codigos.Contains("C001"))
                {
                    _condicoesRepositorio.Add(new CondicaoDePagamentoParaAtualizacao("C001", "CONDICAO 001"));
                }
            })
            .Returns(_condicoesDePagamentoMock.Object);

            _condicoesDePagamentoMock.Setup(x => x.List()).Returns(_condicoesRepositorio);

            _cadastroCondicaoPagamento = new CadastroCondicaoPagamento(_unitOfWorkMock.Object, _condicoesDePagamentoMock.Object);
            _condicaoPagamento01       = new CondicaoDePagamentoCadastroVm()
            {
                Codigo    = "C001",
                Descricao = "CONDICAO 001"
            };

            _condicaoPagamento02 = new CondicaoDePagamentoCadastroVm()
            {
                Codigo    = "C002",
                Descricao = "CONDICAO 002"
            };

            _condicoesDePagamento = new List <CondicaoDePagamentoCadastroVm>()
            {
                _condicaoPagamento01, _condicaoPagamento02
            };
        }
        public IList<CondicaoDePagamentoCadastroVm> Listar(PaginacaoVm paginacaoVm, CondicaoDePagamentoCadastroVm filtro)
        {
            if (!string.IsNullOrEmpty(filtro.CodigoSap))
            {
                _condicoesDePagamento.BuscaPeloCodigoSap(filtro.CodigoSap);

            }

            if (!string.IsNullOrEmpty(filtro.Descricao))
            {
                _condicoesDePagamento.FiltraPelaDescricao(filtro.Descricao);
            }
            int skip = (paginacaoVm.Page - 1) * paginacaoVm.PageSize;

            paginacaoVm.TotalRecords = _condicoesDePagamento.Count();

            var builder = new CondicaoPagamentoCadastroBuilder();
            return builder.BuildList(_condicoesDePagamento.Skip(skip).Take(paginacaoVm.Take).List());
            
        }
        public void QuandoAtualizarUmaListaDeCondicoesDePagamentoComSucessoDeveRetornarStatusOk()
        {
            var cadastroCondicaoPagametoMock = new Mock <ICadastroCondicaoPagamento>(MockBehavior.Strict);

            cadastroCondicaoPagametoMock.Setup(x => x.AtualizarCondicoesDePagamento(It.IsAny <IList <CondicaoDePagamentoCadastroVm> >()));
            var condicaoPagamentoApiController = new CondicaoPagamentoApiController(cadastroCondicaoPagametoMock.Object);
            var condicaoPagamentoCadastroVm    = new CondicaoDePagamentoCadastroVm()
            {
                Codigo    = "C001",
                Descricao = "CONDICAO 001"
            };

            condicaoPagamentoApiController.Request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/CondicaoPagamentoApi/PostMultiplo");
            condicaoPagamentoApiController.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());

            var resposta = condicaoPagamentoApiController.PostMultiplo(new ListaCondicaoPagamento()
            {
                condicaoPagamentoCadastroVm
            });

            Assert.AreEqual(HttpStatusCode.OK, resposta.StatusCode);
            cadastroCondicaoPagametoMock.Verify(x => x.AtualizarCondicoesDePagamento(It.IsAny <IList <CondicaoDePagamentoCadastroVm> >()), Times.Once());
        }