From 9c0aeca6256a8e2056334eff883cda5e4867d9ae Mon Sep 17 00:00:00 2001 From: Prayank Mathur Date: Thu, 24 Mar 2016 20:06:29 +0530 Subject: [PATCH 01/16] Added ApiOptions overload to method GetAll in RepositoryPagesClient as well as Reactive methods and added tests --- .../IObservableRepositoryPagesClient.cs | 13 +++ .../ObservableRepositoryPagesClient.cs | 19 ++++ .../Octokit.Tests.Integration.csproj | 1 + .../ObservableRepositoryPagesClientTests.cs | 86 +++++++++++++++++++ .../Clients/RepositoryPagesClientTests.cs | 9 +- Octokit/Clients/IRepositoryPagesClient.cs | 14 +++ Octokit/Clients/RepositoryPagesClient.cs | 21 ++++- 7 files changed, 158 insertions(+), 5 deletions(-) create mode 100644 Octokit.Tests.Integration/Reactive/ObservableRepositoryPagesClientTests.cs diff --git a/Octokit.Reactive/Clients/IObservableRepositoryPagesClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryPagesClient.cs index d62daa706a..8033fc6c2a 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryPagesClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryPagesClient.cs @@ -16,6 +16,7 @@ public interface IObservableRepositoryPagesClient /// [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")] IObservable Get(string owner, string repositoryName); + /// /// Gets all build metadata for a given repository /// @@ -26,6 +27,18 @@ public interface IObservableRepositoryPagesClient /// /// IObservable GetAll(string owner, string repositoryName); + + /// + /// Gets all build metadata for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// Options to change the response of the API + /// + /// See the API documentation for more information. + /// + /// + IObservable GetAll(string owner, string repositoryName, ApiOptions options); /// /// Gets the build metadata for the last build for a given repository /// diff --git a/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs index ebcd3af70f..a609388578 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs @@ -53,6 +53,25 @@ public IObservable GetAll(string owner, string repositoryName) return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryPageBuilds(owner, repositoryName)); } + /// + /// Gets all build metadata for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// Options to change the behaviour of the API + /// + /// See the API documentation for more information. + /// + /// + public IObservable GetAll(string owner, string repositoryName, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryPageBuilds(owner, repositoryName), options); + } + /// /// Gets the build metadata for the last build for a given repository /// diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 0a5c12a316..2609848218 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -147,6 +147,7 @@ + diff --git a/Octokit.Tests.Integration/Reactive/ObservableRepositoryPagesClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableRepositoryPagesClientTests.cs new file mode 100644 index 0000000000..34677032da --- /dev/null +++ b/Octokit.Tests.Integration/Reactive/ObservableRepositoryPagesClientTests.cs @@ -0,0 +1,86 @@ +using System.Reactive.Linq; +using System.Threading.Tasks; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Integration.Reactive +{ + public class ObservableRepositoryPagesClientTests + { + public class TheGetAllMethod + { + readonly ObservableRepositoryPagesClient _repositoryPagesClient; + const string owner = "octokit"; + const string name = "octokit.net"; + + public TheGetAllMethod() + { + var github = Helper.GetAuthenticatedClient(); + + _repositoryPagesClient = new ObservableRepositoryPagesClient(github); + } + + [IntegrationTest] + public async Task ReturnsRepositoryPages() + { + var pages = await _repositoryPagesClient.GetAll(owner, name).ToList(); + + Assert.NotEmpty(pages); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfPagesWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var pages = await _repositoryPagesClient.GetAll(owner, name, options).ToList(); + Assert.Equal(5, pages.Count); + } + + [IntegrationTest] + public async Task ReturnCorrectCountOfPagesWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var pages = await _repositoryPagesClient.GetAll(owner, name, options).ToList(); + Assert.Equal(5, pages.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstPage = await _repositoryPagesClient.GetAll(owner, name, startOptions).ToList(); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await _repositoryPagesClient.GetAll(owner, name, skipStartOptions).ToList(); + + Assert.NotEqual(firstPage[0].Url, secondPage[0].Url); + Assert.NotEqual(firstPage[1].Url, secondPage[1].Url); + Assert.NotEqual(firstPage[2].Url, secondPage[2].Url); + Assert.NotEqual(firstPage[3].Url, secondPage[3].Url); + Assert.NotEqual(firstPage[4].Url, secondPage[4].Url); + } + } + } +} diff --git a/Octokit.Tests/Clients/RepositoryPagesClientTests.cs b/Octokit.Tests/Clients/RepositoryPagesClientTests.cs index dbafeb1ac5..54c56edea3 100644 --- a/Octokit.Tests/Clients/RepositoryPagesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryPagesClientTests.cs @@ -31,7 +31,7 @@ public async Task EnsuresNonNullArguments() } } - public class TheGetBuildsMethod + public class TheGetAllBuildsMethod { [Fact] public void RequestsCorrectUrl() @@ -41,7 +41,7 @@ public void RequestsCorrectUrl() client.GetAll("fake", "repo"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/pages/builds")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/pages/builds"), null, AcceptHeaders.StableVersion, Args.ApiOptions); } [Fact] @@ -50,8 +50,9 @@ public async Task EnsuresNonNullArguments() var connection = Substitute.For(); var client = new RepositoryPagesClient(connection); - await Assert.ThrowsAsync(() => client.Get(null, "name")); - await Assert.ThrowsAsync(() => client.Get("owner", null)); + await Assert.ThrowsAsync(() => client.GetAll(null, "name", new ApiOptions())); + await Assert.ThrowsAsync(() => client.GetAll("owner", null, new ApiOptions())); + await Assert.ThrowsAsync(() => client.GetAll("owner", "name", null)); } } diff --git a/Octokit/Clients/IRepositoryPagesClient.cs b/Octokit/Clients/IRepositoryPagesClient.cs index 579b263326..2458466f3c 100644 --- a/Octokit/Clients/IRepositoryPagesClient.cs +++ b/Octokit/Clients/IRepositoryPagesClient.cs @@ -23,6 +23,7 @@ public interface IRepositoryPagesClient /// [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")] Task Get(string owner, string repositoryName); + /// /// Gets all build metadata for a given repository /// @@ -33,6 +34,19 @@ public interface IRepositoryPagesClient /// /// Task> GetAll(string owner, string repositoryName); + + /// + /// Gets all build metadata for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the behaviour of the API + /// + /// See the API documentation for more information. + /// + /// + Task> GetAll(string owner, string repositoryName, ApiOptions options); + /// /// Gets the build metadata for the last build for a given repository /// diff --git a/Octokit/Clients/RepositoryPagesClient.cs b/Octokit/Clients/RepositoryPagesClient.cs index 04ed5c2a5a..8800ec2ad2 100644 --- a/Octokit/Clients/RepositoryPagesClient.cs +++ b/Octokit/Clients/RepositoryPagesClient.cs @@ -50,9 +50,28 @@ public Task> GetAll(string owner, string repositoryNam Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); - return ApiConnection.GetAll(ApiUrls.RepositoryPageBuilds(owner, repositoryName)); + return GetAll(owner, repositoryName, ApiOptions.None); } + /// + /// Gets all build metadata for a given repository + /// + /// The owner of the repository + /// The name of the repository + /// Options to change the API response + /// + /// See the API documentation for more information. + /// + /// + public Task> GetAll(string owner, string repositoryName, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); + Ensure.ArgumentNotNull(options, "options"); + + var endpoint = ApiUrls.RepositoryPageBuilds(owner, repositoryName); + return ApiConnection.GetAll(endpoint, null, AcceptHeaders.StableVersion, options); + } /// /// Gets the build metadata for the last build for a given repository /// From 1255be40bf98db3c23ab69f8719dfe079c3070fb Mon Sep 17 00:00:00 2001 From: Prayank Mathur Date: Thu, 24 Mar 2016 23:46:43 +0530 Subject: [PATCH 02/16] Minor fixes --- Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs | 2 +- Octokit/Clients/RepositoryPagesClient.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs index a609388578..74f285e281 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs @@ -50,7 +50,7 @@ public IObservable GetAll(string owner, string repositoryName) Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); - return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryPageBuilds(owner, repositoryName)); + return GetAll(owner, repositoryName, ApiOptions.None); } /// diff --git a/Octokit/Clients/RepositoryPagesClient.cs b/Octokit/Clients/RepositoryPagesClient.cs index 8800ec2ad2..139d57de4a 100644 --- a/Octokit/Clients/RepositoryPagesClient.cs +++ b/Octokit/Clients/RepositoryPagesClient.cs @@ -70,7 +70,7 @@ public Task> GetAll(string owner, string repositoryNam Ensure.ArgumentNotNull(options, "options"); var endpoint = ApiUrls.RepositoryPageBuilds(owner, repositoryName); - return ApiConnection.GetAll(endpoint, null, AcceptHeaders.StableVersion, options); + return ApiConnection.GetAll(endpoint, options); } /// /// Gets the build metadata for the last build for a given repository From 2682e1e2d4cac330ff1583e5fa586bb12a507b1e Mon Sep 17 00:00:00 2001 From: Prayank Mathur Date: Fri, 25 Mar 2016 00:12:53 +0530 Subject: [PATCH 03/16] Some more fixes --- Octokit.Reactive/Clients/ObservableReleasesClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Reactive/Clients/ObservableReleasesClient.cs b/Octokit.Reactive/Clients/ObservableReleasesClient.cs index 100bd131d2..a661a549cc 100644 --- a/Octokit.Reactive/Clients/ObservableReleasesClient.cs +++ b/Octokit.Reactive/Clients/ObservableReleasesClient.cs @@ -33,7 +33,7 @@ public IObservable GetAll(string owner, string name) Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return _connection.GetAndFlattenAllPages(ApiUrls.Releases(owner, name)); + return GetAll(owner, name, ApiOptions.None); } /// From 99e6d7ec713de77c52f416809929f2988ba8fd17 Mon Sep 17 00:00:00 2001 From: Prayank Mathur Date: Fri, 25 Mar 2016 00:24:11 +0530 Subject: [PATCH 04/16] Minor fixes --- Octokit.Reactive/Clients/ObservableReleasesClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Reactive/Clients/ObservableReleasesClient.cs b/Octokit.Reactive/Clients/ObservableReleasesClient.cs index a661a549cc..100bd131d2 100644 --- a/Octokit.Reactive/Clients/ObservableReleasesClient.cs +++ b/Octokit.Reactive/Clients/ObservableReleasesClient.cs @@ -33,7 +33,7 @@ public IObservable GetAll(string owner, string name) Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return GetAll(owner, name, ApiOptions.None); + return _connection.GetAndFlattenAllPages(ApiUrls.Releases(owner, name)); } /// From 948fcdb4f7a8d333a9ec14c060f2eb73b9c322ae Mon Sep 17 00:00:00 2001 From: Prayank Mathur Date: Fri, 25 Mar 2016 00:44:04 +0530 Subject: [PATCH 05/16] Fixes --- Octokit.Tests/Clients/RepositoryPagesClientTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Tests/Clients/RepositoryPagesClientTests.cs b/Octokit.Tests/Clients/RepositoryPagesClientTests.cs index 54c56edea3..4907c3d14e 100644 --- a/Octokit.Tests/Clients/RepositoryPagesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryPagesClientTests.cs @@ -41,7 +41,7 @@ public void RequestsCorrectUrl() client.GetAll("fake", "repo"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/pages/builds"), null, AcceptHeaders.StableVersion, Args.ApiOptions); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/pages/builds"), Args.ApiOptions); } [Fact] From eb73e97f6ab96cd9c509efc6f63edee89ab00412 Mon Sep 17 00:00:00 2001 From: Prayank Mathur Date: Wed, 30 Mar 2016 15:21:43 +0530 Subject: [PATCH 06/16] Added integration tests for the GetAll method --- .../Clients/RepositoryPagesClientTests.cs | 86 +++++++++++++++++++ .../Octokit.Tests.Integration.csproj | 1 + .../Clients/RepositoryPagesClientTests.cs | 2 +- 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs diff --git a/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs new file mode 100644 index 0000000000..3dbdd3a5a8 --- /dev/null +++ b/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Octokit; +using Octokit.Tests.Integration; +using Octokit.Tests.Integration.Helpers; +using Xunit; + +public class RepositoryPagesClientTests +{ + public class TheGetAllMethod + { + readonly IRepositoryPagesClient _repositoryPagesClient; + const string owner = "octokit"; + const string name = "octokit.net"; + + public TheGetAllMethod() + { + var github = Helper.GetAuthenticatedClient(); + _repositoryPagesClient = github.Repository.Page; + } + + [IntegrationTest] + public async Task ReturnsPages() + { + var pages = await _repositoryPagesClient.GetAll(owner, name); + Assert.NotEmpty(pages); + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfPagesWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var pages = await _repositoryPagesClient.GetAll(owner, name, options); + Assert.Equal(5, pages.Count); + } + + [IntegrationTest] + public async Task ReturnCorrectCountOfPagesWithStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var pages = await _repositoryPagesClient.GetAll(owner, name, options); + Assert.Equal(5, pages.Count); + } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPage() + { + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var firstPage = await _repositoryPagesClient.GetAll(owner, name, startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await _repositoryPagesClient.GetAll(owner, name, skipStartOptions); + + Assert.NotEqual(firstPage[0].Url, secondPage[0].Url); + Assert.NotEqual(firstPage[1].Url, secondPage[1].Url); + Assert.NotEqual(firstPage[2].Url, secondPage[2].Url); + Assert.NotEqual(firstPage[3].Url, secondPage[3].Url); + Assert.NotEqual(firstPage[4].Url, secondPage[4].Url); + } + } +} \ No newline at end of file diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 2609848218..da5d7e9ee5 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -101,6 +101,7 @@ + diff --git a/Octokit.Tests/Clients/RepositoryPagesClientTests.cs b/Octokit.Tests/Clients/RepositoryPagesClientTests.cs index 4907c3d14e..2993240290 100644 --- a/Octokit.Tests/Clients/RepositoryPagesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryPagesClientTests.cs @@ -31,7 +31,7 @@ public async Task EnsuresNonNullArguments() } } - public class TheGetAllBuildsMethod + public class TheGetAllMethod { [Fact] public void RequestsCorrectUrl() From ee7dcbd2c13a5c0ad4caa920ae784d6fa03c6366 Mon Sep 17 00:00:00 2001 From: Prayank Mathur Date: Wed, 30 Mar 2016 16:17:40 +0530 Subject: [PATCH 07/16] Some changes in description --- .../Clients/IObservableRepositoryPagesClient.cs | 2 +- Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs | 2 +- Octokit/Clients/IRepositoryPagesClient.cs | 6 +++--- Octokit/Clients/RepositoryPagesClient.cs | 5 +++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableRepositoryPagesClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryPagesClient.cs index 8033fc6c2a..8af9eee786 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryPagesClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryPagesClient.cs @@ -33,7 +33,7 @@ public interface IObservableRepositoryPagesClient /// /// The owner of the repository /// The name of the repository - /// Options to change the response of the API + /// Options to change the API response /// /// See the API documentation for more information. /// diff --git a/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs index 74f285e281..39e0bfa6ef 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs @@ -58,7 +58,7 @@ public IObservable GetAll(string owner, string repositoryName) /// /// The owner of the repository /// The name of the repository - /// Options to change the behaviour of the API + /// Options to change the API response /// /// See the API documentation for more information. /// diff --git a/Octokit/Clients/IRepositoryPagesClient.cs b/Octokit/Clients/IRepositoryPagesClient.cs index 2458466f3c..0716152ae9 100644 --- a/Octokit/Clients/IRepositoryPagesClient.cs +++ b/Octokit/Clients/IRepositoryPagesClient.cs @@ -29,7 +29,7 @@ public interface IRepositoryPagesClient /// /// The owner of the repository /// The name of the repository - /// + /// /// See the API documentation for more information. /// /// @@ -40,8 +40,8 @@ public interface IRepositoryPagesClient /// /// The owner of the repository /// The name of the repository - /// Options for changing the behaviour of the API - /// + /// Options to change the API response + /// /// See the API documentation for more information. /// /// diff --git a/Octokit/Clients/RepositoryPagesClient.cs b/Octokit/Clients/RepositoryPagesClient.cs index 139d57de4a..9958daefb1 100644 --- a/Octokit/Clients/RepositoryPagesClient.cs +++ b/Octokit/Clients/RepositoryPagesClient.cs @@ -41,7 +41,7 @@ public Task Get(string owner, string repositoryName) /// /// The owner of the repository /// The name of the repository - /// + /// /// See the API documentation for more information. /// /// @@ -59,7 +59,7 @@ public Task> GetAll(string owner, string repositoryNam /// The owner of the repository /// The name of the repository /// Options to change the API response - /// + /// /// See the API documentation for more information. /// /// @@ -72,6 +72,7 @@ public Task> GetAll(string owner, string repositoryNam var endpoint = ApiUrls.RepositoryPageBuilds(owner, repositoryName); return ApiConnection.GetAll(endpoint, options); } + /// /// Gets the build metadata for the last build for a given repository /// From 2a5da0ff1e8c6ce2dc7792f3e971d59db9fdf903 Mon Sep 17 00:00:00 2001 From: Prayank Mathur Date: Wed, 30 Mar 2016 16:22:57 +0530 Subject: [PATCH 08/16] Removed extraneous whitespace --- Octokit.Reactive/Clients/IObservableRepositoryPagesClient.cs | 3 ++- Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableRepositoryPagesClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryPagesClient.cs index 8af9eee786..1293eb31a9 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryPagesClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryPagesClient.cs @@ -34,11 +34,12 @@ public interface IObservableRepositoryPagesClient /// The owner of the repository /// The name of the repository /// Options to change the API response - /// + /// /// See the API documentation for more information. /// /// IObservable GetAll(string owner, string repositoryName, ApiOptions options); + /// /// Gets the build metadata for the last build for a given repository /// diff --git a/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs index 39e0bfa6ef..28d06ccc35 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs @@ -59,7 +59,7 @@ public IObservable GetAll(string owner, string repositoryName) /// The owner of the repository /// The name of the repository /// Options to change the API response - /// + /// /// See the API documentation for more information. /// /// From e5545c7bf750e17aeb9ba8b56d7a0b462223f863 Mon Sep 17 00:00:00 2001 From: Prayank Mathur Date: Thu, 7 Apr 2016 12:25:15 +0530 Subject: [PATCH 09/16] WIP adding integration tests --- .../Clients/RepositoryPagesClientTests.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs index 3dbdd3a5a8..b224d21575 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs @@ -10,6 +10,25 @@ public class RepositoryPagesClientTests { + public class TheGetMethod + { + readonly IRepositoryPagesClient _repositoryPagesClient; + const string owner = "octokit"; + const string name = "octokit.net"; + + public TheGetMethod() + { + var github = Helper.GetAuthenticatedClient(); + _repositoryPagesClient = github.Repository.Page; + } + + [IntegrationTest] + public async Task ReturnsMetadata() + { + var data = await _repositoryPagesClient.Get(owner, name); + Assert.Equal(data.CName, "octokit.net"); + } + } public class TheGetAllMethod { readonly IRepositoryPagesClient _repositoryPagesClient; From 7f83e741255a9e215d848fa379dc2b0f24c0c0fa Mon Sep 17 00:00:00 2001 From: Prayank Mathur Date: Thu, 7 Apr 2016 12:45:08 +0530 Subject: [PATCH 10/16] Modified tests --- .../Clients/RepositoryPagesClientTests.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs index b224d21575..1e5a606245 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs @@ -1,11 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Threading.Tasks; using Octokit; using Octokit.Tests.Integration; -using Octokit.Tests.Integration.Helpers; using Xunit; public class RepositoryPagesClientTests @@ -26,7 +21,7 @@ public TheGetMethod() public async Task ReturnsMetadata() { var data = await _repositoryPagesClient.Get(owner, name); - Assert.Equal(data.CName, "octokit.net"); + Assert.Equal("https://api.github.com/repos/octokit/octokit.net/pages", data.Url); } } public class TheGetAllMethod From 8ca8227ba08dfdfbe3e25a609588771689df23e0 Mon Sep 17 00:00:00 2001 From: Prayank Mathur Date: Thu, 7 Apr 2016 12:59:00 +0530 Subject: [PATCH 11/16] Fixes --- .../Clients/RepositoryPagesClientTests.cs | 19 +++++++++++++++++++ .../Octokit.Tests.Integration.csproj | 2 +- ...servableRepositoryDeployKeysClientTests.cs | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs index 1e5a606245..42137555d0 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs @@ -96,5 +96,24 @@ public async Task ReturnsDistinctResultsBasedOnStartPage() Assert.NotEqual(firstPage[3].Url, secondPage[3].Url); Assert.NotEqual(firstPage[4].Url, secondPage[4].Url); } + + public class TheGetLatestMethod + { + readonly IRepositoryPagesClient _repositoryPagesClient; + const string owner = "octokit"; + const string name = "octokit.net"; + + public TheGetLatestMethod() + { + _repositoryPagesClient = Helper.GetAuthenticatedClient().Repository.Page; + } + + public async Task ReturnsMetadata() + { + var data = _repositoryPagesClient.GetLatest(owner, name); + + Assert.NotNull(data.Id); + } + } } } \ No newline at end of file diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index a92378cc02..6c775ab366 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -150,8 +150,8 @@ + - diff --git a/Octokit.Tests.Integration/Reactive/ObservableRepositoryDeployKeysClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableRepositoryDeployKeysClientTests.cs index 3df43c1705..bbcf8ef53a 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableRepositoryDeployKeysClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableRepositoryDeployKeysClientTests.cs @@ -103,4 +103,4 @@ public void Dispose() { Helper.DeleteRepo(_repository); } -} +} \ No newline at end of file From 2f1943a6408aa3c36b3cbacfb2117c9214ce2e93 Mon Sep 17 00:00:00 2001 From: Prayank Mathur Date: Sun, 10 Apr 2016 17:02:37 +0530 Subject: [PATCH 12/16] Added unit tests for Reactive functions --- .../ObservableRepositoryPagesClient.cs | 6 +++ .../Clients/RepositoryPagesClientTests.cs | 1 + .../Clients/RepositoryPagesClientTests.cs | 10 ++++ Octokit.Tests/Octokit.Tests.csproj | 1 + .../ObservableRepositoryPagesClientTests.cs | 48 +++++++++++++++++++ 5 files changed, 66 insertions(+) create mode 100644 Octokit.Tests/Reactive/ObservableRepositoryPagesClientTests.cs diff --git a/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs index 28d06ccc35..16df2d91fe 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs @@ -7,9 +7,15 @@ namespace Octokit.Reactive { public class ObservableRepositoryPagesClient : IObservableRepositoryPagesClient { + private Func @for; readonly IRepositoryPagesClient _client; readonly IConnection _connection; + public ObservableRepositoryPagesClient(Func @for) + { + this.@for = @for; + } + public ObservableRepositoryPagesClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); diff --git a/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs index 42137555d0..71e9a0b7cf 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs @@ -24,6 +24,7 @@ public async Task ReturnsMetadata() Assert.Equal("https://api.github.com/repos/octokit/octokit.net/pages", data.Url); } } + public class TheGetAllMethod { readonly IRepositoryPagesClient _repositoryPagesClient; diff --git a/Octokit.Tests/Clients/RepositoryPagesClientTests.cs b/Octokit.Tests/Clients/RepositoryPagesClientTests.cs index 2993240290..8c7a1f5769 100644 --- a/Octokit.Tests/Clients/RepositoryPagesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryPagesClientTests.cs @@ -54,6 +54,16 @@ public async Task EnsuresNonNullArguments() await Assert.ThrowsAsync(() => client.GetAll("owner", null, new ApiOptions())); await Assert.ThrowsAsync(() => client.GetAll("owner", "name", null)); } + + [Fact] + public async Task EnsuresNonEmptyArguments() + { + var connection = Substitute.For(); + var client = new RepositoryPagesClient(connection); + + await Assert.ThrowsAsync(() => client.GetAll("", "name", new ApiOptions())); + await Assert.ThrowsAsync(() => client.GetAll("owner", "", new ApiOptions())); + } } public class TheGetLatestBuildMethod diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index 8aee294e26..2051df68e7 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -216,6 +216,7 @@ + diff --git a/Octokit.Tests/Reactive/ObservableRepositoryPagesClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoryPagesClientTests.cs new file mode 100644 index 0000000000..133547cbe5 --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableRepositoryPagesClientTests.cs @@ -0,0 +1,48 @@ +using System; +using NSubstitute; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Reactive +{ + public class ObservableRepositoryPagesClientTests + { + public class TheGetAllMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var githubClient = Substitute.For(); + var client = new ObservableRepositoryPagesClient(githubClient); + var options = new ApiOptions(); + + client.GetAll("fake", "repo", options); + + githubClient.Repository.Page.Received().GetAll("fake", "repo", options); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var githubClient = Substitute.For(); + var client = new ObservableRepositoryPagesClient(githubClient); + var options = new ApiOptions(); + + Assert.Throws(() => client.GetAll(null, "repo", new ApiOptions())); + Assert.Throws(() => client.GetAll("owner", null, new ApiOptions())); + Assert.Throws(() => client.GetAll("owner", "repo", null)); + } + + [Fact] + public void EnsuresNonEmptyArguments() + { + var githubClient = Substitute.For(); + var client = new ObservableRepositoryPagesClient(githubClient); + var options = new ApiOptions(); + + Assert.Throws(() => client.GetAll("", "repo", new ApiOptions())); + Assert.Throws(() => client.GetAll("owner", "", new ApiOptions())); + } + } + } +} From 96818f484dbd1a70cfaecc3e8a28d6b0072d2d13 Mon Sep 17 00:00:00 2001 From: Prayank Mathur Date: Sun, 10 Apr 2016 17:06:16 +0530 Subject: [PATCH 13/16] Tidying --- Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs index 16df2d91fe..28d06ccc35 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs @@ -7,15 +7,9 @@ namespace Octokit.Reactive { public class ObservableRepositoryPagesClient : IObservableRepositoryPagesClient { - private Func @for; readonly IRepositoryPagesClient _client; readonly IConnection _connection; - public ObservableRepositoryPagesClient(Func @for) - { - this.@for = @for; - } - public ObservableRepositoryPagesClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); From 9b38fff064bd6e45f4444b4f20f9b635de3377be Mon Sep 17 00:00:00 2001 From: Prayank Mathur Date: Sun, 10 Apr 2016 22:00:44 +0530 Subject: [PATCH 14/16] Fixed unit tests --- .../Reactive/ObservableRepositoryPagesClientTests.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Octokit.Tests/Reactive/ObservableRepositoryPagesClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoryPagesClientTests.cs index 133547cbe5..da5c107588 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoryPagesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoryPagesClientTests.cs @@ -17,8 +17,7 @@ public void RequestsCorrectUrl() var options = new ApiOptions(); client.GetAll("fake", "repo", options); - - githubClient.Repository.Page.Received().GetAll("fake", "repo", options); + githubClient.Received().Repository.Page.GetAll("fake", "repo", options); } [Fact] @@ -26,7 +25,6 @@ public void EnsuresNonNullArguments() { var githubClient = Substitute.For(); var client = new ObservableRepositoryPagesClient(githubClient); - var options = new ApiOptions(); Assert.Throws(() => client.GetAll(null, "repo", new ApiOptions())); Assert.Throws(() => client.GetAll("owner", null, new ApiOptions())); @@ -38,7 +36,6 @@ public void EnsuresNonEmptyArguments() { var githubClient = Substitute.For(); var client = new ObservableRepositoryPagesClient(githubClient); - var options = new ApiOptions(); Assert.Throws(() => client.GetAll("", "repo", new ApiOptions())); Assert.Throws(() => client.GetAll("owner", "", new ApiOptions())); From 33d237a90dc827a55732205ff3d4d9121815ca37 Mon Sep 17 00:00:00 2001 From: Prayank Mathur Date: Mon, 11 Apr 2016 09:57:03 +0530 Subject: [PATCH 15/16] Resolved conflicts --- Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs | 1 + Octokit.Tests.Integration/Octokit.Tests.Integration.csproj | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs index 71e9a0b7cf..e4c5ef9008 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs @@ -109,6 +109,7 @@ public TheGetLatestMethod() _repositoryPagesClient = Helper.GetAuthenticatedClient().Repository.Page; } + [IntegrationTest] public async Task ReturnsMetadata() { var data = _repositoryPagesClient.GetLatest(owner, name); diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 7a80595a5d..e5b649c1e8 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -138,7 +138,6 @@ - From 8313864c9848af91ceba88609352be7e8007b048 Mon Sep 17 00:00:00 2001 From: Prayank Mathur Date: Mon, 11 Apr 2016 10:08:07 +0530 Subject: [PATCH 16/16] Admin rights tests stripped down --- .../Clients/RepositoryPagesClientTests.cs | 96 +------------------ .../ObservableRepositoryPagesClientTests.cs | 56 +---------- 2 files changed, 2 insertions(+), 150 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs index e4c5ef9008..ba2d614c88 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs @@ -17,105 +17,11 @@ public TheGetMethod() _repositoryPagesClient = github.Repository.Page; } - [IntegrationTest] + [IntegrationTest(Skip= "These tests require repository admin rights - see https://github.com/octokit/octokit.net/issues/1263 for discussion")] public async Task ReturnsMetadata() { var data = await _repositoryPagesClient.Get(owner, name); Assert.Equal("https://api.github.com/repos/octokit/octokit.net/pages", data.Url); } } - - public class TheGetAllMethod - { - readonly IRepositoryPagesClient _repositoryPagesClient; - const string owner = "octokit"; - const string name = "octokit.net"; - - public TheGetAllMethod() - { - var github = Helper.GetAuthenticatedClient(); - _repositoryPagesClient = github.Repository.Page; - } - - [IntegrationTest] - public async Task ReturnsPages() - { - var pages = await _repositoryPagesClient.GetAll(owner, name); - Assert.NotEmpty(pages); - } - - [IntegrationTest] - public async Task ReturnsCorrectCountOfPagesWithoutStart() - { - var options = new ApiOptions - { - PageSize = 5, - PageCount = 1 - }; - - var pages = await _repositoryPagesClient.GetAll(owner, name, options); - Assert.Equal(5, pages.Count); - } - - [IntegrationTest] - public async Task ReturnCorrectCountOfPagesWithStart() - { - var options = new ApiOptions - { - PageSize = 5, - PageCount = 1, - StartPage = 2 - }; - - var pages = await _repositoryPagesClient.GetAll(owner, name, options); - Assert.Equal(5, pages.Count); - } - - [IntegrationTest] - public async Task ReturnsDistinctResultsBasedOnStartPage() - { - var startOptions = new ApiOptions - { - PageSize = 5, - PageCount = 1 - }; - - var firstPage = await _repositoryPagesClient.GetAll(owner, name, startOptions); - - var skipStartOptions = new ApiOptions - { - PageSize = 5, - PageCount = 1, - StartPage = 2 - }; - - var secondPage = await _repositoryPagesClient.GetAll(owner, name, skipStartOptions); - - Assert.NotEqual(firstPage[0].Url, secondPage[0].Url); - Assert.NotEqual(firstPage[1].Url, secondPage[1].Url); - Assert.NotEqual(firstPage[2].Url, secondPage[2].Url); - Assert.NotEqual(firstPage[3].Url, secondPage[3].Url); - Assert.NotEqual(firstPage[4].Url, secondPage[4].Url); - } - - public class TheGetLatestMethod - { - readonly IRepositoryPagesClient _repositoryPagesClient; - const string owner = "octokit"; - const string name = "octokit.net"; - - public TheGetLatestMethod() - { - _repositoryPagesClient = Helper.GetAuthenticatedClient().Repository.Page; - } - - [IntegrationTest] - public async Task ReturnsMetadata() - { - var data = _repositoryPagesClient.GetLatest(owner, name); - - Assert.NotNull(data.Id); - } - } - } } \ No newline at end of file diff --git a/Octokit.Tests.Integration/Reactive/ObservableRepositoryPagesClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableRepositoryPagesClientTests.cs index 34677032da..75b7fb3a73 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableRepositoryPagesClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableRepositoryPagesClientTests.cs @@ -20,67 +20,13 @@ public TheGetAllMethod() _repositoryPagesClient = new ObservableRepositoryPagesClient(github); } - [IntegrationTest] + [IntegrationTest(Skip = "These tests require repository admin rights - see https://github.com/octokit/octokit.net/issues/1263 for discussion")] public async Task ReturnsRepositoryPages() { var pages = await _repositoryPagesClient.GetAll(owner, name).ToList(); Assert.NotEmpty(pages); } - - [IntegrationTest] - public async Task ReturnsCorrectCountOfPagesWithoutStart() - { - var options = new ApiOptions - { - PageSize = 5, - PageCount = 1 - }; - - var pages = await _repositoryPagesClient.GetAll(owner, name, options).ToList(); - Assert.Equal(5, pages.Count); - } - - [IntegrationTest] - public async Task ReturnCorrectCountOfPagesWithStart() - { - var options = new ApiOptions - { - PageSize = 5, - PageCount = 1, - StartPage = 2 - }; - - var pages = await _repositoryPagesClient.GetAll(owner, name, options).ToList(); - Assert.Equal(5, pages.Count); - } - - [IntegrationTest] - public async Task ReturnsDistinctResultsBasedOnStartPage() - { - var startOptions = new ApiOptions - { - PageSize = 5, - PageCount = 1 - }; - - var firstPage = await _repositoryPagesClient.GetAll(owner, name, startOptions).ToList(); - - var skipStartOptions = new ApiOptions - { - PageSize = 5, - PageCount = 1, - StartPage = 2 - }; - - var secondPage = await _repositoryPagesClient.GetAll(owner, name, skipStartOptions).ToList(); - - Assert.NotEqual(firstPage[0].Url, secondPage[0].Url); - Assert.NotEqual(firstPage[1].Url, secondPage[1].Url); - Assert.NotEqual(firstPage[2].Url, secondPage[2].Url); - Assert.NotEqual(firstPage[3].Url, secondPage[3].Url); - Assert.NotEqual(firstPage[4].Url, secondPage[4].Url); - } } } }