From 8f548254f1fcd9b7369f70b289113006710f6f3b Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Thu, 17 Mar 2016 15:34:01 +0700 Subject: [PATCH 1/8] New overloaded method Task> GetAll(ApiOptions options) has been added on IAuthorizationsClient and implemented on AuthorizationsClient. --- Octokit/Clients/AuthorizationsClient.cs | 22 +++++++++++++++++++++- Octokit/Clients/IAuthorizationsClient.cs | 17 +++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/Octokit/Clients/AuthorizationsClient.cs b/Octokit/Clients/AuthorizationsClient.cs index 84b41b78cc..09b8bf5a43 100644 --- a/Octokit/Clients/AuthorizationsClient.cs +++ b/Octokit/Clients/AuthorizationsClient.cs @@ -36,7 +36,27 @@ public AuthorizationsClient(IApiConnection apiConnection) : base(apiConnection) /// A list of s. public Task> GetAll() { - return ApiConnection.GetAll(ApiUrls.Authorizations(), ApiOptions.None); + return GetAll(ApiOptions.None); + } + + /// + /// Gets all s for the authenticated user. + /// + /// + /// This method requires authentication. + /// See the API documentation for more information. + /// + /// Options for changing the API response + /// + /// Thrown when the current user does not have permission to make the request. + /// + /// Thrown when a general API error occurs. + /// A list of s. + public Task> GetAll(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return ApiConnection.GetAll(ApiUrls.Authorizations(), options); } /// diff --git a/Octokit/Clients/IAuthorizationsClient.cs b/Octokit/Clients/IAuthorizationsClient.cs index 81b8db48f2..72406ad332 100644 --- a/Octokit/Clients/IAuthorizationsClient.cs +++ b/Octokit/Clients/IAuthorizationsClient.cs @@ -31,6 +31,23 @@ public interface IAuthorizationsClient Justification = "It's an API call, so it's not a property.")] Task> GetAll(); + /// + /// Gets all s for the authenticated user. + /// + /// + /// This method requires authentication. + /// See the API documentation for more information. + /// + /// Options for changing the API response + /// + /// Thrown when the current user does not have permission to make the request. + /// + /// Thrown when a general API error occurs. + /// A list of s. + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", + Justification = "It's an API call, so it's not a property.")] + Task> GetAll(ApiOptions options); + /// /// Gets a specific for the authenticated user. /// From 5b166ebc4269aac07d6c1e4b6bc7486a8b691b6e Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Thu, 17 Mar 2016 15:34:36 +0700 Subject: [PATCH 2/8] New overloaded method IObservable GetAll(ApiOptions options) has been added on IObservableAuthorizationsClient and implemented on ObservableAuthorizationsClient. --- .../Clients/IObservableAuthorizationsClient.cs | 13 +++++++++++++ .../Clients/ObservableAuthorizationsClient.cs | 18 +++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Octokit.Reactive/Clients/IObservableAuthorizationsClient.cs b/Octokit.Reactive/Clients/IObservableAuthorizationsClient.cs index c72986fd01..88382ccca7 100644 --- a/Octokit.Reactive/Clients/IObservableAuthorizationsClient.cs +++ b/Octokit.Reactive/Clients/IObservableAuthorizationsClient.cs @@ -18,6 +18,19 @@ public interface IObservableAuthorizationsClient Justification = "It's an API call, so it's not a property.")] IObservable GetAll(); + /// + /// Get all s for the authenticated user. This method requires basic auth. + /// + /// + /// See API documentation for more + /// details. + /// + /// Options for changing the API response + /// An + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", + Justification = "It's an API call, so it's not a property.")] + IObservable GetAll(ApiOptions options); + /// /// Get a specific for the authenticated user. This method requires basic auth. /// diff --git a/Octokit.Reactive/Clients/ObservableAuthorizationsClient.cs b/Octokit.Reactive/Clients/ObservableAuthorizationsClient.cs index 9d5127b771..c6d4de6af3 100644 --- a/Octokit.Reactive/Clients/ObservableAuthorizationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableAuthorizationsClient.cs @@ -28,7 +28,23 @@ public ObservableAuthorizationsClient(IGitHubClient client) /// An public IObservable GetAll() { - return _connection.GetAndFlattenAllPages(ApiUrls.Authorizations()); + return GetAll(ApiOptions.None); + } + + /// + /// Get all s for the authenticated user. This method requires basic auth. + /// + /// + /// See API documentation for more + /// details. + /// + /// Options for changing the API response + /// An + public IObservable GetAll(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Authorizations(), options); } /// From fb8acd3d1aced612e005b53bc81c6c1c08863c3f Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Thu, 17 Mar 2016 15:37:01 +0700 Subject: [PATCH 3/8] New unit tests have been added to check AuthorizationsClient implementation. --- Octokit.Tests/Clients/AuthorizationsClientTests.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Octokit.Tests/Clients/AuthorizationsClientTests.cs b/Octokit.Tests/Clients/AuthorizationsClientTests.cs index 5aad42eff0..6a50858211 100644 --- a/Octokit.Tests/Clients/AuthorizationsClientTests.cs +++ b/Octokit.Tests/Clients/AuthorizationsClientTests.cs @@ -37,6 +37,19 @@ public void GetsAListOfAuthorizations() Arg.Is(u => u.ToString() == "authorizations"), Args.ApiOptions); } + + [Fact] + public void GetsAListOfAuthorizationsWithApiOptions() + { + var client = Substitute.For(); + var authEndpoint = new AuthorizationsClient(client); + + authEndpoint.GetAll(ApiOptions.None); + + client.Received().GetAll( + Arg.Is(u => u.ToString() == "authorizations"), + Args.ApiOptions); + } } public class TheGetMethod From f8c776485636efb77fb48d060fa39ce18efdb679 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Thu, 17 Mar 2016 15:37:23 +0700 Subject: [PATCH 4/8] New unit tests have been added to check ObservableAuthorizationsClient implementation. --- Octokit.Tests/Octokit.Tests.csproj | 1 + .../ObservableAuthorizationsClientTests.cs | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 Octokit.Tests/Reactive/ObservableAuthorizationsClientTests.cs diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index 5c6484c309..cb994ec614 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -198,6 +198,7 @@ + diff --git a/Octokit.Tests/Reactive/ObservableAuthorizationsClientTests.cs b/Octokit.Tests/Reactive/ObservableAuthorizationsClientTests.cs new file mode 100644 index 0000000000..5aa84daf9d --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableAuthorizationsClientTests.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using NSubstitute; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Reactive +{ + public class ObservableAuthorizationsClientTests + { + public class TheGetAllMethod + { + [Fact] + public void GetsCorrectUrl() + { + var client = Substitute.For(); + var authEndpoint = new ObservableAuthorizationsClient(client); + + authEndpoint.GetAll(); + + client.Connection.Received(1).Get>(Arg.Is(u => u.ToString() == "authorizations"), + Arg.Is>(dictionary => dictionary.Count == 0), null); + } + + [Fact] + public void GetsCorrectUrlWithApiOption() + { + var client = Substitute.For(); + var authEndpoint = new ObservableAuthorizationsClient(client); + + authEndpoint.GetAll(ApiOptions.None); + + client.Connection.Received(1).Get>(Arg.Is(u => u.ToString() == "authorizations"), + Arg.Is>(dictionary => dictionary.Count == 0), null); + } + } + + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new ObservableAuthorizationsClient(null)); + } + } + } +} From 6009cc9720ba902431e6380e741d199f4b308a03 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Thu, 17 Mar 2016 17:06:17 +0700 Subject: [PATCH 5/8] Documentation of methods have been updated. --- Octokit.Reactive/Clients/IObservableAuthorizationsClient.cs | 4 ++-- Octokit.Reactive/Clients/ObservableAuthorizationsClient.cs | 4 ++-- Octokit/Clients/AuthorizationsClient.cs | 4 ++-- Octokit/Clients/IAuthorizationsClient.cs | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableAuthorizationsClient.cs b/Octokit.Reactive/Clients/IObservableAuthorizationsClient.cs index 88382ccca7..0e5083fd15 100644 --- a/Octokit.Reactive/Clients/IObservableAuthorizationsClient.cs +++ b/Octokit.Reactive/Clients/IObservableAuthorizationsClient.cs @@ -13,7 +13,7 @@ public interface IObservableAuthorizationsClient /// See API documentation for more /// details. /// - /// An + /// A list of s for the authenticated user. [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "It's an API call, so it's not a property.")] IObservable GetAll(); @@ -26,7 +26,7 @@ public interface IObservableAuthorizationsClient /// details. /// /// Options for changing the API response - /// An + /// A list of s for the authenticated user. [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "It's an API call, so it's not a property.")] IObservable GetAll(ApiOptions options); diff --git a/Octokit.Reactive/Clients/ObservableAuthorizationsClient.cs b/Octokit.Reactive/Clients/ObservableAuthorizationsClient.cs index c6d4de6af3..d5cd198954 100644 --- a/Octokit.Reactive/Clients/ObservableAuthorizationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableAuthorizationsClient.cs @@ -25,7 +25,7 @@ public ObservableAuthorizationsClient(IGitHubClient client) /// See API documentation for more /// details. /// - /// An + /// A list of s for the authenticated user. public IObservable GetAll() { return GetAll(ApiOptions.None); @@ -39,7 +39,7 @@ public IObservable GetAll() /// details. /// /// Options for changing the API response - /// An + /// A list of s for the authenticated user. public IObservable GetAll(ApiOptions options) { Ensure.ArgumentNotNull(options, "options"); diff --git a/Octokit/Clients/AuthorizationsClient.cs b/Octokit/Clients/AuthorizationsClient.cs index 09b8bf5a43..92a4cf4b6d 100644 --- a/Octokit/Clients/AuthorizationsClient.cs +++ b/Octokit/Clients/AuthorizationsClient.cs @@ -33,7 +33,7 @@ public AuthorizationsClient(IApiConnection apiConnection) : base(apiConnection) /// Thrown when the current user does not have permission to make the request. /// /// Thrown when a general API error occurs. - /// A list of s. + /// A list of s for the authenticated user. public Task> GetAll() { return GetAll(ApiOptions.None); @@ -51,7 +51,7 @@ public Task> GetAll() /// Thrown when the current user does not have permission to make the request. /// /// Thrown when a general API error occurs. - /// A list of s. + /// A list of s for the authenticated user. public Task> GetAll(ApiOptions options) { Ensure.ArgumentNotNull(options, "options"); diff --git a/Octokit/Clients/IAuthorizationsClient.cs b/Octokit/Clients/IAuthorizationsClient.cs index 72406ad332..c78a048d17 100644 --- a/Octokit/Clients/IAuthorizationsClient.cs +++ b/Octokit/Clients/IAuthorizationsClient.cs @@ -26,7 +26,7 @@ public interface IAuthorizationsClient /// Thrown when the current user does not have permission to make the request. /// /// Thrown when a general API error occurs. - /// A list of s. + /// A list of s for the authenticated user. [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "It's an API call, so it's not a property.")] Task> GetAll(); @@ -43,7 +43,7 @@ public interface IAuthorizationsClient /// Thrown when the current user does not have permission to make the request. /// /// Thrown when a general API error occurs. - /// A list of s. + /// A list of s for the authenticated user. [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "It's an API call, so it's not a property.")] Task> GetAll(ApiOptions options); From a00d08149e021d3cab2d8fa7b33851e7833d5a68 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Fri, 18 Mar 2016 13:49:54 +0700 Subject: [PATCH 6/8] The names of unit tests has been corrected in order to fit IReleaseClient unit test name convention (Gets prefix -> Requests prefix). --- Octokit.Tests/Clients/AuthorizationsClientTests.cs | 4 ++-- Octokit.Tests/Reactive/ObservableAuthorizationsClientTests.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Octokit.Tests/Clients/AuthorizationsClientTests.cs b/Octokit.Tests/Clients/AuthorizationsClientTests.cs index 6a50858211..0b0b855e91 100644 --- a/Octokit.Tests/Clients/AuthorizationsClientTests.cs +++ b/Octokit.Tests/Clients/AuthorizationsClientTests.cs @@ -26,7 +26,7 @@ public void ThrowsForBadArgs() public class TheGetAllMethod { [Fact] - public void GetsAListOfAuthorizations() + public void RequestsCorrectUrl() { var client = Substitute.For(); var authEndpoint = new AuthorizationsClient(client); @@ -39,7 +39,7 @@ public void GetsAListOfAuthorizations() } [Fact] - public void GetsAListOfAuthorizationsWithApiOptions() + public void RequestsCorrectUrlWithApiOptions() { var client = Substitute.For(); var authEndpoint = new AuthorizationsClient(client); diff --git a/Octokit.Tests/Reactive/ObservableAuthorizationsClientTests.cs b/Octokit.Tests/Reactive/ObservableAuthorizationsClientTests.cs index 5aa84daf9d..241950bb07 100644 --- a/Octokit.Tests/Reactive/ObservableAuthorizationsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableAuthorizationsClientTests.cs @@ -11,7 +11,7 @@ public class ObservableAuthorizationsClientTests public class TheGetAllMethod { [Fact] - public void GetsCorrectUrl() + public void RequestsCorrectUrl() { var client = Substitute.For(); var authEndpoint = new ObservableAuthorizationsClient(client); @@ -23,7 +23,7 @@ public void GetsCorrectUrl() } [Fact] - public void GetsCorrectUrlWithApiOption() + public void RequestsCorrectUrlWithApiOption() { var client = Substitute.For(); var authEndpoint = new ObservableAuthorizationsClient(client); From 63b58527c6ba1c7596030674d4223a2615006d16 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Fri, 18 Mar 2016 13:50:59 +0700 Subject: [PATCH 7/8] New integration tests for IAuthorizationsClient and IObservableAuthorizationsClient have been added. --- .../Clients/AuthorizationClientTests.cs | 40 ++++++++++++++-- .../Octokit.Tests.Integration.csproj | 1 + .../ObservableAuthorizationsClientTests.cs | 46 +++++++++++++++++++ 3 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 Octokit.Tests.Integration/Reactive/ObservableAuthorizationsClientTests.cs diff --git a/Octokit.Tests.Integration/Clients/AuthorizationClientTests.cs b/Octokit.Tests.Integration/Clients/AuthorizationClientTests.cs index 3108c42b85..994c29b524 100644 --- a/Octokit.Tests.Integration/Clients/AuthorizationClientTests.cs +++ b/Octokit.Tests.Integration/Clients/AuthorizationClientTests.cs @@ -1,5 +1,4 @@ -using System; -using System.Threading.Tasks; +using System.Threading.Tasks; using Xunit; namespace Octokit.Tests.Integration.Clients @@ -13,7 +12,7 @@ public async Task CanCreatePersonalToken() var note = Helper.MakeNameWithTimestamp("Testing authentication"); var newAuthorization = new NewAuthorization( note, - new string[] { "user" }); + new[] { "user" }); var created = await github.Authorization.Create(newAuthorization); @@ -27,6 +26,39 @@ public async Task CanCreatePersonalToken() Assert.Equal(created.Note, get.Note); } + [IntegrationTest] + public async Task CanGetAuthorization() + { + var github = Helper.GetBasicAuthClient(); + + var authorizations = await github.Authorization.GetAll(); + Assert.NotEmpty(authorizations); + } + + [IntegrationTest] + public async Task CanGetAuthorizationWithApiOptions() + { + var github = Helper.GetBasicAuthClient(); + + var authorizations = await github.Authorization.GetAll(ApiOptions.None); + Assert.NotEmpty(authorizations); + } + + [IntegrationTest] + public async Task ReturnsNotEmptyAuthorizationsWithoutStart() + { + var github = Helper.GetBasicAuthClient(); + + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var authorizations = await github.Authorization.GetAll(options); + Assert.NotEmpty(authorizations); + } + [IntegrationTest] public async Task CannotCreatePersonalTokenWhenUsingOauthTokenCredentials() { @@ -34,7 +66,7 @@ public async Task CannotCreatePersonalTokenWhenUsingOauthTokenCredentials() var note = Helper.MakeNameWithTimestamp("Testing authentication"); var newAuthorization = new NewAuthorization( note, - new string[] { "user" }); + new[] { "user" }); var error = Assert.ThrowsAsync(() => github.Authorization.Create(newAuthorization)); Assert.True(error.Result.Message.Contains("username and password Basic Auth")); diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 0a5c12a316..4181ab35f2 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -138,6 +138,7 @@ + diff --git a/Octokit.Tests.Integration/Reactive/ObservableAuthorizationsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableAuthorizationsClientTests.cs new file mode 100644 index 0000000000..348eb77491 --- /dev/null +++ b/Octokit.Tests.Integration/Reactive/ObservableAuthorizationsClientTests.cs @@ -0,0 +1,46 @@ +using System.Reactive.Linq; +using System.Threading.Tasks; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Integration.Reactive +{ + public class ObservableAuthorizationsClientTests + { + readonly ObservableAuthorizationsClient _authorizationsClient; + + public ObservableAuthorizationsClientTests() + { + var github = Helper.GetBasicAuthClient(); + + _authorizationsClient = new ObservableAuthorizationsClient(github); + } + + [IntegrationTest] + public async Task CanGetAuthorization() + { + var authorization = await _authorizationsClient.GetAll(); + Assert.NotNull(authorization); + } + + [IntegrationTest] + public async Task CanGetAuthorizationWithApiOptions() + { + var authorization = await _authorizationsClient.GetAll(ApiOptions.None); + Assert.NotNull(authorization); + } + + [IntegrationTest] + public async Task ReturnsNotEmptyAuthorizationsWithoutStart() + { + var options = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var authorizations = await _authorizationsClient.GetAll(options).ToList(); + Assert.NotEmpty(authorizations); + } + } +} From 1a5658d31f4241a899222cb1db44499949093c28 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Mon, 21 Mar 2016 23:25:54 +0700 Subject: [PATCH 8/8] Add some new tests for overloaded methods. --- .../Clients/ObservableAssigneesClient.cs | 5 +--- Octokit.Tests/Clients/AssigneesClientTests.cs | 26 +++++++++++++++++-- .../Clients/AuthorizationsClientTests.cs | 22 +++++++++++++--- Octokit.Tests/Clients/ReleasesClientTests.cs | 22 ++++++++++++++++ .../Clients/UserEmailsClientTests.cs | 24 ++++++++++++++--- .../ObservableAuthorizationsClientTests.cs | 13 +++++++++- 6 files changed, 98 insertions(+), 14 deletions(-) diff --git a/Octokit.Reactive/Clients/ObservableAssigneesClient.cs b/Octokit.Reactive/Clients/ObservableAssigneesClient.cs index 287179347c..beabc06de0 100644 --- a/Octokit.Reactive/Clients/ObservableAssigneesClient.cs +++ b/Octokit.Reactive/Clients/ObservableAssigneesClient.cs @@ -25,10 +25,7 @@ public ObservableAssigneesClient(IGitHubClient client) /// public IObservable GetAllForRepository(string owner, string name) { - Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); - Ensure.ArgumentNotNullOrEmptyString(name, "name"); - - return _connection.GetAndFlattenAllPages(ApiUrls.Assignees(owner, name)); + return GetAllForRepository(owner, name, ApiOptions.None); } /// diff --git a/Octokit.Tests/Clients/AssigneesClientTests.cs b/Octokit.Tests/Clients/AssigneesClientTests.cs index ac4a7bc073..e5c5601896 100644 --- a/Octokit.Tests/Clients/AssigneesClientTests.cs +++ b/Octokit.Tests/Clients/AssigneesClientTests.cs @@ -4,14 +4,13 @@ using System.Threading.Tasks; using NSubstitute; using Octokit.Internal; -using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests.Clients { public class AssigneesClientTests { - public class TheGetForRepositoryMethod + public class TheGetAllMethod { [Fact] public void RequestsCorrectUrl() @@ -28,6 +27,28 @@ public void RequestsCorrectUrl() Args.ApiOptions); } + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new AssigneesClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + client.GetAllForRepository("fake", "repo", options); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repos/fake/repo/assignees"), + null, + AcceptHeaders.StableVersion, + options); + } + [Fact] public async Task EnsuresNonNullArguments() { @@ -37,6 +58,7 @@ public async Task EnsuresNonNullArguments() await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "")); await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null)); await Assert.ThrowsAsync(() => client.GetAllForRepository("", null)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", null)); } } diff --git a/Octokit.Tests/Clients/AuthorizationsClientTests.cs b/Octokit.Tests/Clients/AuthorizationsClientTests.cs index 0b0b855e91..0724d76bdf 100644 --- a/Octokit.Tests/Clients/AuthorizationsClientTests.cs +++ b/Octokit.Tests/Clients/AuthorizationsClientTests.cs @@ -43,12 +43,28 @@ public void RequestsCorrectUrlWithApiOptions() { var client = Substitute.For(); var authEndpoint = new AuthorizationsClient(client); - - authEndpoint.GetAll(ApiOptions.None); + + var options = new ApiOptions + { + StartPage = 1, + PageSize = 1, + PageCount = 1 + }; + + authEndpoint.GetAll(options); client.Received().GetAll( Arg.Is(u => u.ToString() == "authorizations"), - Args.ApiOptions); + options); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var client = Substitute.For(); + var authEndpoint = new AuthorizationsClient(client); + + await Assert.ThrowsAsync(() => authEndpoint.GetAll(null)); } } diff --git a/Octokit.Tests/Clients/ReleasesClientTests.cs b/Octokit.Tests/Clients/ReleasesClientTests.cs index d82c07072d..10ce49a8d8 100644 --- a/Octokit.Tests/Clients/ReleasesClientTests.cs +++ b/Octokit.Tests/Clients/ReleasesClientTests.cs @@ -24,6 +24,27 @@ public void RequestsCorrectUrl() Args.ApiOptions); } + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var client = Substitute.For(); + var releasesClient = new ReleasesClient(client); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 1 + }; + + releasesClient.GetAll("fake", "repo", options); + + client.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/releases"), + null, + "application/vnd.github.v3", + options); + } + [Fact] public async Task EnsuresNonNullArguments() { @@ -31,6 +52,7 @@ public async Task EnsuresNonNullArguments() await Assert.ThrowsAsync(() => releasesClient.GetAll(null, "name")); await Assert.ThrowsAsync(() => releasesClient.GetAll("owner", null)); + await Assert.ThrowsAsync(() => releasesClient.GetAll("owner", "name", null)); } } diff --git a/Octokit.Tests/Clients/UserEmailsClientTests.cs b/Octokit.Tests/Clients/UserEmailsClientTests.cs index 34d3110661..9ea83029f3 100644 --- a/Octokit.Tests/Clients/UserEmailsClientTests.cs +++ b/Octokit.Tests/Clients/UserEmailsClientTests.cs @@ -11,7 +11,7 @@ public class UserEmailsClientTests public class TheGetAllMethod { [Fact] - public void GetsCorrectUrl() + public void RequestsCorrectUrl() { var connection = Substitute.For(); var client = new UserEmailsClient(connection); @@ -24,15 +24,31 @@ public void GetsCorrectUrl() } [Fact] - public void GetsCorrectUrlWithApiOptions() + public void RequestsCorrectUrlWithApiOptions() { var connection = Substitute.For(); var client = new UserEmailsClient(connection); - client.GetAll(ApiOptions.None); + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + client.GetAll(options); connection.Received(1) - .GetAll(Arg.Is(u => u.ToString() == "user/emails"), Args.ApiOptions); + .GetAll(Arg.Is(u => u.ToString() == "user/emails"), + options); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var releasesClient = new UserEmailsClient(Substitute.For()); + + await Assert.ThrowsAsync(() => releasesClient.GetAll(null)); } } diff --git a/Octokit.Tests/Reactive/ObservableAuthorizationsClientTests.cs b/Octokit.Tests/Reactive/ObservableAuthorizationsClientTests.cs index 241950bb07..7fe3bea0cd 100644 --- a/Octokit.Tests/Reactive/ObservableAuthorizationsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableAuthorizationsClientTests.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.Reactive.Threading.Tasks; +using System.Threading.Tasks; using NSubstitute; using Octokit.Reactive; using Xunit; @@ -27,12 +29,21 @@ public void RequestsCorrectUrlWithApiOption() { var client = Substitute.For(); var authEndpoint = new ObservableAuthorizationsClient(client); - + authEndpoint.GetAll(ApiOptions.None); client.Connection.Received(1).Get>(Arg.Is(u => u.ToString() == "authorizations"), Arg.Is>(dictionary => dictionary.Count == 0), null); } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var client = Substitute.For(); + var authEndpoint = new ObservableAuthorizationsClient(client); + + await Assert.ThrowsAsync(() => authEndpoint.GetAll(null).ToTask()); + } } public class TheCtor