From ad74d911dc57845125af6008650dc7c8aa025168 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Thu, 9 Jun 2016 16:51:42 +0700 Subject: [PATCH 1/3] added new overloads --- .../IObservableRepositoryForksClient.cs | 55 +++++++++++++ .../ObservableRepositoryForksClient.cs | 77 ++++++++++++++++++ Octokit/Clients/IRepositoryForksClient.cs | 55 +++++++++++++ Octokit/Clients/RepositoryForksClient.cs | 78 +++++++++++++++++++ 4 files changed, 265 insertions(+) diff --git a/Octokit.Reactive/Clients/IObservableRepositoryForksClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryForksClient.cs index ccc58d70..dedcdbe0 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryForksClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryForksClient.cs @@ -21,6 +21,16 @@ namespace Octokit.Reactive /// A of s representing forks of specified repository. IObservable GetAll(string owner, string name); + /// + /// Gets the list of forks defined for a repository + /// + /// + /// See API documentation for more information. + /// + /// The ID of the repository + /// A of s representing forks of specified repository. + IObservable GetAll(int repositoryId); + /// /// Gets the list of forks defined for a repository /// @@ -33,6 +43,17 @@ namespace Octokit.Reactive /// A of s representing forks of specified repository. IObservable GetAll(string owner, string name, ApiOptions options); + /// + /// Gets the list of forks defined for a repository + /// + /// + /// See API documentation for more information. + /// + /// The ID of the repository + /// Options for changing the API response + /// A of s representing forks of specified repository. + IObservable GetAll(int repositoryId, ApiOptions options); + /// /// Gets the list of forks defined for a repository /// @@ -45,6 +66,17 @@ namespace Octokit.Reactive /// A of s representing forks of specified repository. IObservable GetAll(string owner, string name, RepositoryForksListRequest request); + /// + /// Gets the list of forks defined for a repository + /// + /// + /// See API documentation for more information. + /// + /// The ID of the repository + /// Used to request and filter a list of repository forks + /// A of s representing forks of specified repository. + IObservable GetAll(int repositoryId, RepositoryForksListRequest request); + /// /// Gets the list of forks defined for a repository /// @@ -58,6 +90,18 @@ namespace Octokit.Reactive /// A of s representing forks of specified repository. IObservable GetAll(string owner, string name, RepositoryForksListRequest request, ApiOptions options); + /// + /// Gets the list of forks defined for a repository + /// + /// + /// See API documentation for more information. + /// + /// The ID of the repository + /// Used to request and filter a list of repository forks + /// Options for changing the API response + /// A of s representing forks of specified repository. + IObservable GetAll(int repositoryId, RepositoryForksListRequest request, ApiOptions options); + /// /// Creates a fork for a repository. Specify organization in the fork parameter to create for an organization. /// @@ -69,5 +113,16 @@ namespace Octokit.Reactive /// Used to fork a repository /// A of representing the created fork of specified repository. IObservable Create(string owner, string name, NewRepositoryFork fork); + + /// + /// Creates a fork for a repository. Specify organization in the fork parameter to create for an organization. + /// + /// + /// See API documentation for more information. + /// + /// The ID of the repository + /// Used to fork a repository + /// A of representing the created fork of specified repository. + IObservable Create(int repositoryId, NewRepositoryFork fork); } } diff --git a/Octokit.Reactive/Clients/ObservableRepositoryForksClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryForksClient.cs index 25b0b325..76944879 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryForksClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryForksClient.cs @@ -44,6 +44,19 @@ namespace Octokit.Reactive return GetAll(owner, name, ApiOptions.None); } + /// + /// Gets the list of forks defined for a repository + /// + /// + /// See API documentation for more information. + /// + /// The ID of the repository + /// A of s representing forks of specified repository. + public IObservable GetAll(int repositoryId) + { + return GetAll(repositoryId, ApiOptions.None); + } + /// /// Gets the list of forks defined for a repository /// @@ -63,6 +76,22 @@ namespace Octokit.Reactive return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryForks(owner, name), options); } + /// + /// Gets the list of forks defined for a repository + /// + /// + /// See API documentation for more information. + /// + /// The ID of the repository + /// Options for changing the API response + /// A of s representing forks of specified repository. + public IObservable GetAll(int repositoryId, ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryForks(repositoryId), options); + } + /// /// Gets the list of forks defined for a repository /// @@ -81,6 +110,20 @@ namespace Octokit.Reactive return GetAll(owner, name, request, ApiOptions.None); } + /// + /// Gets the list of forks defined for a repository + /// + /// + /// See API documentation for more information. + /// + /// The ID of the repository + /// Used to request and filter a list of repository forks + /// A of s representing forks of specified repository. + public IObservable GetAll(int repositoryId, RepositoryForksListRequest request) + { + return GetAll(repositoryId, request, ApiOptions.None); + } + /// /// Gets the list of forks defined for a repository /// @@ -102,6 +145,24 @@ namespace Octokit.Reactive _connection.GetAndFlattenAllPages(ApiUrls.RepositoryForks(owner, name), request.ToParametersDictionary(), options); } + /// + /// Gets the list of forks defined for a repository + /// + /// + /// See API documentation for more information. + /// + /// The ID of the repository + /// Used to request and filter a list of repository forks + /// Options for changing the API response + /// A of s representing forks of specified repository. + public IObservable GetAll(int repositoryId, RepositoryForksListRequest request, ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return request == null ? _connection.GetAndFlattenAllPages(ApiUrls.RepositoryForks(repositoryId), options) : + _connection.GetAndFlattenAllPages(ApiUrls.RepositoryForks(repositoryId), request.ToParametersDictionary(), options); + } + /// /// Creates a fork for a repository. Specify organization in the fork parameter to create for an organization. /// @@ -120,5 +181,21 @@ namespace Octokit.Reactive return _client.Create(owner, name, fork).ToObservable(); } + + /// + /// Creates a fork for a repository. Specify organization in the fork parameter to create for an organization. + /// + /// + /// See API documentation for more information. + /// + /// The ID of the repository + /// Used to fork a repository + /// A of representing the created fork of specified repository. + public IObservable Create(int repositoryId, NewRepositoryFork fork) + { + Ensure.ArgumentNotNull(fork, "fork"); + + return _client.Create(repositoryId, fork).ToObservable(); + } } } \ No newline at end of file diff --git a/Octokit/Clients/IRepositoryForksClient.cs b/Octokit/Clients/IRepositoryForksClient.cs index 742b38d0..3112e58b 100644 --- a/Octokit/Clients/IRepositoryForksClient.cs +++ b/Octokit/Clients/IRepositoryForksClient.cs @@ -22,6 +22,16 @@ namespace Octokit /// A of s representing forks of specified repository. Task> GetAll(string owner, string name); + /// + /// Gets the list of forks defined for a repository + /// + /// + /// See API documentation for more information. + /// + /// The ID of the repository + /// A of s representing forks of specified repository. + Task> GetAll(int repositoryId); + /// /// Gets the list of forks defined for a repository /// @@ -34,6 +44,17 @@ namespace Octokit /// A of s representing forks of specified repository. Task> GetAll(string owner, string name, ApiOptions options); + /// + /// Gets the list of forks defined for a repository + /// + /// + /// See API documentation for more information. + /// + /// The ID of the repository + /// Options for changing the API response + /// A of s representing forks of specified repository. + Task> GetAll(int repositoryId, ApiOptions options); + /// /// Gets the list of forks defined for a repository /// @@ -46,6 +67,17 @@ namespace Octokit /// A of s representing forks of specified repository. Task> GetAll(string owner, string name, RepositoryForksListRequest request); + /// + /// Gets the list of forks defined for a repository + /// + /// + /// See API documentation for more information. + /// + /// The ID of the repository + /// Used to request and filter a list of repository forks + /// A of s representing forks of specified repository. + Task> GetAll(int repositoryId, RepositoryForksListRequest request); + /// /// Gets the list of forks defined for a repository /// @@ -59,6 +91,18 @@ namespace Octokit /// A of s representing forks of specified repository. Task> GetAll(string owner, string name, RepositoryForksListRequest request, ApiOptions options); + /// + /// Gets the list of forks defined for a repository + /// + /// + /// See API documentation for more information. + /// + /// The ID of the repository + /// Used to request and filter a list of repository forks + /// Options for changing the API response + /// A of s representing forks of specified repository. + Task> GetAll(int repositoryId, RepositoryForksListRequest request, ApiOptions options); + /// /// Creates a fork for a repository. Specify organization in the fork parameter to create for an organization. /// @@ -70,5 +114,16 @@ namespace Octokit /// Used to fork a repository /// A representing the created fork of specified repository. Task Create(string owner, string name, NewRepositoryFork fork); + + /// + /// Creates a fork for a repository. Specify organization in the fork parameter to create for an organization. + /// + /// + /// See API documentation for more information. + /// + /// The ID of the repository + /// Used to fork a repository + /// A representing the created fork of specified repository. + Task Create(int repositoryId, NewRepositoryFork fork); } } diff --git a/Octokit/Clients/RepositoryForksClient.cs b/Octokit/Clients/RepositoryForksClient.cs index 0915cde3..3d06a346 100644 --- a/Octokit/Clients/RepositoryForksClient.cs +++ b/Octokit/Clients/RepositoryForksClient.cs @@ -37,6 +37,19 @@ namespace Octokit return GetAll(owner, name, ApiOptions.None); } + /// + /// Gets the list of forks defined for a repository + /// + /// + /// See API documentation for more information. + /// + /// The ID of the repository + /// A of s representing forks of specified repository. + public Task> GetAll(int repositoryId) + { + return GetAll(repositoryId, ApiOptions.None); + } + /// /// Gets the list of forks defined for a repository /// @@ -56,6 +69,22 @@ namespace Octokit return ApiConnection.GetAll(ApiUrls.RepositoryForks(owner, name), options); } + /// + /// Gets the list of forks defined for a repository + /// + /// + /// See API documentation for more information. + /// + /// The ID of the repository + /// Options for changing the API response + /// A of s representing forks of specified repository. + public Task> GetAll(int repositoryId, ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.RepositoryForks(repositoryId), options); + } + /// /// Gets the list of forks defined for a repository /// @@ -74,6 +103,20 @@ namespace Octokit return GetAll(owner, name, request, ApiOptions.None); } + /// + /// Gets the list of forks defined for a repository + /// + /// + /// See API documentation for more information. + /// + /// The ID of the repository + /// Used to request and filter a list of repository forks + /// A of s representing forks of specified repository. + public Task> GetAll(int repositoryId, RepositoryForksListRequest request) + { + return GetAll(repositoryId, request, ApiOptions.None); + } + /// /// Gets the list of forks defined for a repository /// @@ -96,6 +139,25 @@ namespace Octokit ApiConnection.GetAll(ApiUrls.RepositoryForks(owner, name), request.ToParametersDictionary(), options); } + /// + /// Gets the list of forks defined for a repository + /// + /// + /// See API documentation for more information. + /// + /// The ID of the repository + /// Used to request and filter a list of repository forks + /// Options for changing the API response + /// A of s representing forks of specified repository. + public Task> GetAll(int repositoryId, RepositoryForksListRequest request, ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return request == null + ? ApiConnection.GetAll(ApiUrls.RepositoryForks(repositoryId), options) : + ApiConnection.GetAll(ApiUrls.RepositoryForks(repositoryId), request.ToParametersDictionary(), options); + } + /// /// Creates a fork for a repository. Specify organization in the fork parameter to create for an organization. /// @@ -114,5 +176,21 @@ namespace Octokit return ApiConnection.Post(ApiUrls.RepositoryForks(owner, name), fork); } + + /// + /// Creates a fork for a repository. Specify organization in the fork parameter to create for an organization. + /// + /// + /// See API documentation for more information. + /// + /// The ID of the repository + /// Used to fork a repository + /// A representing the created fork of specified repository. + public Task Create(int repositoryId, NewRepositoryFork fork) + { + Ensure.ArgumentNotNull(fork, "fork"); + + return ApiConnection.Post(ApiUrls.RepositoryForks(repositoryId), fork); + } } } From 23eaf1693f6fa03abed122ca0ac05900ae6812aa Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Thu, 9 Jun 2016 17:03:48 +0700 Subject: [PATCH 2/3] added unit tests --- .../Clients/RepositoryForksClientTests.cs | 80 ++++++++++++++++++ .../ObservableRepositoryForksClientTests.cs | 81 +++++++++++++++++++ 2 files changed, 161 insertions(+) diff --git a/Octokit.Tests/Clients/RepositoryForksClientTests.cs b/Octokit.Tests/Clients/RepositoryForksClientTests.cs index 32d8bccb..41f5f615 100644 --- a/Octokit.Tests/Clients/RepositoryForksClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryForksClientTests.cs @@ -31,6 +31,17 @@ namespace Octokit.Tests.Clients connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/forks"), Args.ApiOptions); } + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryForksClient(connection); + + await client.GetAll(1); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/forks"), Args.ApiOptions); + } + [Fact] public async Task RequestsCorrectUrlWithApiOptions() { @@ -49,6 +60,24 @@ namespace Octokit.Tests.Clients connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/forks"), options); } + [Fact] + public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions() + { + var connection = Substitute.For(); + var client = new RepositoryForksClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + await client.GetAll(1, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/forks"), options); + } + [Fact] public async Task RequestsCorrectUrlWithRequestParameters() { @@ -62,6 +91,19 @@ namespace Octokit.Tests.Clients Arg.Is>(d => d["sort"] == "stargazers"), Args.ApiOptions); } + [Fact] + public async Task RequestsCorrectUrlWithRepositoryIdWithRequestParameters() + { + var connection = Substitute.For(); + var client = new RepositoryForksClient(connection); + + await client.GetAll(1, new RepositoryForksListRequest { Sort = Sort.Stargazers }); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repositories/1/forks"), + Arg.Is>(d => d["sort"] == "stargazers"), Args.ApiOptions); + } + [Fact] public async Task RequestsCorrectUrlWithRequestParametersWithApiOptions() { @@ -82,6 +124,26 @@ namespace Octokit.Tests.Clients Arg.Is>(d => d["sort"] == "stargazers"), options); } + [Fact] + public async Task RequestsCorrectUrlWithRepositoryIdWithRequestParametersWithApiOptions() + { + var connection = Substitute.For(); + var client = new RepositoryForksClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + await client.GetAll(1, new RepositoryForksListRequest { Sort = Sort.Stargazers }, options); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repositories/1/forks"), + Arg.Is>(d => d["sort"] == "stargazers"), options); + } + [Fact] public async Task EnsuresNonNullArguments() { @@ -98,6 +160,9 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAll("owner", null, new RepositoryForksListRequest(), ApiOptions.None)); await Assert.ThrowsAsync(() => client.GetAll("owner", "name", new RepositoryForksListRequest(), null)); + await Assert.ThrowsAsync(() => client.GetAll(1, (ApiOptions)null)); + await Assert.ThrowsAsync(() => client.GetAll(1, new RepositoryForksListRequest(), null)); + await Assert.ThrowsAsync(() => client.GetAll("", "name")); await Assert.ThrowsAsync(() => client.GetAll("owner", "")); await Assert.ThrowsAsync(() => client.GetAll("", "name", ApiOptions.None)); @@ -124,6 +189,19 @@ namespace Octokit.Tests.Clients connection.Received().Post(Arg.Is(u => u.ToString() == "repos/fake/repo/forks"), newRepositoryFork); } + [Fact] + public void RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new RepositoryForksClient(connection); + + var newRepositoryFork = new NewRepositoryFork(); + + client.Create(1, newRepositoryFork); + + connection.Received().Post(Arg.Is(u => u.ToString() == "repositories/1/forks"), newRepositoryFork); + } + [Fact] public async Task EnsuresNonNullArguments() { @@ -133,6 +211,8 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.Create("owner", null, new NewRepositoryFork())); await Assert.ThrowsAsync(() => client.Create("owner", "name", null)); + await Assert.ThrowsAsync(() => client.Create(1, null)); + await Assert.ThrowsAsync(() => client.Create("", "name", new NewRepositoryFork())); await Assert.ThrowsAsync(() => client.Create("owner", "", new NewRepositoryFork())); } diff --git a/Octokit.Tests/Reactive/ObservableRepositoryForksClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoryForksClientTests.cs index 77acb660..e6611a1a 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoryForksClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoryForksClientTests.cs @@ -30,6 +30,17 @@ namespace Octokit.Tests.Reactive gitHubClient.Received().Repository.Forks.GetAll("fake", "repo"); } + [Fact] + public void RequestsCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryForksClient(gitHubClient); + + client.GetAll(1); + + gitHubClient.Received().Repository.Forks.GetAll(1); + } + [Fact] public void RequestsCorrectUrlWithApiOptions() { @@ -48,6 +59,24 @@ namespace Octokit.Tests.Reactive gitHubClient.Received().Repository.Forks.GetAll("fake", "repo", options); } + [Fact] + public void RequestsCorrectUrlWithRepositoryIdWithApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryForksClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + client.GetAll(1, options); + + gitHubClient.Received().Repository.Forks.GetAll(1, options); + } + [Fact] public void RequestsCorrectUrlWithRequestParameters() { @@ -62,6 +91,20 @@ namespace Octokit.Tests.Reactive "fake", "repo", repositoryForksListRequest); } + [Fact] + public void RequestsCorrectUrlWithRepositoryIdWithRequestParameters() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryForksClient(gitHubClient); + + var repositoryForksListRequest = new RepositoryForksListRequest { Sort = Sort.Stargazers }; + + client.GetAll(1, repositoryForksListRequest); + + gitHubClient.Received().Repository.Forks.GetAll( + 1, repositoryForksListRequest); + } + [Fact] public void RequestsCorrectUrlWithRequestParametersWithApiOptions() { @@ -82,6 +125,26 @@ namespace Octokit.Tests.Reactive gitHubClient.Received().Repository.Forks.GetAll("fake", "name", repositoryForksListRequest, options); } + [Fact] + public void RequestsCorrectUrlWithRepositoryIdWithRequestParametersWithApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryForksClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + var repositoryForksListRequest = new RepositoryForksListRequest { Sort = Sort.Stargazers }; + + client.GetAll(1, repositoryForksListRequest, options); + + gitHubClient.Received().Repository.Forks.GetAll(1, repositoryForksListRequest, options); + } + [Fact] public void EnsuresNonNullArguments() { @@ -98,6 +161,9 @@ namespace Octokit.Tests.Reactive Assert.Throws(() => client.GetAll("owner", null, new RepositoryForksListRequest(), ApiOptions.None)); Assert.Throws(() => client.GetAll("owner", "name", new RepositoryForksListRequest(), null)); + Assert.Throws(() => client.GetAll(1, (ApiOptions)null)); + Assert.Throws(() => client.GetAll(1, new RepositoryForksListRequest(), null)); + Assert.Throws(() => client.GetAll("", "name")); Assert.Throws(() => client.GetAll("owner", "")); Assert.Throws(() => client.GetAll("", "name", ApiOptions.None)); @@ -124,6 +190,19 @@ namespace Octokit.Tests.Reactive gitHubClient.Received().Repository.Forks.Create("fake", "repo", newRepositoryFork); } + [Fact] + public void RequestsCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableRepositoryForksClient(gitHubClient); + + var newRepositoryFork = new NewRepositoryFork(); + + client.Create(1, newRepositoryFork); + + gitHubClient.Received().Repository.Forks.Create(1, newRepositoryFork); + } + [Fact] public void EnsuresNonNullArguments() { @@ -133,6 +212,8 @@ namespace Octokit.Tests.Reactive Assert.Throws(() => client.Create("owner", null, new NewRepositoryFork())); Assert.Throws(() => client.Create("owner", "name", null)); + Assert.Throws(() => client.Create(1, null)); + Assert.Throws(() => client.Create("", "name", new NewRepositoryFork())); Assert.Throws(() => client.Create("owner", "", new NewRepositoryFork())); } From 053fb581ebc9fcf4ae36024b72a5f453a48dbe7c Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Thu, 9 Jun 2016 17:10:06 +0700 Subject: [PATCH 3/3] added integration tests --- .../Clients/RepositoryForksClientTests.cs | 230 ++++++++++++++++++ 1 file changed, 230 insertions(+) diff --git a/Octokit.Tests.Integration/Clients/RepositoryForksClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryForksClientTests.cs index 5c19b2b2..bbad604c 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryForksClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryForksClientTests.cs @@ -20,6 +20,18 @@ namespace Octokit.Tests.Integration.Clients Assert.Equal("TeamBinary", masterFork.Owner.Login); } + [IntegrationTest] + public async Task ReturnsForksForRepositoryWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + var forks = await github.Repository.Forks.GetAll(7528679); + + var masterFork = forks.FirstOrDefault(fork => fork.FullName == "TeamBinary/octokit.net"); + Assert.NotNull(masterFork); + Assert.Equal("TeamBinary", masterFork.Owner.Login); + } + [IntegrationTest] public async Task ReturnsCorrectCountOfForksWithoutStart() { @@ -36,6 +48,22 @@ namespace Octokit.Tests.Integration.Clients Assert.Equal(1, forks.Count); } + [IntegrationTest] + public async Task ReturnsCorrectCountOfForksWithoutStartWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1 + }; + + var forks = await github.Repository.Forks.GetAll(7528679, options); + + Assert.Equal(1, forks.Count); + } + [IntegrationTest] public async Task ReturnsCorrectCountOfForksWithStart() { @@ -53,6 +81,23 @@ namespace Octokit.Tests.Integration.Clients Assert.Equal(1, forks.Count); } + [IntegrationTest] + public async Task ReturnsCorrectCountOfForksWithStartWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + var forks = await github.Repository.Forks.GetAll(7528679, options); + + Assert.Equal(1, forks.Count); + } + [IntegrationTest] public async Task ReturnsDistinctForksBasedOnStartPage() { @@ -83,6 +128,36 @@ namespace Octokit.Tests.Integration.Clients Assert.NotEqual(firstPage[2].Id, secondPage[2].Id); } + [IntegrationTest] + public async Task ReturnsDistinctForksBasedOnStartPageWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + var startOptions = new ApiOptions + { + PageCount = 1, + PageSize = 3, + StartPage = 1 + }; + + var firstPage = await github.Repository.Forks.GetAll(7528679, startOptions); + + var skipStartOptions = new ApiOptions + { + PageCount = 1, + PageSize = 3, + StartPage = 2 + }; + + var secondPage = await github.Repository.Forks.GetAll(7528679, skipStartOptions); + + Assert.Equal(3, firstPage.Count); + Assert.Equal(3, secondPage.Count); + Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); + Assert.NotEqual(firstPage[1].Id, secondPage[1].Id); + Assert.NotEqual(firstPage[2].Id, secondPage[2].Id); + } + [IntegrationTest] public async Task ReturnsCorrectCountOfForksWithoutStartParameterized() { @@ -101,6 +176,24 @@ namespace Octokit.Tests.Integration.Clients Assert.Equal(1, forks.Count); } + [IntegrationTest] + public async Task ReturnsCorrectCountOfForksWithoutStartParameterizedWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1 + }; + + var repositoryForksListRequest = new RepositoryForksListRequest { Sort = Sort.Newest }; + + var forks = await github.Repository.Forks.GetAll(7528679, repositoryForksListRequest, options); + + Assert.Equal(1, forks.Count); + } + [IntegrationTest] public async Task ReturnsCorrectCountOfForksWithStartParameterized() { @@ -120,6 +213,25 @@ namespace Octokit.Tests.Integration.Clients Assert.Equal(1, forks.Count); } + [IntegrationTest] + public async Task ReturnsCorrectCountOfForksWithStartParameterizedWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + var repositoryForksListRequest = new RepositoryForksListRequest { Sort = Sort.Newest }; + + var forks = await github.Repository.Forks.GetAll(7528679, repositoryForksListRequest, options); + + Assert.Equal(1, forks.Count); + } + [IntegrationTest] public async Task ReturnsDistinctForksBasedOnStartPageParameterized() { @@ -152,6 +264,38 @@ namespace Octokit.Tests.Integration.Clients Assert.NotEqual(firstPage[2].Id, secondPage[2].Id); } + [IntegrationTest] + public async Task ReturnsDistinctForksBasedOnStartPageParameterizedWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + var repositoryForksListRequest = new RepositoryForksListRequest { Sort = Sort.Newest }; + + var startOptions = new ApiOptions + { + PageCount = 1, + PageSize = 3, + StartPage = 1 + }; + + var firstPage = await github.Repository.Forks.GetAll(7528679, repositoryForksListRequest, startOptions); + + var skipStartOptions = new ApiOptions + { + PageCount = 1, + PageSize = 3, + StartPage = 2 + }; + + var secondPage = await github.Repository.Forks.GetAll(7528679, repositoryForksListRequest, skipStartOptions); + + Assert.Equal(3, firstPage.Count); + Assert.Equal(3, secondPage.Count); + Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); + Assert.NotEqual(firstPage[1].Id, secondPage[1].Id); + Assert.NotEqual(firstPage[2].Id, secondPage[2].Id); + } + [IntegrationTest] public async Task ReturnsForksForRepositorySortingTheResultWithOldestFirstWithApiOptions() { @@ -190,6 +334,44 @@ namespace Octokit.Tests.Integration.Clients } } + [IntegrationTest] + public async Task ReturnsForksForRepositorySortingTheResultWithOldestFirstWithApiOptionsWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + var repositoryForksListRequest = new RepositoryForksListRequest { Sort = Sort.Oldest }; + + var startOptions = new ApiOptions + { + PageCount = 1, + PageSize = 3, + StartPage = 1 + }; + + var firstPage = await github.Repository.Forks.GetAll(7528679, repositoryForksListRequest, startOptions); + var firstPageOrdered = firstPage.OrderBy(r => r.CreatedAt).ToList(); + + var skipStartOptions = new ApiOptions + { + PageCount = 1, + PageSize = 3, + StartPage = 1 + }; + + var secondPage = await github.Repository.Forks.GetAll(7528679, repositoryForksListRequest, skipStartOptions); + var secondPageOrdered = secondPage.OrderBy(r => r.CreatedAt).ToList(); + + for (var index = 0; index < firstPage.Count; index++) + { + Assert.Equal(firstPageOrdered[index].FullName, firstPage[index].FullName); + } + + for (var index = 0; index < firstPage.Count; index++) + { + Assert.Equal(secondPageOrdered[index].FullName, secondPage[index].FullName); + } + } + [IntegrationTest] public async Task ReturnsForksForRepositorySortingTheResultWithOldestFirst() { @@ -203,6 +385,20 @@ namespace Octokit.Tests.Integration.Clients Assert.Equal(sortedForks[index].FullName, actualForks[index].FullName); } } + + [IntegrationTest] + public async Task ReturnsForksForRepositorySortingTheResultWithOldestFirstWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + + var actualForks = (await github.Repository.Forks.GetAll(7528679, new RepositoryForksListRequest { Sort = Sort.Oldest })).ToArray(); + var sortedForks = actualForks.OrderBy(fork => fork.CreatedAt).ToArray(); + + for (var index = 0; index < actualForks.Length; index++) + { + Assert.Equal(sortedForks[index].FullName, actualForks[index].FullName); + } + } } public class TheCreateMethod @@ -224,6 +420,23 @@ namespace Octokit.Tests.Integration.Clients Assert.Equal(true, forkCreated.Fork); } + [IntegrationTest] + public async Task ForkCreatedForUserLoggedInWithRepositoryId() + { + // The fork is created asynchronously by github and therefore it cannot + // be certain that the repo exists when the test ends. It is therefore deleted + // before the test starts instead of after. + Helper.DeleteRepo(Helper.Credentials.Login, "octokit.net"); + + var github = Helper.GetAuthenticatedClient(); + + var forkCreated = await github.Repository.Forks.Create(7528679, new NewRepositoryFork()); + + Assert.NotNull(forkCreated); + Assert.Equal(string.Format("{0}/octokit.net", Helper.UserName), forkCreated.FullName); + Assert.Equal(true, forkCreated.Fork); + } + [OrganizationTest] public async Task ForkCreatedForOrganization() { @@ -240,6 +453,23 @@ namespace Octokit.Tests.Integration.Clients Assert.Equal(string.Format("{0}/octokit.net", Helper.Organization), forkCreated.FullName); Assert.Equal(true, forkCreated.Fork); } + + [OrganizationTest] + public async Task ForkCreatedForOrganizationWithRepositoryId() + { + // The fork is created asynchronously by github and therefore it cannot + // be certain that the repo exists when the test ends. It is therefore deleted + // before the test starts. + Helper.DeleteRepo(Helper.Organization, "octokit.net"); + + var github = Helper.GetAuthenticatedClient(); + + var forkCreated = await github.Repository.Forks.Create(7528679, new NewRepositoryFork { Organization = Helper.Organization }); + + Assert.NotNull(forkCreated); + Assert.Equal(string.Format("{0}/octokit.net", Helper.Organization), forkCreated.FullName); + Assert.Equal(true, forkCreated.Fork); + } } } }