added tests for new behaviour within pagination

This commit is contained in:
Brendan Forster
2016-02-14 16:48:11 +11:00
parent 0ea28a94f3
commit 3a9dcc33f7
2 changed files with 65 additions and 1 deletions

View File

@@ -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);
}
}
}
}

View File

@@ -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: