mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-06 20:13:40 +00:00
Add Reactive implementation and unit tests
This commit is contained in:
@@ -5,7 +5,7 @@ using System.Reactive;
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
/// <summary>
|
||||
/// A client for GitHub's User Administration API.
|
||||
/// A client for GitHub's User Administration API (GitHub Enterprise)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/users/administration/">Administration API documentation</a> for more details.
|
||||
@@ -13,43 +13,126 @@ namespace Octokit.Reactive
|
||||
public interface IObservableUserAdministrationClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Promotes ordinary user to a site administrator.
|
||||
/// Create a new user (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/users/administration/#promote-an-ordinary-user-to-a-site-administrator
|
||||
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#create-a-new-user">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="newUser">The <see cref="NewUser"/> object describing the user to create</param>
|
||||
/// <returns>The created <see cref="User"/> object</returns>
|
||||
IObservable<User> Create(NewUser newUser);
|
||||
|
||||
/// <summary>
|
||||
/// Rename an existing user (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#rename-an-existing-user">API documentation</a>
|
||||
/// for more information.
|
||||
/// Note that this queues a request to rename a user, rather than execute it straight away
|
||||
/// </remarks>
|
||||
/// <param name="login">The username to rename</param>
|
||||
/// <param name="userRename">The <see cref="UserRename"/> request, specifying the new login</param>
|
||||
/// <returns>A <see cref="UserRenameResponse"/> object indicating the queued task message and Url to the user</returns>
|
||||
IObservable<UserRenameResponse> Rename(string login, UserRename userRename);
|
||||
|
||||
/// <summary>
|
||||
/// Create an impersonation OAuth token (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#create-an-impersonation-oauth-token">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to impersonate</param>
|
||||
/// <param name="newImpersonationToken">The <see cref="NewImpersonationToken"/> request specifying the required scopes</param>
|
||||
/// <returns>An <see cref="Authorization"/> object containing the impersonation token</returns>
|
||||
IObservable<Authorization> CreateImpersonationToken(string login, NewImpersonationToken newImpersonationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes an impersonation OAuth token (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#delete-an-impersonation-oauth-token">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to remove impersonation token from</param>
|
||||
/// <returns></returns>
|
||||
IObservable<Unit> DeleteImpersonationToken(string login);
|
||||
|
||||
/// <summary>
|
||||
/// Promotes ordinary user to a site administrator (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/users/administration/#promote-an-ordinary-user-to-a-site-administrator">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to promote to administrator.</param>
|
||||
/// <returns></returns>
|
||||
IObservable<Unit> Promote(string login);
|
||||
|
||||
/// <summary>
|
||||
/// Demotes a site administrator to an ordinary user.
|
||||
/// Demotes a site administrator to an ordinary user (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/users/administration/#demote-a-site-administrator-to-an-ordinary-user
|
||||
/// See the <a href="https://developer.github.com/v3/users/administration/#demote-a-site-administrator-to-an-ordinary-user">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to demote from administrator.</param>
|
||||
/// <returns></returns>
|
||||
IObservable<Unit> Demote(string login);
|
||||
|
||||
/// <summary>
|
||||
/// Suspends a user.
|
||||
/// Suspends a user (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/users/administration/#suspend-a-user
|
||||
/// See the <a href="https://developer.github.com/v3/users/administration/#suspend-a-user">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to suspend.</param>
|
||||
/// <returns></returns>
|
||||
IObservable<Unit> Suspend(string login);
|
||||
|
||||
/// <summary>
|
||||
/// Unsuspends a user.
|
||||
/// Unsuspends a user (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/users/administration/#unsuspend-a-user
|
||||
/// See the <a href="https://developer.github.com/v3/users/administration/#unsuspend-a-user">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to unsuspend.</param>
|
||||
/// <returns></returns>
|
||||
IObservable<Unit> Unsuspend(string login);
|
||||
|
||||
/// <summary>
|
||||
/// List all public keys (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#list-all-public-keys">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <returns></returns>
|
||||
IObservable<PublicKey> ListAllPublicKeys();
|
||||
|
||||
/// <summary>
|
||||
/// Delete a user (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#delete-a-user">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to delete</param>
|
||||
/// <returns></returns>
|
||||
IObservable<Unit> Delete(string login);
|
||||
|
||||
/// <summary>
|
||||
/// Delete a public key (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#delete-a-public-key">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="keyId">The key to delete</param>
|
||||
/// <returns></returns>
|
||||
IObservable<Unit> DeletePublicKey(int keyId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,16 @@ using System.Reactive.Linq;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
/// <summary>
|
||||
/// A client for GitHub's User Administration API (GitHub Enterprise)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/users/administration/">Administration API documentation</a> for more details.
|
||||
/// </remarks>
|
||||
public class ObservableUserAdministrationClient : IObservableUserAdministrationClient
|
||||
{
|
||||
readonly IUserAdministrationClient _client;
|
||||
readonly IConnection _connection;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ObservableUserAdministrationClient"/> class.
|
||||
@@ -20,13 +27,74 @@ namespace Octokit.Reactive
|
||||
Ensure.ArgumentNotNull(client, "client");
|
||||
|
||||
_client = client.User.Administration;
|
||||
_connection = client.Connection;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Promotes ordinary user to a site administrator.
|
||||
/// Create a new user (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/users/administration/#promote-an-ordinary-user-to-a-site-administrator
|
||||
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#create-a-new-user">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="newUser">The <see cref="NewUser"/> object describing the user to create</param>
|
||||
/// <returns>The created <see cref="User"/> object</returns>
|
||||
public IObservable<User> Create(NewUser newUser)
|
||||
{
|
||||
return _client.Create(newUser).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rename an existing user (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#rename-an-existing-user">API documentation</a>
|
||||
/// for more information.
|
||||
/// Note that this queues a request to rename a user, rather than execute it straight away
|
||||
/// </remarks>
|
||||
/// <param name="login">The username to rename</param>
|
||||
/// <param name="userRename">The <see cref="UserRename"/> request, specifying the new login</param>
|
||||
/// <returns>A <see cref="UserRenameResponse"/> object indicating the queued task message and Url to the user</returns>
|
||||
public IObservable<UserRenameResponse> Rename(string login, UserRename userRename)
|
||||
{
|
||||
return _client.Rename(login, userRename).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create an impersonation OAuth token (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#create-an-impersonation-oauth-token">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to impersonate</param>
|
||||
/// <param name="newImpersonationToken">The <see cref="NewImpersonationToken"/> request specifying the required scopes</param>
|
||||
/// <returns>An <see cref="Authorization"/> object containing the impersonation token</returns>
|
||||
public IObservable<Authorization> CreateImpersonationToken(string login, NewImpersonationToken newImpersonationToken)
|
||||
{
|
||||
return _client.CreateImpersonationToken(login, newImpersonationToken).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes an impersonation OAuth token (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#delete-an-impersonation-oauth-token">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to remove impersonation token from</param>
|
||||
/// <returns></returns>
|
||||
public IObservable<Unit> DeleteImpersonationToken(string login)
|
||||
{
|
||||
return _client.DeleteImpersonationToken(login).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Promotes ordinary user to a site administrator (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/v3/users/administration/#promote-an-ordinary-user-to-a-site-administrator">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to promote to administrator.</param>
|
||||
/// <returns></returns>
|
||||
@@ -36,10 +104,11 @@ namespace Octokit.Reactive
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Demotes a site administrator to an ordinary user.
|
||||
/// Demotes a site administrator to an ordinary user (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/users/administration/#demote-a-site-administrator-to-an-ordinary-user
|
||||
/// See the <a href="https://developer.github.com/v3/users/administration/#demote-a-site-administrator-to-an-ordinary-user">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to demote from administrator.</param>
|
||||
/// <returns></returns>
|
||||
@@ -49,10 +118,11 @@ namespace Octokit.Reactive
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Suspends a user.
|
||||
/// Suspends a user (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/users/administration/#suspend-a-user
|
||||
/// See the <a href="https://developer.github.com/v3/users/administration/#suspend-a-user">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to suspend.</param>
|
||||
/// <returns></returns>
|
||||
@@ -62,10 +132,11 @@ namespace Octokit.Reactive
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unsuspends a user.
|
||||
/// Unsuspends a user (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// https://developer.github.com/v3/users/administration/#unsuspend-a-user
|
||||
/// See the <a href="https://developer.github.com/v3/users/administration/#unsuspend-a-user">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to unsuspend.</param>
|
||||
/// <returns></returns>
|
||||
@@ -73,5 +144,46 @@ namespace Octokit.Reactive
|
||||
{
|
||||
return _client.Unsuspend(login).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List all public keys (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#list-all-public-keys">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <returns></returns>
|
||||
public IObservable<PublicKey> ListAllPublicKeys()
|
||||
{
|
||||
return _connection.GetAndFlattenAllPages<PublicKey>(ApiUrls.UserAdministrationPublicKeys());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete a user (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#delete-a-user">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="login">The user to delete</param>
|
||||
/// <returns></returns>
|
||||
public IObservable<Unit> Delete(string login)
|
||||
{
|
||||
return _client.Delete(login).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete a public key (must be Site Admin user).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#delete-a-public-key">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="keyId">The key to delete</param>
|
||||
/// <returns></returns>
|
||||
public IObservable<Unit> DeletePublicKey(int keyId)
|
||||
{
|
||||
return _client.DeletePublicKey(keyId).ToObservable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,5 +27,19 @@ namespace Octokit.Tests.Integration.Helpers
|
||||
|
||||
return new RepositoryContext(repo);
|
||||
}
|
||||
|
||||
internal async static Task<EnterpriseTeamContext> CreateEnterpriseTeamContext(this IObservableGitHubClient client, string organization, NewTeam newTeam)
|
||||
{
|
||||
var team = await client.Organization.Team.Create(organization, newTeam);
|
||||
|
||||
return new EnterpriseTeamContext(team);
|
||||
}
|
||||
|
||||
internal async static Task<EnterpriseUserContext> CreateEnterpriseUserContext(this IObservableGitHubClient client, NewUser newUser)
|
||||
{
|
||||
var user = await client.User.Administration.Create(newUser);
|
||||
|
||||
return new EnterpriseUserContext(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -145,6 +145,7 @@
|
||||
<Compile Include="Helper.cs" />
|
||||
<Compile Include="Clients\UsersClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableRespositoryDeployKeysClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableUserAdministrationClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableUserEmailsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableTeamsClientTests.cs" />
|
||||
<Compile Include="RedirectTests.cs" />
|
||||
|
||||
+2
-3
@@ -20,11 +20,10 @@ namespace Octokit.Tests.Integration
|
||||
|
||||
public ObservableEnterpriseLdapClientTests()
|
||||
{
|
||||
var gitHub = EnterpriseHelper.GetAuthenticatedClient();
|
||||
_github = new ObservableGitHubClient(gitHub);
|
||||
_github = new ObservableGitHubClient(EnterpriseHelper.GetAuthenticatedClient());
|
||||
|
||||
NewTeam newTeam = new NewTeam(Helper.MakeNameWithTimestamp("test-team")) { Description = "Test Team" };
|
||||
_context = gitHub.CreateEnterpriseTeamContext(EnterpriseHelper.Organization, newTeam).Result;
|
||||
_context = _github.CreateEnterpriseTeamContext(EnterpriseHelper.Organization, newTeam).Result;
|
||||
}
|
||||
|
||||
[GitHubEnterpriseTest]
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Octokit.Reactive;
|
||||
using Octokit.Tests.Integration.Helpers;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Integration.Clients
|
||||
{
|
||||
public class ObservableUserAdministrationClientTests
|
||||
{
|
||||
readonly IObservableGitHubClient _github;
|
||||
|
||||
public ObservableUserAdministrationClientTests()
|
||||
{
|
||||
_github = new ObservableGitHubClient(EnterpriseHelper.GetAuthenticatedClient());
|
||||
}
|
||||
|
||||
private NewUser GenerateNewUserDetails()
|
||||
{
|
||||
string username = Helper.MakeNameWithTimestamp("user");
|
||||
string email = string.Concat(username, "@company.com");
|
||||
return new NewUser(username, email);
|
||||
}
|
||||
|
||||
[GitHubEnterpriseTest]
|
||||
public async Task CanCreateAndDelete()
|
||||
{
|
||||
User checkUser = null;
|
||||
|
||||
// Create a new user
|
||||
var newUser = GenerateNewUserDetails();
|
||||
|
||||
var observable = _github.User.Administration.Create(newUser);
|
||||
var user = await observable;
|
||||
|
||||
// Check returned object (cant check email as it isn't public)
|
||||
Assert.NotNull(user);
|
||||
Assert.Equal(user.Login, newUser.Login);
|
||||
|
||||
// Get user to check they exist
|
||||
checkUser = await _github.User.Get(newUser.Login);
|
||||
Assert.Equal(checkUser.Login, newUser.Login);
|
||||
|
||||
// Delete the user
|
||||
await _github.User.Administration.Delete(newUser.Login);
|
||||
|
||||
// Ensure user doesnt exist
|
||||
try
|
||||
{
|
||||
checkUser = await _github.User.Get(newUser.Login);
|
||||
if (checkUser != null)
|
||||
{
|
||||
throw new Exception("User still exists!");
|
||||
}
|
||||
}
|
||||
catch (ApiException e)
|
||||
{
|
||||
if (e.StatusCode != System.Net.HttpStatusCode.NotFound)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[GitHubEnterpriseTest]
|
||||
public async Task CanRename()
|
||||
{
|
||||
string renamedUsername = Helper.MakeNameWithTimestamp("user-renamed");
|
||||
// Create a disposable user for the test
|
||||
using (var context = _github.CreateEnterpriseUserContext(GenerateNewUserDetails()).Result)
|
||||
{
|
||||
var observable = _github.User.Administration.Rename(
|
||||
context.UserLogin,
|
||||
new UserRename(renamedUsername));
|
||||
var response = await observable;
|
||||
|
||||
Assert.NotNull(response);
|
||||
Assert.StartsWith("Job queued to rename user", response.Message);
|
||||
Assert.EndsWith(context.UserId.ToString(), response.Url);
|
||||
}
|
||||
|
||||
// Remove user if it was already renamed
|
||||
EnterpriseHelper.DeleteUser(renamedUsername);
|
||||
}
|
||||
|
||||
[GitHubEnterpriseTest]
|
||||
public async Task CanAddAndDeleteImpersonationToken()
|
||||
{
|
||||
// Create a disposable user for the test
|
||||
using (var context = _github.CreateEnterpriseUserContext(GenerateNewUserDetails()).Result)
|
||||
{
|
||||
// Create Impersonation token
|
||||
var observable = _github.User.Administration.CreateImpersonationToken(
|
||||
context.UserLogin,
|
||||
new NewImpersonationToken(new string[] { "public_repo" }));
|
||||
var token = await observable;
|
||||
|
||||
Assert.NotNull(token);
|
||||
Assert.True(
|
||||
token.Scopes.Count() == 1 &&
|
||||
token.Scopes.All(s => s == "public_repo"));
|
||||
|
||||
// Delete Impersonation token
|
||||
await _github.User.Administration.DeleteImpersonationToken(context.UserLogin);
|
||||
}
|
||||
}
|
||||
|
||||
[GitHubEnterpriseTest]
|
||||
public async Task CanPromoteAndDemote()
|
||||
{
|
||||
User checkUser = null;
|
||||
|
||||
// Create a disposable user for the test
|
||||
using (var context = _github.CreateEnterpriseUserContext(GenerateNewUserDetails()).Result)
|
||||
{
|
||||
// Ensure user is not site admin
|
||||
checkUser = await _github.User.Get(context.UserLogin);
|
||||
Assert.False(checkUser.SiteAdmin);
|
||||
|
||||
// Promote to site admin
|
||||
await _github.User.Administration.Promote(context.UserLogin);
|
||||
|
||||
// Ensure user is site admin
|
||||
checkUser = await _github.User.Get(context.UserLogin);
|
||||
Assert.True(checkUser.SiteAdmin);
|
||||
|
||||
// Demote user
|
||||
await _github.User.Administration.Demote(context.UserLogin);
|
||||
|
||||
// Ensure user is not site admin
|
||||
checkUser = await _github.User.Get(context.UserLogin);
|
||||
Assert.False(checkUser.SiteAdmin);
|
||||
}
|
||||
}
|
||||
|
||||
[GitHubEnterpriseTest]
|
||||
public async Task CanSuspendAndUnsuspend()
|
||||
{
|
||||
User checkUser = null;
|
||||
|
||||
// Create a disposable user for the test
|
||||
using (var context = _github.CreateEnterpriseUserContext(GenerateNewUserDetails()).Result)
|
||||
{
|
||||
// Ensure user is not suspended
|
||||
checkUser = await _github.User.Get(context.UserLogin);
|
||||
Assert.False(checkUser.Suspended);
|
||||
|
||||
// Suspend user
|
||||
await _github.User.Administration.Suspend(context.UserLogin);
|
||||
|
||||
// Ensure user is suspended
|
||||
checkUser = await _github.User.Get(context.UserLogin);
|
||||
Assert.True(checkUser.Suspended);
|
||||
|
||||
// Unsuspend user
|
||||
await _github.User.Administration.Unsuspend(context.UserLogin);
|
||||
|
||||
// Ensure user is not suspended
|
||||
checkUser = await _github.User.Get(context.UserLogin);
|
||||
Assert.False(checkUser.Suspended);
|
||||
}
|
||||
}
|
||||
|
||||
[GitHubEnterpriseTest(Skip = "Currently no way to add keys, so cant test listing keys")]
|
||||
public async Task CanListAllPublicKeys()
|
||||
{
|
||||
// Create a disposable user for the test
|
||||
using (var context = _github.CreateEnterpriseUserContext(GenerateNewUserDetails()).Result)
|
||||
{
|
||||
// Ensure user has a key
|
||||
//var key = await _github.User.Keys.Create(new NewPublicKey("title", "key"));
|
||||
|
||||
// Get public keys
|
||||
var observable = _github.User.Administration.ListAllPublicKeys();
|
||||
var keys = await (observable.ToList());
|
||||
|
||||
Assert.NotNull(keys);
|
||||
Assert.True(keys.Count > 0);
|
||||
|
||||
// Delete key
|
||||
//await _github.User.Administration.DeletePublicKey(key.Id);
|
||||
}
|
||||
}
|
||||
|
||||
[GitHubEnterpriseTest(Skip = "Currently no way to add keys, so cant test deleting keys")]
|
||||
public async Task CanDeletePublicKey()
|
||||
{
|
||||
// Create a disposable user for the test
|
||||
using (var context = _github.CreateEnterpriseUserContext(GenerateNewUserDetails()).Result)
|
||||
{
|
||||
// Ensure user has a key
|
||||
//var key = await _github.User.Keys.Create(new NewPublicKey("title", "key"));
|
||||
|
||||
// Delete key
|
||||
//await _github.User.Administration.DeletePublicKey(key.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using NSubstitute;
|
||||
using Octokit.Reactive;
|
||||
using Xunit;
|
||||
@@ -7,10 +8,75 @@ namespace Octokit.Tests.Reactive
|
||||
{
|
||||
public class ObservableUserAdministrationClientTests
|
||||
{
|
||||
public class TheCreateMethod
|
||||
{
|
||||
[Fact]
|
||||
public void CallsIntoClient()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableUserAdministrationClient(gitHubClient);
|
||||
|
||||
client.Create(new NewUser("auser", "email@company.com"));
|
||||
|
||||
gitHubClient.User.Administration.Received().Create(
|
||||
Arg.Is<NewUser>(a =>
|
||||
a.Login == "auser" &&
|
||||
a.Email == "email@company.com"));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheRenameMethod
|
||||
{
|
||||
[Fact]
|
||||
public void CallsIntoClient()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableUserAdministrationClient(gitHubClient);
|
||||
|
||||
client.Rename("auser", new UserRename("renamed-user"));
|
||||
|
||||
gitHubClient.User.Administration.Received().Rename(
|
||||
"auser",
|
||||
Arg.Is<UserRename>(a =>
|
||||
a.Login == "renamed-user"));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateImpersonationTokenMethod
|
||||
{
|
||||
[Fact]
|
||||
public void CallsIntoClient()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableUserAdministrationClient(gitHubClient);
|
||||
|
||||
client.CreateImpersonationToken("auser", new NewImpersonationToken(new string[] { "public_repo" }));
|
||||
|
||||
gitHubClient.User.Administration.Received().CreateImpersonationToken(
|
||||
"auser",
|
||||
Arg.Is<NewImpersonationToken>(a =>
|
||||
a.Scopes.ToList()[0] == "public_repo"));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheDeleteImpersonationTokenMethod
|
||||
{
|
||||
[Fact]
|
||||
public void CallsIntoClient()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableUserAdministrationClient(gitHubClient);
|
||||
|
||||
client.DeleteImpersonationToken("auser");
|
||||
|
||||
gitHubClient.User.Administration.Received().DeleteImpersonationToken("auser");
|
||||
}
|
||||
}
|
||||
|
||||
public class ThePromoteMethod
|
||||
{
|
||||
[Fact]
|
||||
public void GetsFromClientPromtePromote()
|
||||
public void CallsIntoClient()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableUserAdministrationClient(gitHubClient);
|
||||
@@ -24,7 +90,7 @@ namespace Octokit.Tests.Reactive
|
||||
public class TheDemoteMethod
|
||||
{
|
||||
[Fact]
|
||||
public void GetsFromClientDemoteDemote()
|
||||
public void CallsIntoClient()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableUserAdministrationClient(gitHubClient);
|
||||
@@ -38,7 +104,7 @@ namespace Octokit.Tests.Reactive
|
||||
public class TheSuspendMethod
|
||||
{
|
||||
[Fact]
|
||||
public void GetsFromClientSuspendSuspend()
|
||||
public void CallsIntoClient()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableUserAdministrationClient(gitHubClient);
|
||||
@@ -52,7 +118,7 @@ namespace Octokit.Tests.Reactive
|
||||
public class TheUnsuspendMethod
|
||||
{
|
||||
[Fact]
|
||||
public void GetsFromClientUnsuspendUnsuspend()
|
||||
public void CallsIntoClient()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableUserAdministrationClient(gitHubClient);
|
||||
@@ -63,6 +129,54 @@ namespace Octokit.Tests.Reactive
|
||||
}
|
||||
}
|
||||
|
||||
public class TheListAllPublicKeysMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrl()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableUserAdministrationClient(gitHubClient);
|
||||
|
||||
var expectedUri = "admin/keys";
|
||||
|
||||
client.ListAllPublicKeys();
|
||||
|
||||
gitHubClient.Connection.Received().Get<System.Collections.Generic.List<PublicKey>>(
|
||||
Arg.Is<Uri>(a =>
|
||||
a.ToString() == expectedUri),
|
||||
null,
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheDeleteMethod
|
||||
{
|
||||
[Fact]
|
||||
public void CallsIntoClient()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableUserAdministrationClient(gitHubClient);
|
||||
|
||||
client.Delete("auser");
|
||||
|
||||
gitHubClient.User.Administration.Received().Delete("auser");
|
||||
}
|
||||
}
|
||||
|
||||
public class TheDeletePublicKeyMethod
|
||||
{
|
||||
[Fact]
|
||||
public void CallsIntoClient()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableUserAdministrationClient(gitHubClient);
|
||||
|
||||
client.DeletePublicKey(1);
|
||||
|
||||
gitHubClient.User.Administration.Received().DeletePublicKey(1);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCtor
|
||||
{
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user