Exemple #1
0
        public void BrokenServerFixedSizePaged()
        {
            var server  = new FakeServer(s_resourceA, 1);
            var request = new PageStreamingRequest {
                PageSize = 0
            };
            var paged = server.PagedSync(null, null, request);

            Assert.Throws <NotSupportedException>(() => paged.ReadPage(1));
        }
Exemple #2
0
        public void Flatten(PagedResource pagedResource, int pageSize)
        {
            var server  = new FakeServer(pagedResource);
            var request = new PageStreamingRequest {
                PageSize = pageSize
            };
            var paged = server.PagedSync(null, null, request);

            Assert.Equal(pagedResource.All, paged);
        }
Exemple #3
0
        public void SpecifyPageTokenAtStart()
        {
            var server  = new FakeServer(s_resourceA, 1);
            var request = new PageStreamingRequest {
                PageSize = 0, PageToken = "1:0"
            };
            var paged = server.PagedSync(null, null, request);

            Assert.Equal(s_resourceA.Resource.Skip(1), paged.AsRawResponses().Select(x => x.ToArray()));
        }
Exemple #4
0
        public void NaturalPages(PagedResource pagedResource)
        {
            var server  = new FakeServer(pagedResource);
            var request = new PageStreamingRequest {
                PageSize = 0
            };
            var paged = server.PagedSync(null, null, request);

            Assert.Equal(pagedResource.Resource, paged.AsRawResponses().Select(x => x.ToArray()).ToArray());
        }
Exemple #5
0
        public void NoData()
        {
            var noDataResource = new PagedResource();
            var server         = new FakeServer(noDataResource);
            var request        = new PageStreamingRequest {
                PageSize = 0
            };
            var paged = server.PagedSync(null, null, request);

            // Natural pages
            Assert.Equal(1, paged.AsRawResponses().Count());
            var page1 = paged.AsRawResponses().First();

            Assert.Empty(page1);
            Assert.Equal("", page1.NextPageToken);
            // Unnatural things
            Assert.Empty(paged);
            Assert.Empty(paged.ReadPage(1));
        }
Exemple #6
0
        public void ReadPage(PagedResource pagedResource, int pageSize)
        {
            var    server      = new FakeServer(pagedResource);
            string pageToken   = "";
            var    actualPages = new List <Page <int> >();

            do
            {
                var request = new PageStreamingRequest {
                    PageSize = pageSize, PageToken = pageToken
                };
                var paged = server.PagedSync(null, null, request);
                actualPages.Add(paged.ReadPage(pageSize));
            } while ((pageToken = actualPages.Last().NextPageToken) != "");
            var expectedPages = pagedResource.Fixed(pageSize);

            // Ignore trailing empty pages; we could change the fake server to avoid returning a page
            // token when we've reached (but not gone past) the end.
            Assert.Equal(expectedPages, actualPages.TakeWhile(p => p.Any()).Select(p => p.ToArray()).ToArray());
        }