public void LivroIntegracao_Adicionar_ShouldBeOk()
        {
            int   biggerThan       = 0;
            int   sizeListExpected = 2;
            Livro livro            = _service.Adicionar(ObjectMotherLivro.GetLivro());

            livro.Id.Should().BeGreaterThan(biggerThan);
            var last = _service.Get(livro.Id);

            last.Should().NotBeNull();
            var posts = _service.GetAll();

            posts.Count().Should().Be(sizeListExpected);
        }
        protected void ValidarISBN(ILivroService livroRepository)
        {
            RuleFor(x => x.ISBN)
            .NotEmpty()
            .WithMessage(x => "O Campo ISBN deve ser informado.");

            RuleFor(p => p.ISBN)
            .Must((entidade, isbn) => !livroRepository.GetAll().Any(n => n.ISBN == isbn && n.Id != entidade.Id))
            .WithMessage(p => "O ISBN já está sendo utilizado.");
        }
示例#3
0
 public ActionResult <IEnumerable <Livro> > Get()
 {
     try
     {
         return(Ok(_livroService.GetAll()));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex));
     }
 }
 public ActionResult GetAll()
 {
     try
     {
         return(Ok(_livroService.GetAll()));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, "Erro ao buscar, " + ex.Message));
     }
 }
        public void Deve_retornar_todos_os_livros()
        {
            _livroRepository.BuscarTodos().Returns(_listaLivros);
            var livrosEsperados  = _listaLivrosView;
            var livrosRetornados = _livroService.GetAll();

            Assert.AreEqual(livrosEsperados.Count(), livrosRetornados.Count());
            Assert.AreEqual(livrosEsperados.First().LivroId, livrosRetornados.First().LivroId);
            Assert.AreEqual(livrosEsperados.First().Titulo, livrosRetornados.First().Titulo);
            Assert.AreEqual(livrosEsperados.First().NomeDoAutor, livrosRetornados.First().NomeDoAutor);
        }
 public List <LivroViewModel> GetAll()
 {
     try
     {
         return(Mapper.Map <List <LivroViewModel> >(_livroService.GetAll()));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#7
0
        public void DadaUmaInclusaoDeLivroComISBNNaoExistenteDeveRetornarTrue()
        {
            var livros    = service.GetAll();
            var isbnFake  = livros.Max(x => x.ISBN) + 1;
            var novoLivro = new Livro(isbnFake, "Livro 1", 10, $"Autor { isbnFake.ToString() }", DateTime.Now, $"Imagem {isbnFake}");

            Assert.IsTrue(service.AddLivro(novoLivro).Result.ISBN == isbnFake);
        }
示例#8
0
        public async Task <ActionResult> GetAll()
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState)); //400 bad request - solicitação inválida
            }

            try
            {
                return(Ok(await _livroService.GetAll()));                                //200 - ok
            }
            catch (ArgumentException ex)                                                 // trata erro de controller
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message)); // erro 50
            }
        }
示例#9
0
        private LivrosViewModel GetGrid(LivrosViewModel gridViewModel)
        {
            //Aqui geralmente eu usaria o automapper...
            var livros = LivroService.GetAll();

            var model = new LivrosViewModel {
                Livros = new List <LivroViewModel>()
            };

            foreach (var livro in livros)
            {
                model.Livros.Add(new LivroViewModel
                {
                    Autor   = livro.Autor,
                    Erros   = livro.Erros,
                    Id      = livro.Id,
                    IsValid = livro.IsValid(),
                    Nome    = livro.Nome
                });
            }

            return(model);
        }
示例#10
0
        public ActionResult <IEnumerable <LivroDto> > Get()
        {
            var result = _livroService.GetAll();

            return(Ok(result));
        }
示例#11
0
 // GET: Livros
 public ActionResult Index()
 {
     return(View(Mapper.Map <IEnumerable <Livro>, IEnumerable <LivroViewModel> >(_context.GetAll())));
 }
示例#12
0
 public ActionResult Get()
 {
     return(Ok(_livroService.GetAll().ToList()));
 }
示例#13
0
 public IActionResult GetLivroViewModel()
 {
     return(Response(_livroService.GetAll().OrderBy(l => l.Titulo)));
 }
示例#14
0
        public IActionResult OnGet()
        {
            var todosLivros = _livroService.GetAll();

            return(Ok(todosLivros));
        }
示例#15
0
        public List <LivroDTO> GetAll()
        {
            List <Livro> livros = _service.GetAll();

            return(_map.Map <List <LivroDTO> >(livros));
        }
示例#16
0
 // GET: Livros
 public async Task <IActionResult> Index(string search, int filterType)
 {
     return(View(await Task.FromResult(_service.GetAll(search, filterType))));
 }
 public Task <IEnumerable <Livro> > Get()
 {
     return(livroService.GetAll());
 }
示例#18
0
 public IActionResult GetLivros()
 {
     return(Response(_livroService.GetAll()));
 }
示例#19
0
 public IEnumerable <Livro> GetAll()
 {
     return(_service.GetAll());
 }
示例#20
0
 public IEnumerable <Livro> GetLivro()
 {
     return(_livroService.GetAll());
 }
示例#21
0
 public ActionResult <IEnumerable <LivroViewModel> > ObterLivros()
 {
     return(_livroService.GetAll() as List <LivroViewModel>);
 }
示例#22
0
 public void Quando_obter_todos_os_livros_deve_mapear_corretamente()
 {
     LivroService.GetAll().Should().BeEquivalentTo(LivrosVm);
 }
示例#23
0
 public IActionResult GetAll()
 {
     return(Ok(_livroService.GetAll()));
 }