From a98bc84530f1e975a438d1880337d36136b2f6ae Mon Sep 17 00:00:00 2001 From: Haacked Date: Tue, 15 Oct 2013 16:01:34 -0700 Subject: [PATCH] Add unit test for ReadOnlyPagedCollection --- .../Models/ReadOnlyPagedCollectionTests.cs | 39 +++++++++++++++++++ Octokit.Tests/Octokit.Tests.csproj | 1 + 2 files changed, 40 insertions(+) create mode 100644 Octokit.Tests/Models/ReadOnlyPagedCollectionTests.cs diff --git a/Octokit.Tests/Models/ReadOnlyPagedCollectionTests.cs b/Octokit.Tests/Models/ReadOnlyPagedCollectionTests.cs new file mode 100644 index 00000000..aed05627 --- /dev/null +++ b/Octokit.Tests/Models/ReadOnlyPagedCollectionTests.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using NSubstitute; +using Octokit.Internal; +using Xunit; + +namespace Octokit.Tests.Models +{ + public class ReadOnlyPagedCollectionTests + { + public class TheGetNextPageMethod + { + [Fact] + public async Task ReturnsTheNextPage() + { + var nextPageUrl = new Uri("https://example.com/page/2"); + var nextPageResponse = Task.Factory.StartNew>>(() => + new ApiResponse> {BodyAsObject = new List {new object(), new object()}}); + var links = new Dictionary {{"next", nextPageUrl}}; + var scopes = new List(); + + var response = new ApiResponse> + { + BodyAsObject = new List(), + ApiInfo = new ApiInfo(links, scopes, scopes, "etag", 100, 100) + }; + var connection = Substitute.For(); + connection.GetAsync>(nextPageUrl, null, null).Returns(nextPageResponse); + var pagedCollection = new ReadOnlyPagedCollection(response, connection); + + var nextPage = await pagedCollection.GetNextPage(); + + Assert.NotNull(nextPage); + Assert.Equal(2, nextPage.Count); + } + } + } +} diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index b02129cb..2404a825 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -84,6 +84,7 @@ +