Пример #1
0
        public async Task GetAllAsync_EmptyData_ExpectedCalls()
        {
            ClientResponse <IList <ModelBase> > mockPage1Response = GetListResponse(new List <ModelBase>(), 3);
            ClientResponse <IList <ModelBase> > mockPage2Response = GetListResponse(new List <ModelBase>(), 3);
            ClientResponse <IList <ModelBase> > mockPage3Response = GetListResponse(new List <ModelBase>(), 3);

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

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

            IUKFastClient     client = new TestUKFastClient(null);
            IList <ModelBase> items  = await client.GetAllAsync(async (ClientRequestParameters p) => new Paginated <ModelBase>(mockClient, "testresource", p, mockPage1Response), new ClientRequestParameters()
            {
                Pagination = new ClientRequestPagination()
            });

            Assert.AreEqual(0, items.Count);
        }
Пример #2
0
 public Paginated(IUKFastClient client, string resource, ClientRequestParameters parameters, ClientResponse <IList <T> > response)
 {
     this.Client                = client;
     this.Resource              = resource;
     this.Parameters            = parameters ?? new ClientRequestParameters();
     this.Parameters.Pagination = this.Parameters.Pagination ?? new ClientRequestPagination();
     this.Items      = response?.Body?.Data;
     this.Pagination = response?.Body?.Metadata?.Pagination ?? new ClientResponseMetadataPagination();
 }
Пример #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);
        }
Пример #4
0
        public async Task GetAllAsync_NullParameters_ExpectedConfiguredParameters()
        {
            ClientResponse <IList <ModelBase> > mockPage1Response = GetListResponse(null, 2);
            ClientResponse <IList <ModelBase> > mockPage2Response = GetListResponse(null, 2);

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

            mockClient.GetPaginatedAsync <ModelBase>("testresource", Arg.Is <ClientRequestParameters>(x => x.Pagination.Page == 2 && x.Pagination.PerPage == 99)).Returns(Task.Run(() => new Paginated <ModelBase>(mockClient, "testresource", null, mockPage2Response)));

            IUKFastClient client = new TestUKFastClient(null, new ClientConfig()
            {
                PaginationDefaultPerPage = 99
            });

            await client.GetAllAsync(async (ClientRequestParameters p) => new Paginated <ModelBase>(mockClient, "testresource", p, mockPage1Response), null);

            await mockClient.Received().GetPaginatedAsync <ModelBase>("testresource", Arg.Is <ClientRequestParameters>(x => x.Pagination.PerPage == 99));
        }
Пример #5
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);
        }