mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-05 23:06:10 +00:00
added tests for new behaviour within pagination
This commit is contained in:
@@ -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<IApiResponse<List<object>>>(() =>
|
||||
new ApiResponse<List<object>>(new Response(), new List<object> { new object(), new object() }));
|
||||
|
||||
var links = new Dictionary<string, Uri>();
|
||||
var scopes = new List<string>();
|
||||
var httpResponse = Substitute.For<IResponse>();
|
||||
httpResponse.ApiInfo.Returns(new ApiInfo(links, scopes, scopes, "etag", new RateLimit(new Dictionary<string, string>())));
|
||||
|
||||
var response = new ApiResponse<List<object>>(httpResponse, new List<object>());
|
||||
var connection = Substitute.For<IConnection>();
|
||||
|
||||
connection.Get<List<object>>(nextPageUrl, null, null).Returns(nextPageResponse);
|
||||
|
||||
var pagedCollection = new ReadOnlyPagedCollection<object>(
|
||||
response,
|
||||
nextPageUri => connection.Get<List<object>>(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<IApiResponse<List<object>>>(() =>
|
||||
new ApiResponse<List<object>>(new Response(), new List<object> { new object(), new object() }));
|
||||
|
||||
var links = new Dictionary<string, Uri> { { "next", nextPageUrl } };
|
||||
var scopes = new List<string>();
|
||||
var httpResponse = Substitute.For<IResponse>();
|
||||
httpResponse.ApiInfo.Returns(new ApiInfo(links, scopes, scopes, "etag", new RateLimit(new Dictionary<string, string>())));
|
||||
|
||||
var response = new ApiResponse<List<object>>(httpResponse, new List<object>());
|
||||
var connection = Substitute.For<IConnection>();
|
||||
|
||||
connection.Get<List<object>>(nextPageUrl, null, null).Returns(nextPageResponse);
|
||||
|
||||
var pageCount = 0;
|
||||
|
||||
var pagedCollection = new ReadOnlyPagedCollection<object>(
|
||||
response,
|
||||
nextPageUri =>
|
||||
{
|
||||
if (pageCount > 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
pageCount++;
|
||||
return connection.Get<List<object>>(nextPageUrl, null, null);
|
||||
});
|
||||
|
||||
var first = await pagedCollection.GetNextPage();
|
||||
var second = await pagedCollection.GetNextPage();
|
||||
|
||||
Assert.NotNull(first);
|
||||
Assert.NotNull(second);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user