diff --git a/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs index cc0bddeb..0117463a 100644 --- a/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs @@ -552,6 +552,21 @@ public class RepositoriesClientTests Assert.True(repositories.Count > 80); } + + [IntegrationTest] + public async Task ReturnsAllPublicRepositoriesSinceLastSeen() + { + var github = Helper.GetAuthenticatedClient(); + + var request = new PublicRepositoryRequest { Since = 32732250 }; + var repositories = await github.Repository.GetAllPublic(request); + + Assert.NotNull(repositories); + Assert.True(repositories.Any()); + Assert.Equal(32732252, repositories[0].Id); + Assert.False(repositories[0].Private); + Assert.Equal("zad19", repositories[0].Name); + } } public class TheGetAllForOrgMethod diff --git a/Octokit.Tests.Integration/Reactive/ObservableRepositoriesClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableRepositoriesClientTests.cs index fe5294b8..3a63339e 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableRepositoriesClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableRepositoriesClientTests.cs @@ -1,4 +1,5 @@ -using System.Reactive.Linq; +using System.Linq; +using System.Reactive.Linq; using System.Threading.Tasks; using Octokit.Reactive; using Xunit; @@ -27,5 +28,26 @@ namespace Octokit.Tests.Integration Assert.False(repository2.Fork); } } + + public class TheGetAllPublicSinceMethod + { + [IntegrationTest] + public async Task ReturnsAllPublicReposSinceLastSeen() + { + var github = Helper.GetAuthenticatedClient(); + + var client = new ObservableRepositoriesClient(github); + var request = new PublicRepositoryRequest + { + Since = 32732250 + }; + var repositories = await client.GetAllPublic(request).ToArray(); + Assert.NotNull(repositories); + Assert.True(repositories.Any()); + Assert.Equal(32732252, repositories[0].Id); + Assert.False(repositories[0].Private); + Assert.Equal("zad19", repositories[0].Name); + } + } } } diff --git a/Octokit.Tests/Clients/RepositoriesClientTests.cs b/Octokit.Tests/Clients/RepositoriesClientTests.cs index 0534472b..1dcb5787 100644 --- a/Octokit.Tests/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoriesClientTests.cs @@ -273,6 +273,37 @@ namespace Octokit.Tests.Clients } } + + public class TheGetAllPublicSinceMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new RepositoriesClient(connection); + + client.GetAllPublic(new PublicRepositoryRequest { Since = 364 }); + + connection.Received() + .GetAll(Arg.Is(u => u.ToString() == "/repositories"), + Arg.Any>()); + } + + [Fact] + public void SendsTheCorrectParameter() + { + var connection = Substitute.For(); + var client = new RepositoriesClient(connection); + + client.GetAllPublic(new PublicRepositoryRequest { Since = 364 }); + + connection.Received() + .GetAll(Arg.Is(u => u.ToString() == "/repositories"), + Arg.Is>(d => d.Count == 1 + && d["since"] == "364")); + } + } + public class TheGetAllForCurrentMethod { [Fact] diff --git a/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs index 044a74d7..a69ab0b2 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs @@ -158,6 +158,61 @@ namespace Octokit.Tests.Reactive } } + public class TheGetAllPublicRepositoriesSinceMethod + { + [Fact] + public async Task ReturnsEveryPageOfRepositories() + { + var firstPageUrl = new Uri("/repositories", UriKind.Relative); + var secondPageUrl = new Uri("https://example.com/page/2"); + var firstPageLinks = new Dictionary { { "next", secondPageUrl } }; + var firstPageResponse = new ApiResponse>( + CreateResponseWithApiInfo(firstPageLinks), + new List + { + new Repository(364), + new Repository(365), + new Repository(366) + }); + var thirdPageUrl = new Uri("https://example.com/page/3"); + var secondPageLinks = new Dictionary { { "next", thirdPageUrl } }; + var secondPageResponse = new ApiResponse> + ( + CreateResponseWithApiInfo(secondPageLinks), + new List + { + new Repository(367), + new Repository(368), + new Repository(369) + }); + var lastPageResponse = new ApiResponse>( + new Response(), + new List + { + new Repository(370) + }); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Get>(firstPageUrl, + Arg.Is>(d => d.Count == 1 + && d["since"] == "364"), null) + .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + gitHubClient.Connection.Get>(secondPageUrl, null, null) + .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + gitHubClient.Connection.Get>(thirdPageUrl, null, null) + .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + var repositoriesClient = new ObservableRepositoriesClient(gitHubClient); + + var results = await repositoriesClient.GetAllPublic(new PublicRepositoryRequest { Since = 364 }).ToArray(); + + Assert.Equal(7, results.Length); + gitHubClient.Connection.Received(1).Get>(firstPageUrl, + Arg.Is>(d=>d.Count == 1 + && d["since"] == "364"), null); + gitHubClient.Connection.Received(1).Get>(secondPageUrl, null, null); + gitHubClient.Connection.Received(1).Get>(thirdPageUrl, null, null); + } + } + public class TheGetAllBranchesMethod { [Fact]