private int CountExpectedDiscos(GetDiscosQuery request)
        {
            var query = _context.Disco.AsQueryable();

            if (request.Ids?.Count > 0)
            {
                query = query.Where(e => request.Ids.Contains(e.IdDisco));
            }

            if (request.IdGenerosMusicais?.Count > 0)
            {
                query = query.Where(e => request.IdGenerosMusicais.Contains(e.IdGeneroMusical));
            }

            if (!string.IsNullOrEmpty(request.Nome))
            {
                query = query.Where(e => e.Nome.ToLower().Contains(request.Nome.ToLower()));
            }

            if (!string.IsNullOrEmpty(request.NomeGeneroMusical))
            {
                query = query.Where(e => e.GeneroMusical.Nome.ToLower().Contains(request.NomeGeneroMusical.ToLower()));
            }

            var paginacao = request.Paginacao ?? new PaginacaoViewModel(PaginacaoConstants.PaginaDefault, PaginacaoConstants.ItensPorPaginaDefault);

            var resultado = query.Skip((paginacao.Pagina - 1) * paginacao.ItensPorPagina).Take(paginacao.ItensPorPagina).Count();

            return(resultado);
        }
        public async Task Success_Get_WithParams(GetDiscosQuery query)
        {
            var result = await _queryHandler.Handle(query, CancellationToken.None);

            var countSeed = CountExpectedDiscos(query);

            Assert.NotNull(result);
            Assert.Equal(countSeed, result.Itens.Count);
        }
Beispiel #3
0
        public async Task <ActionResult <ConsultaPaginadaViewModel <DiscoViewModel> > > GetAll([FromQuery] List <int> ids, [FromQuery] List <int> idGeneros,
                                                                                               [FromQuery] string nome, [FromQuery] string nomeGenero, [FromQuery] int?pagina, [FromQuery] int?itensPorPagina)
        {
            var query = new GetDiscosQuery()
            {
                Ids = ids,
                IdGenerosMusicais = idGeneros,
                Nome = nome,
                NomeGeneroMusical = nomeGenero
            };

            if (pagina != null && itensPorPagina != null)
            {
                query.Paginacao = new PaginacaoViewModel((int)pagina, (int)itensPorPagina);
            }

            return(Ok(await Mediator.Send(query)));
        }