Exemplo n.º 1
0
        public void EmprestimoRepositorio_Editar_Livro_ShouldBeOk()
        {
            Emprestimo emprestimo = ObjectMotherEmprestimo.GetEmprestimo();

            emprestimo.Id          = 1;
            emprestimo.Livro       = _livro;
            _livro.Disponibilidade = false;
            Action executeAction = () => _repositorio.Editar(emprestimo);

            executeAction.Should().Throw <ExcecaoLivroIndisponivel>();
        }
 public Emprestimo Editar(Emprestimo emprestimo)
 {
     if (emprestimo.Id < 1)
     {
         throw new ExcecaoIdentifivadorIndefinido();
     }
     emprestimo.Validar();
     return(_repositorio.Editar(emprestimo));
 }
Exemplo n.º 3
0
        public async Task <EmprestimoViewModel> CancelaEmprestimo(EmprestimoViewModel emprestimo)
        {
            var validacao = await _emprestimoValidacaoCancelamento.Validar(emprestimo);

            if (validacao.IsValid)
            {
                var obj = await _emprestimoRepositorio.SelecionarPorId(emprestimo.Id);

                obj.Status = EStatusEmprestimo.CANCELADO;

                await _emprestimoRepositorio.Editar(obj);

                _ = _livroServico.Devolver(emprestimo.LivroId);

                return(_mapper.Map <EmprestimoViewModel>(obj));
            }

            Erros.AddRange(validacao.Errors.Select(erro => erro.ErrorMessage).ToList());
            return(emprestimo);
        }