public void PagingOptions_Apply_Return_Requested_Page_With_Multiple_Sort()
        {
            var contacts = new List<Contact>();
            for (int i = 1; i <= 5; i++)
            {
                contacts.Add(new Contact { Name = "Test User " + (i % 2), ContactTypeId = i});
            }

            const int resultingPage = 2;
            const int pageSize = 2;

            var qo = new PagingOptions<Contact>(resultingPage, pageSize, "Name", isDescending: true);
            qo.ThenSortBy("ContactTypeId", isDescending: true);

            IQueryable<Contact> queryable = qo.Apply(contacts.AsQueryable());
            queryable.Count().ShouldEqual(2);

            var contact = queryable.First();
            contact.Name.ShouldEqual("Test User 1");
            contact.ContactTypeId.ShouldEqual(1);

            var qo2 = new PagingOptions<Contact, string>(resultingPage, pageSize, x => x.Name, isDescending: true);
            qo2.ThenSortBy(x => x.ContactTypeId, isDescending: true);

            queryable = qo2.Apply(contacts.AsQueryable());
            queryable.Count().ShouldEqual(2);

            contact = queryable.First();
            contact.Name.ShouldEqual("Test User 1");
            contact.ContactTypeId.ShouldEqual(1);
        }
        public void PagingOptions_Apply_Will_Set_TotalItems_With_Multiple_Sort()
        {
            var contacts = new List <Contact>();

            for (int i = 1; i <= 5; i++)
            {
                contacts.Add(new Contact {
                    Name = "Test User " + i
                });
            }

            const int resultingPage = 2;
            const int pageSize      = 2;
            var       qo            = new PagingOptions <Contact>(resultingPage, pageSize, "Name", isDescending: true);

            qo.ThenSortBy("ContactTypeId");
            qo.Apply(contacts.AsQueryable());
            qo.TotalItems.ShouldBe(5);

            var qo2 = new PagingOptions <Contact, string>(resultingPage, pageSize, x => x.Name, isDescending: true);

            qo2.ThenSortBy(x => x.ContactTypeId);
            qo2.Apply(contacts.AsQueryable());
            qo2.TotalItems.ShouldBe(5);
        }
        public void PagingOptions_Apply_Return_Requested_Page()
        {
            var contacts = new List <Contact>();

            for (int i = 1; i <= 5; i++)
            {
                contacts.Add(new Contact {
                    Name = "Test User " + i
                });
            }

            const int resultingPage = 2;
            const int pageSize      = 2;

            var qo = new PagingOptions <Contact>(resultingPage, pageSize, "Name", isDescending: true);
            IQueryable <Contact> queryable = qo.Apply(contacts.AsQueryable());

            queryable.Count().ShouldBe(2);
            queryable.First().Name.ShouldBe("Test User 3");

            var qo2 = new PagingOptions <Contact, string>(resultingPage, pageSize, x => x.Name, isDescending: true);

            queryable = qo2.Apply(contacts.AsQueryable());
            queryable.Count().ShouldBe(2);
            queryable.First().Name.ShouldBe("Test User 3");
        }
Exemple #4
0
        public async Task <IEnumerable <TopicResultDto> > GetAll(string userId, SearchOptions <TopicResultDto, Topic> searchOptions,
                                                                 PagingOptions pagingOptions, FilterOptions filterOptions)
        {
            var query = _context.Topics
                        .Where(t => !t.IsDeleted)
                        .Include(t => t.Category)
                        .Include(t => t.User)
                        .Include(t => t.Comments)
                        .Include(t => t.Views)
                        .AsQueryable();

            query = pagingOptions.Apply(filterOptions.Apply(searchOptions.Apply(query), userId));

            return((await query.ToListAsync()).Select(TopicResultDto.Create));
        }
        public void PagingOptions_Apply_Will_Set_TotalItems()
        {
            var contacts = new List<Contact>();
            for (int i = 1; i <= 5; i++)
            {
                contacts.Add(new Contact { Name = "Test User " + i });
            }

            const int resultingPage = 2;
            const int pageSize = 2;
            var qo = new PagingOptions<Contact>(resultingPage, pageSize, "Name", isDescending: true);
            qo.Apply(contacts.AsQueryable());
            qo.TotalItems.ShouldEqual(5);

            var qo2 = new PagingOptions<Contact, string>(resultingPage, pageSize, x => x.Name, isDescending: true);
            qo2.Apply(contacts.AsQueryable());
            qo2.TotalItems.ShouldEqual(5);
        }
        public void PagingOptions_Apply_Return_Requested_Page()
        {
            var contacts = new List<Contact>();
            for (int i = 1; i <= 5; i++)
            {
                contacts.Add(new Contact { Name = "Test User " + i });
            }

            const int resultingPage = 2;
            const int pageSize = 2;

            var qo = new PagingOptions<Contact>(resultingPage, pageSize, "Name", isDescending: true);
            IQueryable<Contact> queryable = qo.Apply(contacts.AsQueryable());
            queryable.Count().ShouldEqual(2);
            queryable.First().Name.ShouldEqual("Test User 3");

            var qo2 = new PagingOptions<Contact, string>(resultingPage, pageSize, x => x.Name, isDescending: true);
            queryable = qo2.Apply(contacts.AsQueryable());
            queryable.Count().ShouldEqual(2);
            queryable.First().Name.ShouldEqual("Test User 3");
        }
        public void PagingOptions_Apply_Return_Requested_Page_With_Multiple_Sort()
        {
            var contacts = new List <Contact>();

            for (int i = 1; i <= 5; i++)
            {
                contacts.Add(new Contact {
                    Name = "Test User " + (i % 2), ContactTypeId = i
                });
            }

            const int resultingPage = 2;
            const int pageSize      = 2;

            var qo = new PagingOptions <Contact>(resultingPage, pageSize, "Name", isDescending: true);

            qo.ThenSortBy("ContactTypeId", isDescending: true);

            IQueryable <Contact> queryable = qo.Apply(contacts.AsQueryable());

            queryable.Count().ShouldBe(2);

            var contact = queryable.First();

            contact.Name.ShouldBe("Test User 1");
            contact.ContactTypeId.ShouldBe(1);

            var qo2 = new PagingOptions <Contact, string>(resultingPage, pageSize, x => x.Name, isDescending: true);

            qo2.ThenSortBy(x => x.ContactTypeId, isDescending: true);

            queryable = qo2.Apply(contacts.AsQueryable());
            queryable.Count().ShouldBe(2);

            contact = queryable.First();
            contact.Name.ShouldBe("Test User 1");
            contact.ContactTypeId.ShouldBe(1);
        }