public void Salvar(Emprestimo emprestimo)
        {
            if (emprestimo != null && emprestimo.Validar())
            {
                emprestimo.DataEmprestimo = emprestimo.DataEmprestimo == DateTime.MinValue
                    ? DateTime.Now
                    : emprestimo.DataEmprestimo;

                emprestimo.Amigo  = _amigoBusiness.Obter(emprestimo.Amigo.Codigo);
                emprestimo.Titulo = _tituloBusiness.Obter(emprestimo.Titulo.Codigo);
                if (emprestimo.Codigo > 0)
                {
                    AlterarTituloEmprestado(emprestimo);
                }
                else
                {
                    _emprestimoData.Salvar(emprestimo);
                }
                if (emprestimo.DataDevolucao == null)
                {
                    emprestimo.Titulo.IsEmprestado = "S";
                    _tituloBusiness.Salvar(emprestimo.Titulo);
                }
            }
            else
            {
                throw new ProjetoException("Dados inválidos ao salvar o empréstimo.");
            }
        }
Exemple #2
0
        public void Domain_Emprestimo_Nao_Deveria_Aceitar_Cliente_Com_Menos_4_Caracteres()
        {
            _emprestimo = ObjectMother.GetEmprestimoClienteMenor4Caracteres();
            Action action = () => _emprestimo.Validar();

            action.Should().Throw <InvalidCaractersException>();
        }
Exemple #3
0
        public void Domain_Emprestimo_Nao_Deveria_Aceitar_Data_Menor_Que_Atual()
        {
            _emprestimo = ObjectMother.GetEmprestimoDataMenorQueAtual();
            Action action = () => _emprestimo.Validar();

            action.Should().Throw <InvalidDateException>();
        }
Exemple #4
0
        public void Emprestimo_ShouldBeOk()
        {
            Emprestimo emprestimo = ObjetoMaeEmprestimo.obterEmprestimo();
            Action     validar    = () => emprestimo.Validar();

            validar.Should().NotThrow <BusinessException>();
        }
Exemple #5
0
        public void Domain_Emprestimo_Nao_Deveria_Aceitar_Disponiblidade_Indisponivel()
        {
            _emprestimo = ObjectMother.GetEmprestimo();
            _emprestimo.livro.Disponibilidade = false;
            Action action = () => _emprestimo.Validar();

            action.Should().Throw <InvalidAvailabilityException>();
        }
Exemple #6
0
        public Emprestimo Salvar(Emprestimo emprestimo)
        {
            emprestimo.Validar();
            string sql = "INSERT INTO TBEmprestimos(Cliente,LivroId,DataDevolucao) VALUES (@Cliente,@LivroId,@DataDevolucao)";

            emprestimo.Id = Db.Insert(sql, Take(emprestimo, false));
            return(emprestimo);
        }
Exemple #7
0
        public void Emprestimo_Disponibilidade_ShouldBeFail()
        {
            Emprestimo emprestimo = ObjetoMaeEmprestimo.obterEmprestimo();

            emprestimo.Livro.Disponibilidade = false;
            Action validar = () => emprestimo.Validar();

            validar.Should().Throw <DisponibilidadeException>();
        }
Exemple #8
0
 public Emprestimo Atualizar(Emprestimo emprestimo)
 {
     if (emprestimo.Id < 1)
     {
         throw new IdentificadorIndefinidoException();
     }
     emprestimo.Validar();
     return(_repository.Atualizar(emprestimo));
 }
 public Emprestimo Editar(Emprestimo emprestimo)
 {
     if (emprestimo.Id < 1)
     {
         throw new ExcecaoIdentifivadorIndefinido();
     }
     emprestimo.Validar();
     return(_repositorio.Editar(emprestimo));
 }
        public void Emprestimo_Valid_ShouldBeSuccess()
        {
            Emprestimo emprestimo = new Emprestimo();

            emprestimo.Id                     = 1;
            emprestimo.NomeCliente            = "Isabel";
            emprestimo.Livro                  = _mockLivro.Object;
            _mockLivro.Object.Disponibilidade = true;
            emprestimo.DataDevolucao          = DateTime.Now.AddDays(10);
            emprestimo.Validar();
        }
Exemple #11
0
        public Emprestimo Editar(Emprestimo emprestimo)
        {
            emprestimo.Validar();
            if (emprestimo.Id < 1)
            {
                throw new ExcecaoIdentifivadorIndefinido();
            }
            string sql = "UPDATE TBEmprestimo SET NomeCliente = @NomeCliente, LivroId = @LivroId, DataDevolucao = @DataDevolucao WHERE Id = @Id";

            Db.Update(sql, Take(emprestimo, true));
            return(emprestimo);
        }
