/// <summary>
        /// Gets the page offset for the specific paging information.
        /// </summary>
        /// <param name="pagingInfo">Presentation paging information.</param>
        /// <returns>Page offset.</returns>
        public int GetPageOffSet(PresentationPagingInfo pagingInfo)
        {
            double halfPage = Math.Round((double)(pagingInfo.MaxPageNumbersToShow / 2));

            if (pagingInfo.PageNumber < halfPage)
            {
                return(0);   // first half of page set, dont offset
            }

            int quarterPage = Convert.ToInt32(Math.Round(halfPage / 2, 0, MidpointRounding.AwayFromZero));

            var offSet = Convert.ToInt32(pagingInfo.PageNumber - (quarterPage + 1));

            // Handle if we are at the end of the set (we still want to show the full maxPageNumbersToShow of options)
            while (offSet + pagingInfo.MaxPageNumbersToShow > pagingInfo.LastPageNumber + 1)
            {
                offSet--;
            }

            if (offSet < 0)
            {
                return(0);   // offset should never be less than zero
            }
            return(offSet);
        }
示例#2
0
            public void WhenTotalItemsCountAndPageSizeAreValid_ThenReturnTotalPageCount(int totalItemsCount, int pageSize, int expected)
            {
                var classUnderTest = new PresentationPagingInfo(totalItemsCount, pageSize, 0);

                var result = classUnderTest.TotalPageCount;

                Assert.That(result, Is.EqualTo(expected));
            }
            public void WhenPageNumerIsGiven_ThenOffSetIsReturned(int pageNumber, int expected)
            {
                var pagingInfo = new PresentationPagingInfo(TotalItems, PageSize, pageNumber);

                var result = Act(pagingInfo);

                Assert.That(result, Is.EqualTo(expected));
            }
            public void WhenTotalItems51_AndPageSize10_AndPageNumber1_AndMaxPagesToShow3_ThenReturnOffsetZero()
            {
                var pagingInfo = new PresentationPagingInfo(51, 10, 1, 3);

                var result = Act(pagingInfo);

                Assert.That(result, Is.EqualTo(0));
            }
            [TestCase(110, 10, 11)]                     // 110 / 10 = 11
            public void WhenZeroOffSet_ThenCreateCorrectSizeOfList(int totalItemsCount, int pageSize, int expected)
            {
                var pagingInfo     = new PresentationPagingInfo(totalItemsCount, pageSize, 0, 1000);
                var classUnderTest = CreateClassUnderTest();

                var pageNumbers = classUnderTest.Create(pagingInfo);

                Assert.That(pageNumbers.Count, Is.EqualTo(expected));
            }
示例#6
0
        private static PaginationPageViewModel CreatePaginationPageViewModel(int pageNumber)
        {
            var pagingInfo = new PresentationPagingInfo(TotalItemsCount, PageSize, pageNumber, MaxPageNumbersToShow);

            return(new PaginationPageViewModel(TotalItemsCount, pageNumber, PageSize)
            {
                PageNavigationNumbers = new PageNumbersFactory(new MiddlePageOffSetStrategy()).Create(pagingInfo)
            });
        }
            public void WhenZeroOffSet_AndTotalItemCountIsZero_ThenCreateEmptyCollection()
            {
                var pagingInfo     = new PresentationPagingInfo(0, 2, 0);
                var classUnderTest = CreateClassUnderTest();

                var pageNumbers = classUnderTest.Create(pagingInfo);

                Assert.That(pageNumbers.Count, Is.EqualTo(0));
            }
            public void WhenZeroOffSet_AndPageNumberCountIsGreaterThanMaxPageNumbersToShow_ThenCreateListOfSizeMaxPageNumbersToShow()
            {
                const int maxPageNumbersToShow = 11;

                var pagingInfo     = new PresentationPagingInfo(110, 10, 0, maxPageNumbersToShow);
                var classUnderTest = CreateClassUnderTest();

                var pageNumbers = classUnderTest.Create(pagingInfo);    // 120 / 10 = 12

                Assert.That(pageNumbers.Count, Is.EqualTo(maxPageNumbersToShow));
            }
            public void WhenZeroOffSet_ThenSetIsCurrentPageTo4thPage()
            {
                var pagingInfo     = new PresentationPagingInfo(10, 3, 3);
                var classUnderTest = CreateClassUnderTest();

                var pageNumbers = classUnderTest.Create(pagingInfo);

                Assert.That(pageNumbers[0].IsCurrentPage, Is.False);
                Assert.That(pageNumbers[1].IsCurrentPage, Is.False);
                Assert.That(pageNumbers[2].IsCurrentPage, Is.False);
                Assert.That(pageNumbers[3].IsCurrentPage, Is.True);
            }
            public void WhenZeroOffSet_ThenSetDisplayTextCorrectly()
            {
                var pagingInfo     = new PresentationPagingInfo(10, 2, 0);
                var classUnderTest = CreateClassUnderTest();

                var pageNumbers = classUnderTest.Create(pagingInfo);

                Assert.That(pageNumbers[0].DisplayNumber, Is.EqualTo("1"));
                Assert.That(pageNumbers[1].DisplayNumber, Is.EqualTo("2"));
                Assert.That(pageNumbers[2].DisplayNumber, Is.EqualTo("3"));
                Assert.That(pageNumbers[3].DisplayNumber, Is.EqualTo("4"));
                Assert.That(pageNumbers[4].DisplayNumber, Is.EqualTo("5"));
            }
示例#11
0
 public void WhenTotalItemsLessThanZero_ThenThrowException()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => _ = new PresentationPagingInfo(-1, 10, 0));
 }
示例#12
0
            public void WhenPageNumberGreaterThanTotalPageCount_ThenSetPageNumberToLastPage()
            {
                var classUnderTest = new PresentationPagingInfo(100, 10, 10);

                Assert.That(classUnderTest.PageNumber, Is.EqualTo(classUnderTest.LastPageNumber));
            }
示例#13
0
 public void WhenPageSizeLessThanOne_ThenThrowException()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => _ = new PresentationPagingInfo(100, 0, 0));
 }
 public int GetPageOffSet(PresentationPagingInfo pagingInfo)
 {
     return(5);
 }
示例#15
0
 public void WhenPageNumberIsLessThanZero_ThenThrowException()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => _ = new PresentationPagingInfo(100, 10, -1));
 }
示例#16
0
            public void WhenTotalPageCountIsTwo_ThenReturnOne()
            {
                var classUnderTest = new PresentationPagingInfo(20, 10, 0);

                Assert.That(classUnderTest.LastPageNumber, Is.EqualTo(1));
            }
示例#17
0
 public void WhenMaxPageNumbersToShowIsLessThanOne_ThenThrowException()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => _ = new PresentationPagingInfo(100, 10, 0, 0));
 }
示例#18
0
            public void WhenPageNumberLessThanOrEqualToTotalPageCount_ThenSetPageNumber()
            {
                var classUnderTest = new PresentationPagingInfo(100, 10, 9);

                Assert.That(classUnderTest.PageNumber, Is.EqualTo(classUnderTest.LastPageNumber));
            }
 private int Act(PresentationPagingInfo pagingInfo)
 {
     return(_classUnderTest.GetPageOffSet(pagingInfo));
 }