コード例 #1
0
        static void TestIEnumerableStaticPaginated(int page, int total = 5)
        {
            PeopleList listOfAllPeople = new PeopleList();
            int        countOfPeople   = listOfAllPeople.Count;

            IEnumerable <People> listOfPeople0 = listOfAllPeople
                                                 .OrderBy(x => x.Id)
                                                 .Skip((page - 1) * total)
                                                 .Take(total)
                                                 .ToArray();

            StaticPaginated <People> paginated0 = new StaticPaginated <People>(listOfPeople0, page, total, countOfPeople);

            page += 1;
            IEnumerable <People> listOfPeople1 = listOfAllPeople
                                                 .OrderBy(x => x.Id)
                                                 .Skip((page) * total)
                                                 .Take(total)
                                                 .ToArray();

            StaticPaginated <People> paginated1 = new StaticPaginated <People>(listOfPeople1.ToArray(), page, total, countOfPeople);

            PaginatedMetaData bm0 = paginated0.ToPaginatedMetaData();
            PaginatedMetaData bm1 = paginated1.ToPaginatedMetaData();

            var ap0 = paginated0.Pages;
            var ap1 = paginated1.Pages;
        }
コード例 #2
0
        static void TestIQueryablePaginated(int page, int total = 5)
        {
            using (DatabaseContext db = new DatabaseContext())
            {
                var count = db.People.Count();
                Paginated <People> listOfQueryable0 = db.People
                                                      .OrderBy(x => x.Name)
                                                      .ToPaginated(page, total);

                Paginated <People> listOfQueryable1 = db.People
                                                      .OrderBy(x => x.Name)
                                                      .ToPaginated((page + 1), total);

                PaginatedMetaData am0 = listOfQueryable0.ToPaginatedMetaData();
                PaginatedMetaData am1 = listOfQueryable1.ToPaginatedMetaData();

                int[] ap0 = listOfQueryable0.Pages.ToArray();
                int[] ap1 = listOfQueryable1.Pages.ToArray();

                listOfQueryable0.SetPages(1);
                int[] ap3 = listOfQueryable0.Pages.ToArray();

                listOfQueryable1.SetPages(1);
                int[] ap4 = listOfQueryable1.Pages.ToArray();
            }
        }
コード例 #3
0
        public void TestPaginatedWithIQuerable()
        {
            int pageNumber = 1;
            int pageSize   = 2;

            Paginated <People> st = Database.People.ToPaginated(pageNumber, pageSize);


            PaginatedMetaData metaData = st.ToPaginatedMetaData();

            Assert.IsInstanceOfType(st, typeof(Paginated <People>));
            Assert.IsInstanceOfType(st, typeof(IPaginated));
            Assert.IsInstanceOfType(st, typeof(IPaginated <People>));
            Assert.IsInstanceOfType(st, typeof(IList));
            Assert.IsInstanceOfType(st, typeof(IList <People>));
            Assert.IsInstanceOfType(st, typeof(List <People>));
            Assert.IsInstanceOfType(st, typeof(PaginatedBase <People>));
            Assert.IsInstanceOfType(metaData, typeof(PaginatedMetaData));
            Assert.AreEqual(metaData.FirstItemOnPage, 1);
            Assert.IsTrue(metaData.HasNextPage);
            Assert.IsFalse(metaData.HasPreviousPage);
            Assert.IsTrue(metaData.IsFirstPage);
            Assert.IsFalse(metaData.IsLastPage);
            Assert.AreEqual(metaData.LastItemOnPage, 2);
            Assert.AreEqual(metaData.MaximumPageNumbersToDisplay, 8);
            Assert.AreEqual(metaData.PageCount, 5);
            Assert.AreEqual(metaData.Pages.Count, 5);
            Assert.AreEqual(metaData.PageNumber, 1);
            Assert.AreEqual(metaData.PageSize, 2);
            Assert.AreEqual(metaData.TotalItemCount, st.TotalItemCount);
        }
コード例 #4
0
        public void TestStaticPaginated()
        {
            List <int> numbers    = GetNumbers().ToList();
            int        pageNumber = 1;
            int        pageSize   = 10;

            StaticPaginated <int> st =
                new StaticPaginated <int>(
                    numbers.Skip(pageNumber).Take(pageSize),
                    pageNumber,
                    pageSize,
                    numbers.Count);

            PaginatedMetaData metaData = st.ToPaginatedMetaData();

            Assert.IsInstanceOfType(st, typeof(StaticPaginated <int>));
            Assert.IsInstanceOfType(st, typeof(IPaginated));
            Assert.IsInstanceOfType(st, typeof(IPaginated <int>));
            Assert.IsInstanceOfType(st, typeof(IList));
            Assert.IsInstanceOfType(st, typeof(IList <int>));
            Assert.IsInstanceOfType(st, typeof(List <int>));
            Assert.IsInstanceOfType(st, typeof(PaginatedBase <int>));
            Assert.IsInstanceOfType(metaData, typeof(PaginatedMetaData));
            Assert.AreEqual(metaData.FirstItemOnPage, 1);
            Assert.IsTrue(metaData.HasNextPage);
            Assert.IsFalse(metaData.HasPreviousPage);
            Assert.IsTrue(metaData.IsFirstPage);
            Assert.IsFalse(metaData.IsLastPage);
            Assert.AreEqual(metaData.LastItemOnPage, 10);
            Assert.AreEqual(metaData.MaximumPageNumbersToDisplay, 8);
            Assert.AreEqual(metaData.PageCount, 10);
            Assert.AreEqual(metaData.Pages.Count, 5);
            Assert.AreEqual(metaData.PageNumber, 1);
            Assert.AreEqual(metaData.PageSize, 10);
            Assert.AreEqual(metaData.TotalItemCount, numbers.Count);
        }