Exemple #12
0
 public Emprestimo Atualizar(Emprestimo emprestimo)
 {
     emprestimo.Validar();
     if (emprestimo.Id > 0)
     {
         Db.Update(_sqlEditar, Take(emprestimo));
         return(emprestimo);
     }
     else
     {
         throw new IdentificadorIndefinidoException();
     }
 }
Exemple #13
0
        public void Emprestimo_NomeNuloOuVazio_DeveRetornarExcecao()
        {
            //Cenário
            Emprestimo emprestimo = ObjectMother.ObterEmprestimoInvalido_NomeClienteNuloOuVazio();

            emprestimo.Id    = 1;
            emprestimo.Livro = _mockLivro.Object;

            //Ação
            Action acaoResultado = () => emprestimo.Validar();

            //Verificar
            acaoResultado.Should().Throw <NomeNuloOuVazioException>();
        }
Exemple #14
0
        public void Emprestimo_LivroIndisponivelParaEmprestimo_DeveRetornarExcecao()
        {
            //Cenário
            Emprestimo emprestimo = ObjectMother.ObterEmprestimoValido();

            emprestimo.Id    = 1;
            emprestimo.Livro = _mockLivro.Object;

            _mockLivro.Setup(livro => livro.Disponibilidade).Returns(false);
            //_mockLivro.Object.Disponibilidade = false;

            //Ação
            Action acaoResultado = () => emprestimo.Validar();

            //Verificar
            acaoResultado.Should().Throw <LivroIndisponivelException>();
        }
        public string Devolver(string amigoEmprestimoDevolu, string caixaEmprestimoDevolu, string revistaEmprestimoDevolu)
        {
            Emprestimo emprestimo = null;

            int posicao = 0;

            emprestimo.amigoEmprestimoDevolu   = amigoEmprestimoDevolu;
            emprestimo.caixaEmprestimoDevolu   = caixaEmprestimoDevolu;
            emprestimo.revistaEmprestimoDevolu = revistaEmprestimoDevolu;

            string resultadoValidacao = emprestimo.Validar();

            if (resultadoValidacao == "EMPRESTIMO_VALIDO")
            {
                registros[posicao] = emprestimo;
            }

            return(resultadoValidacao);
        }
Exemple #16
0
        public string RegistrarEmprestimo(int id, int idAmigo, int idRevista, DateTime dataEmprestimo, DateTime dataDevolucao, string status)
        {
            Emprestimo emprestimo;

            int posicao;

            emprestimo = new Emprestimo();
            posicao    = ObterPosicaoVaga();

            emprestimo.amigo          = controladorAmigo.SelecionarAmigoPorId(idAmigo);
            emprestimo.revista        = controladorRevista.SelecionarRevistaPorId(idRevista);
            emprestimo.dataEmprestimo = dataEmprestimo;
            emprestimo.dataDevolucao  = dataDevolucao;
            emprestimo.status         = status;

            string resultadoValidacao = emprestimo.Validar();

            if (resultadoValidacao == "EMPRESTIMO_VALIDO")
            {
                registros[posicao] = emprestimo;
            }

            return(resultadoValidacao);
        }
Exemple #17
0
 public Emprestimo Adicionar(Emprestimo emprestimo)
 {
     emprestimo.Validar();
     emprestimo.Id = Db.Insert(_sqlInserir, Take(emprestimo));
     return(emprestimo);
 }
Exemple #18
0
 public void Domain_Emprestimo_Deveria_Adicionar_Corretamente()
 {
     _emprestimo = ObjectMother.GetEmprestimo();
     _emprestimo.Validar();
     _emprestimo.Should().NotBeNull();
 }
Exemple #19
0
 public Emprestimo Salvar(Emprestimo emprestimo)
 {
     emprestimo.Validar();
     return(_repository.Salvar(emprestimo));
 }
Exemple #20
0
 public Emprestimo Adicionar(Emprestimo entidade)
 {
     entidade.Validar();
     entidade.Id = Db.Insert(_sqlAdd, Take(entidade));
     return(entidade);
 }
 public Emprestimo Adicionar(Emprestimo emprestimo)
 {
     emprestimo.Validar();
     return(_repositorio.Salvar(emprestimo));
 }
Exemple #22
0
 public void Editar(Emprestimo entidade)
 {
     entidade.Validar();
     Db.Update(_sqlUpdate, Take(entidade));
 }