mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-01 18:35:35 +00:00
Implemented the rest of the User Administration Client and tests, including observable classes.
This commit is contained in:
@@ -4,38 +4,52 @@ using System.Reactive;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
/// <summary>
|
||||
/// A client for GitHub's User Administration API.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/users/administration/">Administration API documentation</a> for more details.
|
||||
/// </remarks>
|
||||
public interface IObservableUserAdministrationClient
|
||||
{
|
||||
/// <summary>
|
||||
/// A client for GitHub's User Administration API.
|
||||
/// Promotes ordinary user to a site administrator.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/users/administration/">Administration API documentation</a> for more details.
|
||||
/// https://developer.github.com/v3/users/administration/#promote-an-ordinary-user-to-a-site-administrator
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to promote to administrator.</param>
|
||||
/// <returns></returns>
|
||||
IObservable<Unit> Promote(string login);
|
||||
|
||||
/// <summary>
|
||||
/// A client for GitHub's User Administration API.
|
||||
/// Demotes a site administrator to an ordinary user.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/users/administration/">Administration API documentation</a> for more details.
|
||||
/// https://developer.github.com/v3/users/administration/#demote-a-site-administrator-to-an-ordinary-user
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to demote from administrator.</param>
|
||||
/// <returns></returns>
|
||||
IObservable<Unit> Demote(string login);
|
||||
|
||||
/// <summary>
|
||||
/// A client for GitHub's User Administration API.
|
||||
/// Suspends a user.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/users/administration/">Administration API documentation</a> for more details.
|
||||
/// https://developer.github.com/v3/users/administration/#suspend-a-user
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to suspend.</param>
|
||||
/// <returns></returns>
|
||||
IObservable<Unit> Suspend(string login);
|
||||
|
||||
/// <summary>
|
||||
/// A client for GitHub's User Administration API.
|
||||
/// Unsuspends a user.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/users/administration/">Administration API documentation</a> for more details.
|
||||
/// https://developer.github.com/v3/users/administration/#unsuspend-a-user
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to unsuspend.</param>
|
||||
/// <returns></returns>
|
||||
IObservable<Unit> Unsuspend(string login);
|
||||
|
||||
}
|
||||
|
||||
@@ -2,30 +2,74 @@
|
||||
using System.Reactive;
|
||||
using System.Reactive.Threading.Tasks;
|
||||
using Octokit.Reactive.Internal;
|
||||
using System.Reactive.Linq;
|
||||
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
public class ObservableUserAdministrationClient : IObservableUserAdministrationClient
|
||||
{
|
||||
public IObservable<Unit> Demote(string login)
|
||||
readonly IUserAdministrationClient _client;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ObservableUserAdministrationClient"/> class.
|
||||
/// </summary>
|
||||
/// <param name="client">An <see cref="IUserAdministrationClient" /> used to make the requests</param>
|
||||
public ObservableUserAdministrationClient(IUserAdministrationClient userAdministrationClient)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
_client = userAdministrationClient;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Promotes ordinary user to a site administrator.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/users/administration/#promote-an-ordinary-user-to-a-site-administrator
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to promote to administrator.</param>
|
||||
/// <returns></returns>
|
||||
public IObservable<Unit> Promote(string login)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(login, "login");
|
||||
throw new NotImplementedException();
|
||||
return _client.Promote(login).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Demotes a site administrator to an ordinary user.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/users/administration/#demote-a-site-administrator-to-an-ordinary-user
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to demote from administrator.</param>
|
||||
/// <returns></returns>
|
||||
public IObservable<Unit> Demote(string login)
|
||||
{
|
||||
return _client.Demote(login).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Suspends a user.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/users/administration/#suspend-a-user
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to suspend.</param>
|
||||
/// <returns></returns>
|
||||
public IObservable<Unit> Suspend(string login)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return _client.Suspend(login).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unsuspends a user.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/users/administration/#unsuspend-a-user
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to unsuspend.</param>
|
||||
/// <returns></returns>
|
||||
public IObservable<Unit> Unsuspend(string login)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return _client.Unsuspend(login).ToObservable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using Octokit.Tests.Helpers;
|
||||
using Xunit;
|
||||
using Octokit.Clients;
|
||||
|
||||
namespace Octokit.Tests.Clients
|
||||
{
|
||||
@@ -38,5 +37,91 @@ namespace Octokit.Tests.Clients
|
||||
connection.Received().Put(Arg.Is<Uri>(u => u.ToString() == "/users/auser/site_admin"));
|
||||
}
|
||||
}
|
||||
public class TheDemoteMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new UserAdministrationClient(Substitute.For<IApiConnection>());
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Demote(null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonEmptyString()
|
||||
{
|
||||
var client = new UserAdministrationClient(Substitute.For<IApiConnection>());
|
||||
var exception = await Assert.ThrowsAsync<ArgumentException>(() => client.Demote(""));
|
||||
Assert.Equal("login", exception.ParamName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new UserAdministrationClient(connection);
|
||||
|
||||
client.Demote("auser");
|
||||
|
||||
connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "/users/auser/site_admin"));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheSuspendMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new UserAdministrationClient(Substitute.For<IApiConnection>());
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Suspend(null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonEmptyString()
|
||||
{
|
||||
var client = new UserAdministrationClient(Substitute.For<IApiConnection>());
|
||||
var exception = await Assert.ThrowsAsync<ArgumentException>(() => client.Suspend(""));
|
||||
Assert.Equal("login", exception.ParamName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new UserAdministrationClient(connection);
|
||||
|
||||
client.Suspend("auser");
|
||||
|
||||
connection.Received().Put(Arg.Is<Uri>(u => u.ToString() == "/users/auser/suspended"));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheUnsuspendMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new UserAdministrationClient(Substitute.For<IApiConnection>());
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Unsuspend(null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonEmptyString()
|
||||
{
|
||||
var client = new UserAdministrationClient(Substitute.For<IApiConnection>());
|
||||
var exception = await Assert.ThrowsAsync<ArgumentException>(() => client.Unsuspend(""));
|
||||
Assert.Equal("login", exception.ParamName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new UserAdministrationClient(connection);
|
||||
|
||||
client.Unsuspend("auser");
|
||||
|
||||
connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "/users/auser/suspended"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using NSubstitute;
|
||||
using Octokit.Reactive;
|
||||
using Xunit;
|
||||
using System.Reactive.Linq;
|
||||
|
||||
namespace Octokit.Tests.Reactive
|
||||
{
|
||||
@@ -13,10 +10,56 @@ namespace Octokit.Tests.Reactive
|
||||
public class ThePromoteMethod
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresArgumentIsNotNull()
|
||||
public void GetsFromClientPromtePromote()
|
||||
{
|
||||
var client = new ObservableUserAdministrationClient();
|
||||
Assert.Throws<ArgumentNullException>(() => client.Promote(null));
|
||||
var administrationClient = Substitute.For<IUserAdministrationClient>();
|
||||
var client = new ObservableUserAdministrationClient(administrationClient);
|
||||
|
||||
client.Promote("auser");
|
||||
|
||||
administrationClient.Received().Promote("auser");
|
||||
}
|
||||
}
|
||||
|
||||
public class TheDemoteMethod
|
||||
{
|
||||
[Fact]
|
||||
public void GetsFromClientDemoteDemote()
|
||||
{
|
||||
var administrationClient = Substitute.For<IUserAdministrationClient>();
|
||||
var client = new ObservableUserAdministrationClient(administrationClient);
|
||||
|
||||
client.Demote("auser");
|
||||
|
||||
administrationClient.Received().Demote("auser");
|
||||
}
|
||||
}
|
||||
|
||||
public class TheSuspendMethod
|
||||
{
|
||||
[Fact]
|
||||
public void GetsFromClientSuspendSuspend()
|
||||
{
|
||||
var administrationClient = Substitute.For<IUserAdministrationClient>();
|
||||
var client = new ObservableUserAdministrationClient(administrationClient);
|
||||
|
||||
client.Suspend("auser");
|
||||
|
||||
administrationClient.Received().Suspend("auser");
|
||||
}
|
||||
}
|
||||
|
||||
public class TheUnsuspendMethod
|
||||
{
|
||||
[Fact]
|
||||
public void GetsFromClientUnsuspendUnsuspend()
|
||||
{
|
||||
var administrationClient = Substitute.For<IUserAdministrationClient>();
|
||||
var client = new ObservableUserAdministrationClient(administrationClient);
|
||||
|
||||
client.Unsuspend("auser");
|
||||
|
||||
administrationClient.Received().Unsuspend("auser");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace Octokit
|
||||
Task Suspend(string login);
|
||||
|
||||
/// <summary>
|
||||
/// Unsuspends a user
|
||||
/// Unsuspends a user.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/users/administration/#unsuspend-a-user
|
||||
|
||||
@@ -4,36 +4,83 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Octokit.Clients
|
||||
namespace Octokit
|
||||
{
|
||||
/// <summary>
|
||||
/// A client for GitHub's User Administration API.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/users/administration/">Administration API documentation</a> for more details.
|
||||
/// </remarks>
|
||||
public class UserAdministrationClient : ApiClient, IUserAdministrationClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UserAdministrationClient"/> class.
|
||||
/// </summary>
|
||||
/// <param name="apiConnection">The client's connection</param>
|
||||
public UserAdministrationClient(IApiConnection apiConnection)
|
||||
: base(apiConnection)
|
||||
{
|
||||
}
|
||||
|
||||
public Task Demote(string login)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Promotes ordinary user to a site administrator.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/users/administration/#promote-an-ordinary-user-to-a-site-administrator
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to promote to administrator.</param>
|
||||
/// <returns></returns>
|
||||
public Task Promote(string login)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(login, "login");
|
||||
var endpoint = ApiUrls.UserAdministration(login);
|
||||
|
||||
return ApiConnection.Put(endpoint);
|
||||
}
|
||||
|
||||
public Task Suspend(string login)
|
||||
/// <summary>
|
||||
/// Demotes a site administrator to an ordinary user.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/users/administration/#demote-a-site-administrator-to-an-ordinary-user
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to demote from administrator.</param>
|
||||
/// <returns></returns>
|
||||
public Task Demote(string login)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
Ensure.ArgumentNotNullOrEmptyString(login, "login");
|
||||
var endpoint = ApiUrls.UserAdministration(login);
|
||||
return ApiConnection.Delete(endpoint);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Suspends a user.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/users/administration/#suspend-a-user
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to suspend.</param>
|
||||
/// <returns></returns>
|
||||
public Task Suspend(string login)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(login, "login");
|
||||
var endpoint = ApiUrls.UserSuspension(login);
|
||||
return ApiConnection.Put(endpoint);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unsuspends a user.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/users/administration/#unsuspend-a-user
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to unsuspend.</param>
|
||||
/// <returns></returns>
|
||||
public Task Unsuspend(string login)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
Ensure.ArgumentNotNullOrEmptyString(login, "login");
|
||||
var endpoint = ApiUrls.UserSuspension(login);
|
||||
return ApiConnection.Delete(endpoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace Octokit
|
||||
Email = new UserEmailsClient(apiConnection);
|
||||
Followers = new FollowersClient(apiConnection);
|
||||
Keys = new UserKeysClient(apiConnection);
|
||||
Administration = new UserAdministrationClient(apiConnection);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1570,10 +1570,26 @@ namespace Octokit
|
||||
return "repos/{0}/{1}/pages/builds/latest".FormatUri(owner, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the relative <see cref="Uri"/> for altering administration status of a user.
|
||||
/// </summary>
|
||||
/// <param name="login">The login for the intended user.</param>
|
||||
/// <returns></returns>
|
||||
public static Uri UserAdministration(string login)
|
||||
{
|
||||
return "/users/{0}/site_admin".FormatUri(login);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the relative <see cref="Uri"/> for altering suspension status of a user.
|
||||
/// </summary>
|
||||
/// <param name="login">The login for the intended user.</param>
|
||||
/// <returns></returns>
|
||||
public static Uri UserSuspension(string login)
|
||||
{
|
||||
return "/users/{0}/suspended".FormatUri(login);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user