Esempio n. 1
0
        public void Atualizar(Anuncio anuncio)
        {
            ValidarAnuncio(anuncio);

            this.repositorioDeAutomovel.Atualizar(anuncio.Automovel);
            this.repositorioDeAnuncios.Atualizar(anuncio);
        }
Esempio n. 2
0
        public Uri IncluirPagamentoDoAnuncio(Anuncio anuncio)
        {
            Uri uri = null;
            Pagamento pagamento = new Pagamento(anuncio);

            if (anuncio == null || anuncio.Plano == null)
            {
                throw new ArgumentNullException();
            }

            if (!anuncio.Plano.Ativo)
            {
                throw new Exception("Plano inválido");
            }

            pagamento.Status = StatusPagamento.AguardandoPagamento;

            repositorioPagamento.Incluir(pagamento);

            if (anuncio.Plano.Valor == 0)
            {
                this.Pagar(pagamento);
            }
            else
            {
                uri = this.servicoPagamentoPagSeguro.RequisitarPagamento(pagamento);
            }

            return uri;
        }
        public EstatisticaAnuncio ObterEstatisticaDoAnuncio(Anuncio anuncio)
        {
            if (anuncio == null)
            {
                throw new ArgumentNullException();
            }

            return this.repositorioEstatisticaAnuncio.ObterEstatisticaDoAnuncio(anuncio);
        }
        public void ObterEstatisticaDoAnuncio_Anuncio_Valido_Chama_Repositorio_ObterEstatisticaDoAnuncio_Retorna_Estatistica()
        {
            Anuncio anuncio = new Anuncio(null, new Automovel(new Modelo()), null);
            EstatisticaAnuncio estatistaAnuncio = new EstatisticaAnuncio(anuncio);

            repositorioEstatisticaAnuncioMock.Setup(r => r.ObterEstatisticaDoAnuncio(anuncio)).Returns(estatistaAnuncio);

            Assert.AreEqual(estatistaAnuncio, target.ObterEstatisticaDoAnuncio(anuncio));
            repositorioEstatisticaAnuncioMock.Verify(r => r.ObterEstatisticaDoAnuncio(anuncio));
        }
Esempio n. 5
0
        public void AprovarAnuncio(Anuncio anuncio)
        {
            if (anuncio == null)
            {
                throw new ArgumentNullException();
            }

            anuncio.Status = StatusAnuncio.Aprovado;

            this.Atualizar(anuncio);
        }
Esempio n. 6
0
        public void Excluir(Anuncio anuncio)
        {
            if (anuncio == null)
            {
                throw new ArgumentNullException();
            }

            this.repositorioDeAutomovel.Excluir(anuncio.Automovel);
            this.repositorioEstatisticaAnuncio.Excluir(this.repositorioEstatisticaAnuncio.ObterEstatisticaDoAnuncio(anuncio));

            this.repositorioDeAnuncios.Excluir(anuncio);
        }
Esempio n. 7
0
        public void Anunciar(Anuncio anuncio)
        {
            ValidarAnuncio(anuncio);

            repositorioDeAutomovel.Incluir(anuncio.Automovel);
            servicoDeAnunciante.Incluir(anuncio.Anunciante);

            anuncio.Data = DateTime.Now;
            anuncio.Status = StatusAnuncio.AguardandoAprovacao;

            this.repositorioDeAnuncios.Anuciar(anuncio);
            this.repositorioEstatisticaAnuncio.Incluir(new EstatisticaAnuncio(anuncio));
        }
        public void VisualizarAnuncio_Anuncio_Com_Estatistica_Incrementa_VisualizacoesAnuncio_Chama_Repositorio_Incluir_Atualizar()
        {
            uint visitas = 10;
            Anuncio anuncio = new Anuncio(null, new Automovel(new Modelo()), null);
            EstatisticaAnuncio estatistaAnuncio = new EstatisticaAnuncio(anuncio) { VisualizacoesAnuncio = visitas } ;

            repositorioEstatisticaAnuncioMock.Setup(r => r.ObterEstatisticaDoAnuncio(anuncio)).Returns(estatistaAnuncio);

            target.VisualizarAnuncio(anuncio);

            repositorioEstatisticaAnuncioMock.Verify(r => r.ObterEstatisticaDoAnuncio(anuncio));
            repositorioEstatisticaAnuncioMock.Verify(r => r.Atualizar(estatistaAnuncio));
            Assert.AreEqual(++visitas, estatistaAnuncio.VisualizacoesAnuncio);
        }
