mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-06 12:03:19 +00:00
Add ApiOptions overloads to IObservableWatchedClient + tests.
This commit is contained in:
committed by
aedampir@gmail.com
parent
591ab76a7b
commit
a9abc5abc4
@@ -14,6 +14,16 @@ namespace Octokit.Reactive
|
||||
/// <returns>A <see cref="IObservable{User}"/> of <see cref="User"/>s watching the passed repository</returns>
|
||||
IObservable<User> GetAllWatchers(string owner, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the watchers for the passed repository
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="options">Options for changing the API's response.</param>
|
||||
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated</exception>
|
||||
/// <returns>A <see cref="IObservable{User}"/> of <see cref="User"/>s watching the passed repository</returns>
|
||||
IObservable<User> GetAllWatchers(string owner, string name, ApiOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the watched <see cref="Repository"/>(ies) for the current user
|
||||
/// </summary>
|
||||
@@ -22,6 +32,14 @@ namespace Octokit.Reactive
|
||||
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
|
||||
IObservable<Repository> GetAllForCurrent();
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the watched <see cref="Repository"/>(ies) for the current user
|
||||
/// </summary>
|
||||
/// <param name="options">Options for changing the API's response.</param>
|
||||
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated</exception>
|
||||
/// <returns>A <see cref="IObservable{Repository}"/> of <see cref="Repository"/></returns>
|
||||
IObservable<Repository> GetAllForCurrent(ApiOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the <see cref="Repository"/>(ies) watched by the specified user
|
||||
/// </summary>
|
||||
@@ -30,6 +48,15 @@ namespace Octokit.Reactive
|
||||
/// <returns>A <see cref="IObservable{Repository}"/> watched by the specified user</returns>
|
||||
IObservable<Repository> GetAllForUser(string user);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the <see cref="Repository"/>(ies) watched by the specified user
|
||||
/// </summary>
|
||||
/// <param name="user">The login of the user</param>
|
||||
/// <param name="options">Options for changing the API's response.</param>
|
||||
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated</exception>
|
||||
/// <returns>A <see cref="IObservable{Repository}"/> watched by the specified user</returns>
|
||||
IObservable<Repository> GetAllForUser(string user, ApiOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Check if a repository is watched by the current authenticated user
|
||||
/// </summary>
|
||||
|
||||
@@ -29,7 +29,24 @@ namespace Octokit.Reactive
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
return _connection.GetAndFlattenAllPages<User>(ApiUrls.Watchers(owner, name));
|
||||
return GetAllWatchers(owner, name, ApiOptions.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the watchers for the passed repository
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="options">Options for changing the API's response.</param>
|
||||
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated</exception>
|
||||
/// <returns>A <see cref="IObservable{User}"/> of <see cref="User"/>s watching the passed repository</returns>
|
||||
public IObservable<User> GetAllWatchers(string owner, string name, ApiOptions options)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNull(options, "options");
|
||||
|
||||
return _connection.GetAndFlattenAllPages<User>(ApiUrls.Watchers(owner, name), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -39,7 +56,20 @@ namespace Octokit.Reactive
|
||||
/// <returns>A <see cref="IObservable{Repository}"/> of <see cref="Repository"/></returns>
|
||||
public IObservable<Repository> GetAllForCurrent()
|
||||
{
|
||||
return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.Watched());
|
||||
return GetAllForCurrent(ApiOptions.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the watched <see cref="Repository"/>(ies) for the current user
|
||||
/// </summary>
|
||||
/// <param name="options">Options for changing the API's response.</param>
|
||||
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated</exception>
|
||||
/// <returns>A <see cref="IObservable{Repository}"/> of <see cref="Repository"/></returns>
|
||||
public IObservable<Repository> GetAllForCurrent(ApiOptions options)
|
||||
{
|
||||
Ensure.ArgumentNotNull(options, "options");
|
||||
|
||||
return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.Watched(), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -52,6 +82,21 @@ namespace Octokit.Reactive
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(user, "user");
|
||||
|
||||
return GetAllForUser(user, ApiOptions.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all of the <see cref="Repository"/>(ies) watched by the specified user
|
||||
/// </summary>
|
||||
/// <param name="user">The login of the user</param>
|
||||
/// <param name="options">Options for changing the API's response.</param>
|
||||
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated</exception>
|
||||
/// <returns>A <see cref="IObservable{Repository}"/> watched by the specified user</returns>
|
||||
public IObservable<Repository> GetAllForUser(string user, ApiOptions options)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(user, "user");
|
||||
Ensure.ArgumentNotNull(options, "options");
|
||||
|
||||
return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.WatchedByUser(user));
|
||||
}
|
||||
|
||||
|
||||
@@ -238,6 +238,7 @@
|
||||
<Compile Include="Reactive\ObservableUserAdministrationClientTests.cs" />
|
||||
<Compile Include="Reactive\Enterprise\ObservableEnterpriseAdminStatsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableUserEmailsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableWatchedClientTests.cs" />
|
||||
<Compile Include="SelfTests.cs" />
|
||||
<Compile Include="SimpleJsonSerializerTests.cs" />
|
||||
<Compile Include="Clients\UsersClientTests.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<ArgumentNullException>(() => new ObservableWatchedClient(null));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetAllWatchersMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task EnsuresArguments()
|
||||
{
|
||||
var client = new ObservableWatchedClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllWatchers(null, "name").ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllWatchers("owner", null).ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllWatchers("owner", "name", null).ToTask());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetsWatchersFromClient()
|
||||
{
|
||||
var connection = Substitute.For<IConnection>();
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
gitHubClient.Connection.Returns(connection);
|
||||
var client = new ObservableWatchedClient(gitHubClient);
|
||||
|
||||
client.GetAllWatchers("jugglingnutcase", "katiejamie");
|
||||
connection.Received().Get<List<User>>(ApiUrls.Watchers("jugglingnutcase", "katiejamie"), Arg.Any<IDictionary<string, string>>(), null);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetAllForCurrentMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task EnsuresArguments()
|
||||
{
|
||||
var client = new ObservableWatchedClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForCurrent(null).ToTask());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetsStarsForCurrent()
|
||||
{
|
||||
var connection = Substitute.For<IConnection>();
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
gitHubClient.Connection.Returns(connection);
|
||||
var client = new ObservableWatchedClient(gitHubClient);
|
||||
|
||||
client.GetAllForCurrent();
|
||||
connection.Received().Get<List<Repository>>(ApiUrls.Watched(), Arg.Any<IDictionary<string, string>>(), null);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetAllForUserMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task EnsuresArguments()
|
||||
{
|
||||
var client = new ObservableWatchedClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser(null).ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForUser("").ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser("user", null).ToTask());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetsStarsForUser()
|
||||
{
|
||||
var connection = Substitute.For<IConnection>();
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
gitHubClient.Connection.Returns(connection);
|
||||
var client = new ObservableWatchedClient(gitHubClient);
|
||||
|
||||
client.GetAllForUser("jugglingnutcase");
|
||||
connection.Received().Get<List<Repository>>(ApiUrls.WatchedByUser("jugglingnutcase"), Arg.Any<IDictionary<string, string>>(), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user