diff --git a/Octokit.Reactive/Clients/IObservableAuthorizationsClient.cs b/Octokit.Reactive/Clients/IObservableAuthorizationsClient.cs index c72986fd01..0e5083fd15 100644 --- a/Octokit.Reactive/Clients/IObservableAuthorizationsClient.cs +++ b/Octokit.Reactive/Clients/IObservableAuthorizationsClient.cs @@ -13,11 +13,24 @@ 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(); + /// + /// Get all s for the authenticated user. This method requires basic auth. + /// + /// + /// See API documentation for more + /// details. + /// + /// Options for changing the API response + /// 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); + /// /// Get a specific for the authenticated user. This method requires basic auth. /// 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.Reactive/Clients/ObservableAuthorizationsClient.cs b/Octokit.Reactive/Clients/ObservableAuthorizationsClient.cs index 9d5127b771..d5cd198954 100644 --- a/Octokit.Reactive/Clients/ObservableAuthorizationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableAuthorizationsClient.cs @@ -25,10 +25,26 @@ public ObservableAuthorizationsClient(IGitHubClient client) /// See API documentation for more /// details. /// - /// An + /// A list of s for the authenticated user. 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 + /// A list of s for the authenticated user. + public IObservable GetAll(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Authorizations(), options); } /// 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); + } + } +} 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 5aad42eff0..0724d76bdf 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); @@ -37,6 +37,35 @@ public void GetsAListOfAuthorizations() Arg.Is(u => u.ToString() == "authorizations"), Args.ApiOptions); } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var client = Substitute.For(); + var authEndpoint = new AuthorizationsClient(client); + + var options = new ApiOptions + { + StartPage = 1, + PageSize = 1, + PageCount = 1 + }; + + authEndpoint.GetAll(options); + + client.Received().GetAll( + Arg.Is(u => u.ToString() == "authorizations"), + options); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var client = Substitute.For(); + var authEndpoint = new AuthorizationsClient(client); + + await Assert.ThrowsAsync(() => authEndpoint.GetAll(null)); + } } public class TheGetMethod 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/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..7fe3bea0cd --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableAuthorizationsClientTests.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Reactive.Threading.Tasks; +using System.Threading.Tasks; +using NSubstitute; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Reactive +{ + public class ObservableAuthorizationsClientTests + { + public class TheGetAllMethod + { + [Fact] + public void RequestsCorrectUrl() + { + 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 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 + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new ObservableAuthorizationsClient(null)); + } + } + } +} diff --git a/Octokit/Clients/AuthorizationsClient.cs b/Octokit/Clients/AuthorizationsClient.cs index 84b41b78cc..92a4cf4b6d 100644 --- a/Octokit/Clients/AuthorizationsClient.cs +++ b/Octokit/Clients/AuthorizationsClient.cs @@ -33,10 +33,30 @@ 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 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 for the authenticated user. + 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..c78a048d17 100644 --- a/Octokit/Clients/IAuthorizationsClient.cs +++ b/Octokit/Clients/IAuthorizationsClient.cs @@ -26,11 +26,28 @@ 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(); + /// + /// 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 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); + /// /// Gets a specific for the authenticated user. ///