diff --git a/Octokit.Reactive/Clients/IObservableOrganizationMembersClient.cs b/Octokit.Reactive/Clients/IObservableOrganizationMembersClient.cs
index 8e5a903bc0..a327040aaa 100644
--- a/Octokit.Reactive/Clients/IObservableOrganizationMembersClient.cs
+++ b/Octokit.Reactive/Clients/IObservableOrganizationMembersClient.cs
@@ -304,6 +304,21 @@ public interface IObservableOrganizationMembersClient
///
IObservable AddOrUpdateOrganizationMembership(string org, string user, OrganizationMembershipUpdate addOrUpdateRequest);
+ ///
+ /// Create an organization invitation for a user
+ ///
+ ///
+ /// This method requires authentication.
+ /// The authenticated user must be an organization owner.
+ /// See the API documentation
+ /// for more information.
+ ///
+ /// The login for the organization
+ /// An instance containing the
+ /// details of the organization invitation
+ ///
+ IObservable CreateOrganizationInvitation(string org, OrganizationInvitationRequest invitationRequest);
+
///
/// Remove a user's membership with an organization.
///
diff --git a/Octokit.Reactive/Clients/ObservableOrganizationMembersClient.cs b/Octokit.Reactive/Clients/ObservableOrganizationMembersClient.cs
index e258722c26..31d41f23ba 100644
--- a/Octokit.Reactive/Clients/ObservableOrganizationMembersClient.cs
+++ b/Octokit.Reactive/Clients/ObservableOrganizationMembersClient.cs
@@ -418,6 +418,27 @@ public IObservable AddOrUpdateOrganizationMembership(str
return _client.AddOrUpdateOrganizationMembership(org, user, addOrUpdateRequest).ToObservable();
}
+
+ ///
+ /// Create an organization invitation for a user
+ ///
+ ///
+ /// This method requires authentication.
+ /// The authenticated user must be an organization owner.
+ /// See the API documentation
+ /// for more information.
+ ///
+ /// The login for the organization
+ /// An instance containing the
+ /// details of the organization invitation
+ ///
+ public IObservable CreateOrganizationInvitation(string org, OrganizationInvitationRequest invitationRequest)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
+ Ensure.ArgumentNotNull(invitationRequest, nameof(invitationRequest));
+
+ return _client.CreateOrganizationInvitation(org, invitationRequest).ToObservable();
+ }
///
/// Remove a user's membership with an organization.
diff --git a/Octokit.Tests.Integration/Clients/OrganizationMembersClientTests.cs b/Octokit.Tests.Integration/Clients/OrganizationMembersClientTests.cs
index d1fcb7f2c9..580d24fe09 100644
--- a/Octokit.Tests.Integration/Clients/OrganizationMembersClientTests.cs
+++ b/Octokit.Tests.Integration/Clients/OrganizationMembersClientTests.cs
@@ -1,5 +1,7 @@
-using System.Linq;
+using System;
+using System.Linq;
using System.Threading.Tasks;
+using Octokit.Tests.Helpers;
using Octokit.Tests.Integration.Helpers;
using Xunit;
@@ -172,6 +174,95 @@ public async Task ReturnsUsersPendingAdminOrganizationMembership()
}
}
+ public class TheCreateOrganizationInvitationMethod
+ {
+ readonly IGitHubClient _gitHub;
+
+ public TheCreateOrganizationInvitationMethod()
+ {
+ _gitHub = Helper.GetAuthenticatedClient();
+ }
+
+ [OrganizationTest]
+ public async Task ReturnsOrganizationMembershipInvitationViaUserId()
+ {
+ var user = await _gitHub.User.Get("alfhenrik-test-2");
+
+ var organizationInvitationRequest = new OrganizationInvitationRequest(user.Id);
+ var organizationMembershipInvitation = await _gitHub.Organization.Member.CreateOrganizationInvitation(Helper.Organization, organizationInvitationRequest);
+
+ Assert.Equal("alfhenrik-test-2", organizationMembershipInvitation.Login);
+ Assert.Equal(OrganizationMembershipRole.DirectMember, organizationMembershipInvitation.Role.Value);
+ Assert.Equal(Helper.UserName, organizationMembershipInvitation.Inviter.Login);
+
+ await _gitHub.Organization.Member.RemoveOrganizationMembership(Helper.Organization, "alfhenrik-test-2");
+ }
+
+ [OrganizationTest]
+ public async Task ReturnsOrganizationMembershipInvitationViaUserEmail()
+ {
+ var email = RandomEmailGenerator.GenerateRandomEmail();
+
+ var organizationInvitationRequest = new OrganizationInvitationRequest(email);
+ var organizationMembershipInvitation = await _gitHub.Organization.Member.CreateOrganizationInvitation(Helper.Organization, organizationInvitationRequest);
+
+ Assert.Equal(email, organizationMembershipInvitation.Email);
+ Assert.Equal(OrganizationMembershipRole.DirectMember, organizationMembershipInvitation.Role.Value);
+ Assert.Equal(Helper.UserName, organizationMembershipInvitation.Inviter.Login);
+
+ await _gitHub.Organization.Member.CancelOrganizationInvitation(Helper.Organization, organizationMembershipInvitation.Id);
+ }
+
+ [OrganizationTest]
+ public async Task ThrowsApiValidationExceptionForCurrentOrganizationMembers()
+ {
+ var user = await _gitHub.User.Get(Helper.UserName);
+ var organizationInvitationRequest = new OrganizationInvitationRequest(user.Id);
+
+ await Assert.ThrowsAsync(() => _gitHub.Organization.Member.CreateOrganizationInvitation(Helper.Organization, organizationInvitationRequest));
+ }
+
+ [OrganizationTest]
+ public async Task ReturnsOrganizationMembershipInvitationSingleTeam()
+ {
+ var user = await _gitHub.User.Get("alfhenrik-test-2");
+
+ var team1 = await _gitHub.Organization.Team.Create(Helper.Organization, new NewTeam("TestTeam1"));
+
+ var organizationInvitationRequest = new OrganizationInvitationRequest(user.Id, new int[] {team1.Id});
+ var organizationMembershipInvitation = await _gitHub.Organization.Member.CreateOrganizationInvitation(Helper.Organization, organizationInvitationRequest);
+
+ Assert.Equal("alfhenrik-test-2", organizationMembershipInvitation.Login);
+ Assert.Equal(OrganizationMembershipRole.DirectMember, organizationMembershipInvitation.Role.Value);
+ Assert.Equal(Helper.UserName, organizationMembershipInvitation.Inviter.Login);
+ Assert.Equal(1, organizationMembershipInvitation.TeamCount);
+
+ await _gitHub.Organization.Team.Delete(Helper.Organization, team1.Slug);
+ await _gitHub.Organization.Member.RemoveOrganizationMembership(Helper.Organization, "alfhenrik-test-2");
+ }
+
+ [OrganizationTest]
+ public async Task ReturnsOrganizationMembershipInvitationMultipleTeams()
+ {
+ var user = await _gitHub.User.Get("alfhenrik-test-2");
+
+ var team1 = await _gitHub.Organization.Team.Create(Helper.Organization, new NewTeam("TestTeam1"));
+ var team2 = await _gitHub.Organization.Team.Create(Helper.Organization, new NewTeam("TestTeam2"));
+
+ var organizationInvitationRequest = new OrganizationInvitationRequest(user.Id, new int[] {team1.Id, team2.Id});
+ var organizationMembershipInvitation = await _gitHub.Organization.Member.CreateOrganizationInvitation(Helper.Organization, organizationInvitationRequest);
+
+ Assert.Equal("alfhenrik-test-2", organizationMembershipInvitation.Login);
+ Assert.Equal(OrganizationMembershipRole.DirectMember, organizationMembershipInvitation.Role.Value);
+ Assert.Equal(Helper.UserName, organizationMembershipInvitation.Inviter.Login);
+ Assert.Equal(2, organizationMembershipInvitation.TeamCount);
+
+ await _gitHub.Organization.Team.Delete(Helper.Organization, team1.Slug);
+ await _gitHub.Organization.Team.Delete(Helper.Organization, team2.Slug);
+ await _gitHub.Organization.Member.RemoveOrganizationMembership(Helper.Organization, "alfhenrik-test-2");
+ }
+ }
+
public class TheRemoveOrganizationMembershipMethod
{
readonly IGitHubClient _gitHub;
diff --git a/Octokit.Tests.Integration/Reactive/ObservableOrganizationMembersClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableOrganizationMembersClientTests.cs
index 6095584ba3..aed9bcf5b7 100644
--- a/Octokit.Tests.Integration/Reactive/ObservableOrganizationMembersClientTests.cs
+++ b/Octokit.Tests.Integration/Reactive/ObservableOrganizationMembersClientTests.cs
@@ -1,7 +1,9 @@
-using System.Reactive.Linq;
+using System;
+using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using System.Threading.Tasks;
using Octokit.Reactive;
+using Octokit.Tests.Helpers;
using Octokit.Tests.Integration.Helpers;
using Xunit;
@@ -62,6 +64,97 @@ public async Task ReturnsUsersPendingAdminOrganizationMembership()
await _client.RemoveOrganizationMembership(Helper.Organization, "alfhenrik-test-2");
}
}
+
+ public class TheCreateOrganizationInvitationMethod
+ {
+ readonly IGitHubClient _gitHub;
+ readonly ObservableOrganizationMembersClient _client;
+
+ public TheCreateOrganizationInvitationMethod()
+ {
+ _gitHub = Helper.GetAuthenticatedClient();
+ _client = new ObservableOrganizationMembersClient(_gitHub);
+ }
+
+ [OrganizationTest]
+ public async Task ReturnsOrganizationMembershipInvitationViaUserId()
+ {
+ var user = await _gitHub.User.Get("alfhenrik-test-2");
+
+ var organizationInvitationRequest = new OrganizationInvitationRequest(user.Id);
+ var organizationMembershipInvitation = await _client.CreateOrganizationInvitation(Helper.Organization, organizationInvitationRequest);
+
+ Assert.Equal("alfhenrik-test-2", organizationMembershipInvitation.Login);
+ Assert.Equal(OrganizationMembershipRole.DirectMember, organizationMembershipInvitation.Role.Value);
+ Assert.Equal(Helper.UserName, organizationMembershipInvitation.Inviter.Login);
+
+ await _client.RemoveOrganizationMembership(Helper.Organization, "alfhenrik-test-2");
+ }
+
+ [OrganizationTest]
+ public async Task ReturnsOrganizationMembershipInvitationViaUserEmail()
+ {
+ var email = RandomEmailGenerator.GenerateRandomEmail();
+
+ var organizationInvitationRequest = new OrganizationInvitationRequest(email);
+ var organizationMembershipInvitation = await _client.CreateOrganizationInvitation(Helper.Organization, organizationInvitationRequest);
+
+ Assert.Equal(email, organizationMembershipInvitation.Email);
+ Assert.Equal(OrganizationMembershipRole.DirectMember, organizationMembershipInvitation.Role.Value);
+ Assert.Equal(Helper.UserName, organizationMembershipInvitation.Inviter.Login);
+
+ await _client.CancelOrganizationInvitation(Helper.Organization, organizationMembershipInvitation.Id);
+ }
+
+ [OrganizationTest]
+ public async Task ThrowsApiValidationExceptionForCurrentOrganizationMembers()
+ {
+ var user = await _gitHub.User.Get(Helper.UserName);
+ var organizationInvitationRequest = new OrganizationInvitationRequest(user.Id);
+
+ await Assert.ThrowsAsync(() => _client.CreateOrganizationInvitation(Helper.Organization, organizationInvitationRequest).ToTask());
+ }
+
+ [OrganizationTest]
+ public async Task ReturnsOrganizationMembershipInvitationSingleTeam()
+ {
+ var user = await _gitHub.User.Get("alfhenrik-test-2");
+
+ var team1 = await _gitHub.Organization.Team.Create(Helper.Organization, new NewTeam("TestTeam1"));
+
+ var organizationInvitationRequest = new OrganizationInvitationRequest(user.Id, new int[] {team1.Id});
+ var organizationMembershipInvitation = await _client.CreateOrganizationInvitation(Helper.Organization, organizationInvitationRequest);
+
+ Assert.Equal("alfhenrik-test-2", organizationMembershipInvitation.Login);
+ Assert.Equal(OrganizationMembershipRole.DirectMember, organizationMembershipInvitation.Role.Value);
+ Assert.Equal(Helper.UserName, organizationMembershipInvitation.Inviter.Login);
+ Assert.Equal(1, organizationMembershipInvitation.TeamCount);
+
+ await _gitHub.Organization.Team.Delete(Helper.Organization, team1.Slug);
+ await _client.RemoveOrganizationMembership(Helper.Organization, "alfhenrik-test-2");
+ }
+
+ [OrganizationTest]
+ public async Task ReturnsOrganizationMembershipInvitationMultipleTeams()
+ {
+ var user = await _gitHub.User.Get("alfhenrik-test-2");
+
+ var team1 = await _gitHub.Organization.Team.Create(Helper.Organization, new NewTeam("TestTeam1"));
+ var team2 = await _gitHub.Organization.Team.Create(Helper.Organization, new NewTeam("TestTeam2"));
+
+ var organizationInvitationRequest = new OrganizationInvitationRequest(user.Id, new int[] {team1.Id, team2.Id});
+ var organizationMembershipInvitation = await _client.CreateOrganizationInvitation(Helper.Organization, organizationInvitationRequest);
+
+ Assert.Equal("alfhenrik-test-2", organizationMembershipInvitation.Login);
+ Assert.Equal(OrganizationMembershipRole.DirectMember, organizationMembershipInvitation.Role.Value);
+ Assert.Equal(Helper.UserName, organizationMembershipInvitation.Inviter.Login);
+ Assert.Equal(2, organizationMembershipInvitation.TeamCount);
+
+ await _gitHub.Organization.Team.Delete(Helper.Organization, team1.Slug);
+ await _gitHub.Organization.Team.Delete(Helper.Organization, team2.Slug);
+ await _client.RemoveOrganizationMembership(Helper.Organization, "alfhenrik-test-2");
+ }
+ }
public class TheRemoveOrganizationMembershipMethod
{
diff --git a/Octokit.Tests/Clients/OrganizationMembersClientTests.cs b/Octokit.Tests/Clients/OrganizationMembersClientTests.cs
index d09ed836aa..838cca8644 100644
--- a/Octokit.Tests/Clients/OrganizationMembersClientTests.cs
+++ b/Octokit.Tests/Clients/OrganizationMembersClientTests.cs
@@ -2,6 +2,7 @@
using System.Net;
using System.Threading.Tasks;
using NSubstitute;
+using NSubstitute.Core.DependencyInjection;
using Octokit.Internal;
using Xunit;
@@ -562,6 +563,33 @@ public async Task EnsureNonNullArguments()
}
}
+ public class TheCreateOrganizationInvitationMethod
+ {
+ [Fact]
+ public void PostsToTheCorrectUrl()
+ {
+ var organizationInvitationRequest = new OrganizationInvitationRequest("email");
+
+ var connection = Substitute.For();
+ var client = new OrganizationMembersClient(connection);
+
+ client.CreateOrganizationInvitation("org", organizationInvitationRequest);
+
+ connection.Received().Post(Arg.Is(u => u.ToString() == "orgs/org/invitations"), Arg.Any