diff --git a/Octokit.Tests/Models/ReadOnlyPagedCollectionTests.cs b/Octokit.Tests/Models/ReadOnlyPagedCollectionTests.cs index 6fa1e4c2..6b690a63 100644 --- a/Octokit.Tests/Models/ReadOnlyPagedCollectionTests.cs +++ b/Octokit.Tests/Models/ReadOnlyPagedCollectionTests.cs @@ -33,6 +33,70 @@ namespace Octokit.Tests.Models Assert.NotNull(nextPage); Assert.Equal(2, nextPage.Count); } + + [Fact] + public async Task WhenNoInformationSetReturnsNull() + { + var nextPageUrl = new Uri("https://example.com/page/2"); + var nextPageResponse = Task.Factory.StartNew>>(() => + new ApiResponse>(new Response(), new List { new object(), new object() })); + + var links = new Dictionary(); + var scopes = new List(); + var httpResponse = Substitute.For(); + httpResponse.ApiInfo.Returns(new ApiInfo(links, scopes, scopes, "etag", new RateLimit(new Dictionary()))); + + var response = new ApiResponse>(httpResponse, new List()); + var connection = Substitute.For(); + + connection.Get>(nextPageUrl, null, null).Returns(nextPageResponse); + + var pagedCollection = new ReadOnlyPagedCollection( + response, + nextPageUri => connection.Get>(nextPageUrl, null, null)); + + var nextPage = await pagedCollection.GetNextPage(); + + Assert.Null(nextPage); + } + + [Fact] + public async Task WhenInlineFuncKillsPaginationReturnNull() + { + var nextPageUrl = new Uri("https://example.com/page/2"); + var nextPageResponse = Task.Factory.StartNew>>(() => + new ApiResponse>(new Response(), new List { new object(), new object() })); + + var links = new Dictionary { { "next", nextPageUrl } }; + var scopes = new List(); + var httpResponse = Substitute.For(); + httpResponse.ApiInfo.Returns(new ApiInfo(links, scopes, scopes, "etag", new RateLimit(new Dictionary()))); + + var response = new ApiResponse>(httpResponse, new List()); + var connection = Substitute.For(); + + connection.Get>(nextPageUrl, null, null).Returns(nextPageResponse); + + var pageCount = 0; + + var pagedCollection = new ReadOnlyPagedCollection( + response, + nextPageUri => + { + if (pageCount > 1) + { + return null; + } + pageCount++; + return connection.Get>(nextPageUrl, null, null); + }); + + var first = await pagedCollection.GetNextPage(); + var second = await pagedCollection.GetNextPage(); + + Assert.NotNull(first); + Assert.NotNull(second); + } } } } diff --git a/mkdocs.yml b/mkdocs.yml index a2ea05de..3ac0cf66 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -31,7 +31,7 @@ pages: - Advanced: - 'API Options': 'extensibility.md' - 'Debugging from Source': 'debugging-source.md' - - 'HttpClient': 'http-client.md' + - 'OAuth Flow': 'oauth-flow.md' - 'HttpClient': 'http-client.md' - Contributing: