Example #1
0
        public void Total_ReturnsTotalItems()
        {
            ClientResponse <IList <ModelBase> > paginatedResponse = UKFastClientTests.GetListResponse(new List <ModelBase>(), 10);

            paginatedResponse.Body.Metadata.Pagination.Total = 99;

            Paginated <ModelBase> paginated = new Paginated <ModelBase>(null, "testresource", new ClientRequestParameters(), paginatedResponse);

            Assert.AreEqual(99, paginated.Total);
        }
Example #2
0
        public void CurrentPage_LessThan1_Returns1()
        {
            ClientResponse <IList <ModelBase> > paginatedResponse = UKFastClientTests.GetListResponse(new List <ModelBase>(), 10);

            Paginated <ModelBase> paginated = new Paginated <ModelBase>(null, "testresource", new ClientRequestParameters()
            {
                Pagination = new ClientRequestPagination()
                {
                    Page = -4
                }
            }, paginatedResponse);

            Assert.AreEqual(1, paginated.CurrentPage);
        }
Example #3
0
        public async Task First_ReturnsFirstPage()
        {
            ClientResponse <IList <ModelBase> > paginatedResponse = UKFastClientTests.GetListResponse(new List <ModelBase>(), 3);
            ClientResponse <IList <ModelBase> > mockResponse      = UKFastClientTests.GetListResponse(new List <ModelBase>(), 3);

            IUKFastClient client = Substitute.For <IUKFastClient>();

            client.GetPaginatedAsync <ModelBase>("testresource", Arg.Is <ClientRequestParameters>(x => x.Pagination.Page == 1)).Returns(x =>
            {
                return(Task.Run(() => new Paginated <ModelBase>(client, "testresource", x.ArgAt <ClientRequestParameters>(1), mockResponse)));
            });

            Paginated <ModelBase> paginated = new Paginated <ModelBase>(client, "testresource", new ClientRequestParameters(), paginatedResponse);
            Paginated <ModelBase> first     = await paginated.First();

            Assert.AreEqual(1, first.CurrentPage);
        }
Example #4
0
        public async Task Previous_FirstPage_ReturnsNull()
        {
            ClientRequestParameters parameters = new ClientRequestParameters()
            {
                Pagination = new ClientRequestPagination()
                {
                    Page = 1
                }
            };

            ClientResponse <IList <ModelBase> > response = UKFastClientTests.GetListResponse(new List <ModelBase>(), 3);

            Paginated <ModelBase> paginated = new Paginated <ModelBase>(null, null, parameters, response);

            Paginated <ModelBase> previous = await paginated.Previous();

            Assert.IsNull(previous);
        }
Example #5
0
        public async Task Last_LastPage_ReturnsNull()
        {
            ClientRequestParameters parameters = new ClientRequestParameters()
            {
                Pagination = new ClientRequestPagination()
                {
                    Page = 3
                }
            };

            ClientResponse <IList <ModelBase> > response = UKFastClientTests.GetListResponse(new List <ModelBase>(), 3);

            Paginated <ModelBase> paginated = new Paginated <ModelBase>(null, null, parameters, response);

            Paginated <ModelBase> next = await paginated.Next();

            Assert.IsNull(next);
        }
Example #6
0
        public async Task Previous_NotFirstPage_ReturnsPreviousPage()
        {
            ClientResponse <IList <ModelBase> > paginatedResponse = UKFastClientTests.GetListResponse(new List <ModelBase>(), 3);
            ClientResponse <IList <ModelBase> > mockResponse      = UKFastClientTests.GetListResponse(new List <ModelBase>(), 3);

            IUKFastClient client = Substitute.For <IUKFastClient>();

            client.GetPaginatedAsync <ModelBase>("testresource", Arg.Any <ClientRequestParameters>()).Returns(x =>
            {
                return(Task.Run(() => new Paginated <ModelBase>(client, "testresource", x.ArgAt <ClientRequestParameters>(1), mockResponse)));
            });

            Paginated <ModelBase> paginated = new Paginated <ModelBase>(client, "testresource", new ClientRequestParameters()
            {
                Pagination = new ClientRequestPagination()
                {
                    Page = 3
                }
            }, paginatedResponse);

            Paginated <ModelBase> previous = await paginated.Previous();

            Assert.AreEqual(2, previous.CurrentPage);
        }