From a9abc5abc4c79ce0292e64af11e028393b87685e Mon Sep 17 00:00:00 2001 From: Devesh Khandelwal Date: Fri, 22 Apr 2016 11:29:34 +0530 Subject: [PATCH] Add ApiOptions overloads to IObservableWatchedClient + tests. --- .../Clients/IObservableWatchedClient.cs | 27 ++++++ .../Clients/ObservableWatchedClient.cs | 49 +++++++++- Octokit.Tests/Octokit.Tests.csproj | 1 + .../Reactive/ObservableWatchedClientTests.cs | 96 +++++++++++++++++++ 4 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 Octokit.Tests/Reactive/ObservableWatchedClientTests.cs diff --git a/Octokit.Reactive/Clients/IObservableWatchedClient.cs b/Octokit.Reactive/Clients/IObservableWatchedClient.cs index a3fa7a07..e4265acf 100644 --- a/Octokit.Reactive/Clients/IObservableWatchedClient.cs +++ b/Octokit.Reactive/Clients/IObservableWatchedClient.cs @@ -14,6 +14,16 @@ namespace Octokit.Reactive /// A of s watching the passed repository IObservable GetAllWatchers(string owner, string name); + /// + /// Retrieves all of the watchers for the passed repository + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API's response. + /// Thrown if the client is not authenticated + /// A of s watching the passed repository + IObservable GetAllWatchers(string owner, string name, ApiOptions options); + /// /// Retrieves all of the watched (ies) for the current user /// @@ -22,6 +32,14 @@ namespace Octokit.Reactive [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] IObservable GetAllForCurrent(); + /// + /// Retrieves all of the watched (ies) for the current user + /// + /// Options for changing the API's response. + /// Thrown if the client is not authenticated + /// A of + IObservable GetAllForCurrent(ApiOptions options); + /// /// Retrieves all of the (ies) watched by the specified user /// @@ -30,6 +48,15 @@ namespace Octokit.Reactive /// A watched by the specified user IObservable GetAllForUser(string user); + /// + /// Retrieves all of the (ies) watched by the specified user + /// + /// The login of the user + /// Options for changing the API's response. + /// Thrown if the client is not authenticated + /// A watched by the specified user + IObservable GetAllForUser(string user, ApiOptions options); + /// /// Check if a repository is watched by the current authenticated user /// diff --git a/Octokit.Reactive/Clients/ObservableWatchedClient.cs b/Octokit.Reactive/Clients/ObservableWatchedClient.cs index 814516cb..d72fab03 100644 --- a/Octokit.Reactive/Clients/ObservableWatchedClient.cs +++ b/Octokit.Reactive/Clients/ObservableWatchedClient.cs @@ -29,7 +29,24 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return _connection.GetAndFlattenAllPages(ApiUrls.Watchers(owner, name)); + return GetAllWatchers(owner, name, ApiOptions.None); + } + + /// + /// Retrieves all of the watchers for the passed repository + /// + /// The owner of the repository + /// The name of the repository + /// Options for changing the API's response. + /// Thrown if the client is not authenticated + /// A of s watching the passed repository + public IObservable GetAllWatchers(string owner, string name, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Watchers(owner, name), options); } /// @@ -39,7 +56,20 @@ namespace Octokit.Reactive /// A of public IObservable GetAllForCurrent() { - return _connection.GetAndFlattenAllPages(ApiUrls.Watched()); + return GetAllForCurrent(ApiOptions.None); + } + + /// + /// Retrieves all of the watched (ies) for the current user + /// + /// Options for changing the API's response. + /// Thrown if the client is not authenticated + /// A of + public IObservable GetAllForCurrent(ApiOptions options) + { + Ensure.ArgumentNotNull(options, "options"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Watched(), options); } /// @@ -52,6 +82,21 @@ namespace Octokit.Reactive { Ensure.ArgumentNotNullOrEmptyString(user, "user"); + return GetAllForUser(user, ApiOptions.None); + } + + /// + /// Retrieves all of the (ies) watched by the specified user + /// + /// The login of the user + /// Options for changing the API's response. + /// Thrown if the client is not authenticated + /// A watched by the specified user + public IObservable GetAllForUser(string user, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(options, "options"); + return _connection.GetAndFlattenAllPages(ApiUrls.WatchedByUser(user)); } diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index deb7e33c..67e4dc85 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -238,6 +238,7 @@ + diff --git a/Octokit.Tests/Reactive/ObservableWatchedClientTests.cs b/Octokit.Tests/Reactive/ObservableWatchedClientTests.cs new file mode 100644 index 00000000..811c0b3a --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableWatchedClientTests.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Reactive.Threading.Tasks; +using System.Threading.Tasks; +using NSubstitute; +using Octokit.Reactive; +using Octokit.Reactive.Internal; +using Xunit; + +namespace Octokit.Tests.Reactive +{ + public class ObservableWatchedClientTests + { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new ObservableWatchedClient(null)); + } + } + + public class TheGetAllWatchersMethod + { + [Fact] + public async Task EnsuresArguments() + { + var client = new ObservableWatchedClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.GetAllWatchers(null, "name").ToTask()); + await Assert.ThrowsAsync(() => client.GetAllWatchers("owner", null).ToTask()); + await Assert.ThrowsAsync(() => client.GetAllWatchers("owner", "name", null).ToTask()); + } + + [Fact] + public void GetsWatchersFromClient() + { + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableWatchedClient(gitHubClient); + + client.GetAllWatchers("jugglingnutcase", "katiejamie"); + connection.Received().Get>(ApiUrls.Watchers("jugglingnutcase", "katiejamie"), Arg.Any>(), null); + } + } + + public class TheGetAllForCurrentMethod + { + [Fact] + public async Task EnsuresArguments() + { + var client = new ObservableWatchedClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.GetAllForCurrent(null).ToTask()); + } + + [Fact] + public void GetsStarsForCurrent() + { + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableWatchedClient(gitHubClient); + + client.GetAllForCurrent(); + connection.Received().Get>(ApiUrls.Watched(), Arg.Any>(), null); + } + } + + public class TheGetAllForUserMethod + { + [Fact] + public async Task EnsuresArguments() + { + var client = new ObservableWatchedClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.GetAllForUser(null).ToTask()); + await Assert.ThrowsAsync(() => client.GetAllForUser("").ToTask()); + await Assert.ThrowsAsync(() => client.GetAllForUser("user", null).ToTask()); + } + + [Fact] + public void GetsStarsForUser() + { + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableWatchedClient(gitHubClient); + + client.GetAllForUser("jugglingnutcase"); + connection.Received().Get>(ApiUrls.WatchedByUser("jugglingnutcase"), Arg.Any>(), null); + } + } + } +} \ No newline at end of file