public void ThrowOrderByIncorrectException_ReturnsOrderByValidationError() { var sut = new ListQueryModel <int>(); FluentActions.Invoking(() => sut.ThrowOrderByIncorrectException(new Exception())) .Should().ThrowExactly <InputValidationException>() .And.Errors.Keys.Should().Contain(nameof(ListQueryModel <int> .OrderBy)); }
public virtual async Task <IListResponseModel <TDto> > GetProjectedListAsync <TDto>(ListQueryModel <TDto> model, Expression <Func <TEntity, bool> > additionalFilter = null, bool readOnly = false) where TDto : IMapFrom <TEntity> { var query = readOnly ? BaseQuery.AsNoTracking() : BaseQuery; if (additionalFilter != null) { query = query.Where(additionalFilter); } IQueryable <TDto> filteredDtoQuery = default; try { filteredDtoQuery = query .ProjectTo <TDto>(_mapper.ConfigurationProvider) .ApplyFilter(model.Filter); } catch (FormatException fe) { model.ThrowFilterIncorrectException(fe.InnerException); } var totalRowCount = await filteredDtoQuery.CountAsync(); IEnumerable <TDto> resultPage = default; try { resultPage = await filteredDtoQuery .ApplyOrder(model.OrderBy) .ApplyPaging(model.PageSize, model.PageIndex) .ToListAsync(); } catch (FormatException fe) { model.ThrowOrderByIncorrectException(fe.InnerException); } return(new ListResponseModel <TDto>(model, totalRowCount, resultPage)); }