Esempio n. 9
0
        public void Anunciar_Anuncio_Invalido_Dispara_Exception_4_Erros()
        {
            Anuncio anuncio = new Anuncio(new Anunciante(), new Automovel(null), new Plano() { Ativo = false });

            try
            {
                target.Anunciar(anuncio);
            }
            catch (Exception ex)
            {
                Assert.AreEqual(4, ex.Message.Split('\n').Where(e => !string.IsNullOrEmpty(e)).Count());
                throw;
            }
        }
Esempio n. 10
0
        public void Anunciar_Anuncio_Valido_Chama_Servico_Incluir_Anunciante_Automovel__Estatistica_DataAnuncio_Atual_Status_AguardandoAprovacao()
        {
            Automovel automovel = new Automovel(new Modelo()) { ParcelasRestantes = 1, ValorParcela = 10.00M };
            Anunciante anunciante = new Anunciante();
            Anuncio anuncio = new Anuncio(anunciante, automovel, new Plano() { Ativo = true });
            EstatisticaAnuncio estatisticaAnuncio = new EstatisticaAnuncio(anuncio);

            target.Anunciar(anuncio);

            servicoAnuncianteMock.Verify(s => s.Incluir(anunciante));
            repositorioAutomovelMock.Verify(s => s.Incluir(automovel));
            repositorioEstatisticaAnuncioMock.Verify(s => s.Incluir(estatisticaAnuncio));
            repositorioAnuncioMock.Verify(s => s.Anuciar(anuncio));

            Assert.AreEqual(DateTime.Now.ToShortDateString(), anuncio.Data.ToShortDateString());
            Assert.AreEqual(StatusAnuncio.AguardandoAprovacao, anuncio.Status);
        }
        public void VisualizarTelefoneDoAnuncio(Anuncio anuncio)
        {
            if (anuncio == null)
            {
                throw new ArgumentNullException();
            }

            EstatisticaAnuncio estatisticaAnuncio = this.ObterEstatisticaDoAnuncio(anuncio);

            if (estatisticaAnuncio == null)
            {
                throw new Exception("Anúncio inválido.");
            }

            estatisticaAnuncio.VisualizacoesTelefone++;

            this.repositorioEstatisticaAnuncio.Atualizar(estatisticaAnuncio);
        }
Esempio n. 12
0
        public void ObterAnuncioPorId_IdAnuncio_Valido_Retorna_Anuncio_Chama_Repositorio_ObterAnuncioPorId()
        {
            Anuncio anuncio = new Anuncio(null, null, null) { Id = 1 };

            repositorioAnuncioMock.Setup(r => r.ObterAnuncioPorId(anuncio.Id)).Returns(anuncio);

            Assert.AreEqual(anuncio, target.ObterAnuncioPorId(anuncio.Id));
            repositorioAnuncioMock.Verify(r => r.ObterAnuncioPorId(anuncio.Id));
        }
Esempio n. 13
0
        public void Excluir_Anuncio_Valido_Chama_Servico_Excluir_Automovel_Repositorio_Excluir()
        {
            Automovel automovel = new Automovel(new Modelo());
            Anunciante anunciante = new Anunciante();
            Anuncio anuncio = new Anuncio(anunciante, automovel, new Plano() { Ativo = true });
            EstatisticaAnuncio estatisticaAnuncio = new EstatisticaAnuncio(anuncio);

            repositorioEstatisticaAnuncioMock.Setup(s => s.ObterEstatisticaDoAnuncio(anuncio)).Returns(estatisticaAnuncio);

            target.Excluir(anuncio);

            repositorioAutomovelMock.Verify(s => s.Excluir(automovel));
            repositorioEstatisticaAnuncioMock.Verify(s => s.Excluir(estatisticaAnuncio));
            repositorioAnuncioMock.Verify(s => s.Excluir(anuncio));
        }
Esempio n. 14
0
 public void Atualizar_Automovel_Do_Anuncio_Nulo_Dispara_ArgumentNullException()
 {
     Anuncio anuncio = new Anuncio(new Anunciante(), null, new Plano());
     target.Atualizar(anuncio);
 }
Esempio n. 15
0
        public void Atualizar_Anuncio_Valido_Chama_Servico_Atualizar_Automovel_Repositorio_Atualizar()
        {
            Automovel automovel = new Automovel(new Modelo()) { ParcelasRestantes = 1, ValorParcela = 10.00M };
            Anunciante anunciante = new Anunciante();
            Anuncio anuncio = new Anuncio(anunciante, automovel, new Plano() { Ativo = true });

            target.Atualizar(anuncio);

            repositorioAutomovelMock.Verify(s => s.Atualizar(automovel));
            repositorioAnuncioMock.Verify(s => s.Atualizar(anuncio));
        }
Esempio n. 16
0
 public void DesaprovarAnuncio(Anuncio anuncio)
 {
     anuncio.Status = StatusAnuncio.Desaprovado;
     this.AtualizarAnuncio(anuncio);
 }
Esempio n. 17
0
 public void ExcluirAnuncio(Anuncio anuncio)
 {
     this.repositorioDeAnuncios.ExcluirAnuncio(anuncio);
 }
Esempio n. 18
0
        public Pagamento ObterPagamentoDoAnuncio(Anuncio anuncio)
        {
            if (anuncio == null)
            {
                throw new ArgumentNullException();
            }

            return this.repositorioPagamento.ObterPagamentoDoAnuncio(anuncio);
        }
Esempio n. 19
0
 public void AtualizarAnuncio(Anuncio anuncio)
 {
     //validar
     this.repositorioDeAnuncios.AtualizarAnuncio(anuncio);
 }
Esempio n. 20
0
        public void ReprovarAnuncio_Anuncio_Valido_Chama_Atualizar_Automovel_Chama_Repositorio()
        {
            Automovel automovel = new Automovel(new Modelo()) { ParcelasRestantes = 1, ValorParcela = 10.00M };
            Anunciante anunciante = new Anunciante();
            Anuncio anuncio = new Anuncio(anunciante, automovel, new Plano() { Ativo = true });

            target.ReprovarAnuncio(anuncio);

            repositorioAutomovelMock.Verify(s => s.Atualizar(automovel));
            repositorioAnuncioMock.Verify(s => s.Atualizar(anuncio));
            Assert.AreEqual(StatusAnuncio.Reprovado, anuncio.Status);
        }
Esempio n. 21
0
 public Pagamento(Anuncio anuncio)
 {
     this.Anuncio = anuncio;
 }
Esempio n. 22
0
 public EstatisticaAnuncio(Anuncio anuncio)
 {
     this.Anuncio = anuncio;
 }
Esempio n. 23
0
        private void ValidarAnuncio(Anuncio anuncio)
        {
            if (anuncio == null || anuncio.Plano == null || anuncio.Automovel == null)
            {
                throw new ArgumentNullException();
            }

            StringBuilder erros = new StringBuilder();

            if (anuncio.Automovel.ValorParcela == 0)
            {
                erros.AppendLine("Valor de parcela inválida.");
            }

            if (anuncio.Automovel.ParcelasRestantes == 0)
            {
                erros.AppendLine("Parcelas restantes inválidas.");
            }

            if (anuncio.Automovel.Modelo == null)
            {
                erros.AppendLine("Modelo inválido.");
            }

            if (!anuncio.Plano.Ativo)
            {
                erros.AppendLine("Plano inválido.");
            }

            if (erros.Length > 0)
            {
                throw new Exception(erros.ToString());
            }
        }
Esempio n. 24
0
 public void Anunciar_Plano_Do_Anuncio_Nulo_Dispara_ArgumentNullException()
 {
     Anuncio anuncio = new Anuncio(new Anunciante(), new Automovel(null), null);
     target.Anunciar(anuncio);
 }
Esempio n. 25
0
 public void Anuciar(Anuncio anuncio)
 {
     //validar
     this.repositorioDeAnuncios.Anuciar(anuncio);
 }