public async Task CanGetAllInvitations()
            {
                var github   = Helper.GetAuthenticatedClient();
                var repoName = Helper.MakeNameWithTimestamp("public-repo");

                using (var context = await github.CreateRepositoryContext(new NewRepository(repoName)))
                {
                    var fixture    = github.Repository.Collaborator;
                    var permission = new CollaboratorRequest(Permission.Push);

                    // invite a collaborator
                    var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, owner, permission);

                    Assert.Equal(owner, response.Invitee.Login);
                    Assert.Equal(InvitationPermissionType.Write, response.Permissions);

                    var invitations = await github.Repository.Invitation.GetAllForRepository(context.Repository.Id);

                    Assert.Equal(1, invitations.Count);
                    Assert.Equal(invitations[0].CreatedAt, response.CreatedAt);
                    Assert.Equal(invitations[0].Id, response.Id);
                    Assert.Equal(invitations[0].Invitee.Login, response.Invitee.Login);
                    Assert.Equal(invitations[0].Inviter.Login, response.Inviter.Login);
                    Assert.Equal(invitations[0].Permissions, response.Permissions);
                    Assert.Equal(invitations[0].Repository.Id, response.Repository.Id);
                }
            }
示例#2
0
 public IActionResult RemoveCollaborator(int noteID, CollaboratorRequest collaborator)
 {
     try
     {
         bool   success = false;
         string message;
         var    idClaim = HttpContext.User.Claims.FirstOrDefault(id => id.Type.Equals("id", StringComparison.InvariantCultureIgnoreCase));
         int    userID  = Convert.ToInt32(idClaim.Value);
         bool   data    = _userNoteBusiness.RemoveCollaborator(noteID, collaborator);
         if (data)
         {
             success = true;
             message = "Collaborator Removed Successfully";
             return(Ok(new { success, message }));
         }
         else
         {
             message = "Enter Proper Collaborator ID";
             return(NotFound(new { success, message }));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(new { ex.Message }));
     }
 }
        public async Task ReturnsCorrectCountOfInvitationsWithoutStart()
        {
            var collaborator = Helper.CredentialsSecondUser.Login;
            var github       = Helper.GetAuthenticatedClient();
            var repoName     = Helper.MakeNameWithTimestamp("public-repo");

            using (var context = await github.CreateRepositoryContext(new NewRepository(repoName)))
            {
                var fixture    = github.Repository.Collaborator;
                var permission = new CollaboratorRequest(Permission.Push);

                // invite a collaborator
                var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, collaborator, permission);

                Assert.Equal(collaborator, response.Invitee.Login);
                Assert.Equal(InvitationPermissionType.Write, response.Permissions);

                var options = new ApiOptions
                {
                    PageSize  = 1,
                    PageCount = 1,
                };

                var invitations = await github.Repository.Invitation.GetAllForRepository(context.Repository.Id, options);

                Assert.Equal(1, invitations.Count);
            }
        }
示例#4
0
        /// <summary>
        /// Adds a new collaborator to the repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The id of the repository</param>
        /// <param name="user">Username of the new collaborator</param>
        /// <param name="permission">The permission to set. Only valid on organization-owned repositories.</param>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        public IObservable <bool> Add(long repositoryId, string user, CollaboratorRequest permission)
        {
            Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
            Ensure.ArgumentNotNull(permission, nameof(permission));

            return(_client.Add(repositoryId, user, permission).ToObservable());
        }
            public async Task CanUpdateInvitation()
            {
                var github = Helper.GetAuthenticatedClient();

                var repoName = Helper.MakeNameWithTimestamp("public-repo");

                using (var context = await github.CreateRepositoryContext(new NewRepository(repoName)))
                {
                    var fixture    = github.Repository.Collaborator;
                    var permission = new CollaboratorRequest(Permission.Push);

                    // invite a collaborator
                    var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission);

                    Assert.Equal(context.RepositoryOwner, response.Invitee.Login);
                    Assert.Equal(InvitationPermissionType.Write, response.Permissions);

                    var updatedInvitation = new InvitationUpdate(InvitationPermissionType.Admin);

                    var update = await github.Repository.Invitation.Edit(response.Repository.Id, response.Id, updatedInvitation);

                    Assert.Equal(updatedInvitation.Permissions, update.Permissions);
                    Assert.Equal(response.Id, update.Id);
                    Assert.Equal(response.Repository.Id, update.Repository.Id);
                    Assert.Equal(response.Invitee.Login, update.Invitee.Login);
                    Assert.Equal(response.Inviter.Login, update.Inviter.Login);
                }
            }
            public async Task CanGetAllInvitations()
            {
                var github   = Helper.GetAuthenticatedClient();
                var repoName = Helper.MakeNameWithTimestamp("public-repo");

                using (var context = await github.CreateRepositoryContext(new NewRepository(repoName)))
                {
                    var fixture    = github.Repository.Collaborator;
                    var permission = new CollaboratorRequest(Permission.Push);

                    // invite a collaborator
                    var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission);

                    Assert.Equal(context.RepositoryOwner, response.Invitee.Login);
                    Assert.Equal(InvitationPermissionType.Write, response.Permissions);

                    var invitations = await github.Repository.Invitation.GetAllForCurrent();

                    Assert.True(invitations.Count >= 1);
                    Assert.NotNull(invitations.FirstOrDefault(i => i.CreatedAt == response.CreatedAt));
                    Assert.NotNull(invitations.FirstOrDefault(i => i.Id == response.Id));
                    Assert.NotNull(invitations.FirstOrDefault(i => i.Inviter.Login == response.Inviter.Login));
                    Assert.NotNull(invitations.FirstOrDefault(i => i.Invitee.Login == response.Invitee.Login));
                    Assert.NotNull(invitations.FirstOrDefault(i => i.Permissions == response.Permissions));
                    Assert.NotNull(invitations.FirstOrDefault(i => i.Repository.Id == response.Repository.Id));
                }
            }
            public void EnsuresNonEmptyArguments()
            {
                SetupWithNonReactiveClient();
                var permission = new CollaboratorRequest(Permission.Push);

                Assert.Throws <ArgumentException>(() => _client.Invite("", "repo", "user", permission));
                Assert.Throws <ArgumentException>(() => _client.Invite("owner", "", "user", permission));
                Assert.Throws <ArgumentException>(() => _client.Invite("owner", "repo", "", permission));
            }
示例#8
0
        /// <summary>
        /// Adds a new collaborator to the repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/collaborators/#add-collaborator">API documentation</a> for more information.
        /// </remarks>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="user">Username of the new collaborator</param>
        /// <param name="permission">The permission to set. Only valid on organization-owned repositories.</param>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        public IObservable <bool> Add(string owner, string name, string user, CollaboratorRequest permission)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
            Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
            Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
            Ensure.ArgumentNotNull(permission, nameof(permission));

            return(_client.Add(owner, name, user, permission).ToObservable());
        }
            public void RequestsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new RepoCollaboratorsClient(connection);

                var permission = new CollaboratorRequest(Permission.Push);

                client.Invite("owner", "test", "user1", permission);
                connection.Received().Put <RepositoryInvitation>(Arg.Is <Uri>(u => u.ToString() == "repos/owner/test/collaborators/user1"), Arg.Is <CollaboratorRequest>(permission), Arg.Any <string>(), Arg.Is <string>("application/vnd.github.swamp-thing-preview+json"));
            }
            public void CallsInviteOnRegularDeploymentsClient()
            {
                SetupWithoutNonReactiveClient();
                var permission = new CollaboratorRequest(Permission.Push);

                _client.Invite("owner", "repo", "user", permission);

                _githubClient.Repository.Collaborator.Received(1).Invite(Arg.Is("owner"),
                                                                         Arg.Is("repo"),
                                                                         Arg.Is("user"),
                                                                         Arg.Is(permission));
            }
            public async Task EnsuresNonWhitespaceArguments()
            {
                SetupWithNonReactiveClient();
                var permission = new CollaboratorRequest(Permission.Push);

                await AssertEx.ThrowsWhenGivenWhitespaceArgument(
                    async whitespace => await _client.Invite(whitespace, "repo", "user", permission));

                await AssertEx.ThrowsWhenGivenWhitespaceArgument(
                    async whitespace => await _client.Invite("owner", whitespace, "user", permission));

                await AssertEx.ThrowsWhenGivenWhitespaceArgument(
                    async whitespace => await _client.Invite("owner", "repo", whitespace, permission));
            }
        public async Task ReturnsCorrectCountOfInvitationsWithStart()
        {
            var github    = Helper.GetAuthenticatedClient();
            var repoNames = Enumerable.Range(0, 2).Select(i => Helper.MakeNameWithTimestamp($"public-repo{i}")).ToList();

            var contexts = new List <RepositoryContext>();

            try
            {
                foreach (var repoName in repoNames)
                {
                    contexts.Add(await github.CreateRepositoryContext(new NewRepository(repoName)));
                }
                var fixture    = github.Repository.Collaborator;
                var permission = new CollaboratorRequest(Permission.Push);

                // invite a collaborator to all repos
                foreach (var context in contexts)
                {
                    var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission);

                    Assert.Equal(context.RepositoryOwner, response.Invitee.Login);
                    Assert.Equal(InvitationPermissionType.Write, response.Permissions);
                }

                var startOptions = new ApiOptions
                {
                    PageSize  = 1,
                    PageCount = 1,
                    StartPage = 2
                };


                var invitations = await github.Repository.Invitation.GetAllForCurrent(startOptions);

                Assert.Equal(1, invitations.Count);
            }
            finally
            {
                if (contexts != null)
                {
                    foreach (var context in contexts)
                    {
                        context?.Dispose();
                    }
                }
            }
        }
            public async Task EnsuresNonNullArguments()
            {
                var client     = new RepoCollaboratorsClient(Substitute.For <IApiConnection>());
                var permission = new CollaboratorRequest(Permission.Push);

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.Invite(null, "test", "user1", permission));

                await Assert.ThrowsAsync <ArgumentException>(() => client.Invite("", "test", "user1", permission));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.Invite("owner", null, "user1", permission));

                await Assert.ThrowsAsync <ArgumentException>(() => client.Invite("owner", "", "user1", permission));

                await Assert.ThrowsAsync <ArgumentException>(() => client.Invite("owner", "test", "", permission));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.Invite("owner", "test", null, permission));

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.Invite("owner", "test", "user1", null));
            }
        public async Task ReturnsDistinctInvitationsBasedOnStart()
        {
            var collaborator1 = Helper.CredentialsSecondUser.Login;
            var github        = Helper.GetAuthenticatedClient();
            var repoName      = Helper.MakeNameWithTimestamp("public-repo");

            using (var context = await github.CreateRepositoryContext(new NewRepository(repoName)))
            {
                var fixture    = github.Repository.Collaborator;
                var permission = new CollaboratorRequest(Permission.Push);

                // invite a collaborator
                var response1 = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, collaborator1, permission);

                Assert.Equal(collaborator1, response1.Invitee.Login);
                Assert.Equal(InvitationPermissionType.Write, response1.Permissions);

                var response2 = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission);

                Assert.Equal(context.RepositoryOwner, response2.Invitee.Login);
                Assert.Equal(InvitationPermissionType.Write, response2.Permissions);

                var startOptions = new ApiOptions
                {
                    PageSize  = 1,
                    PageCount = 1
                };

                var skipStartOptions = new ApiOptions
                {
                    PageSize  = 1,
                    PageCount = 1,
                    StartPage = 2
                };

                var firstInvitations = await github.Repository.Invitation.GetAllForRepository(context.Repository.Id, startOptions);

                var secondInvitations = await github.Repository.Invitation.GetAllForRepository(context.Repository.Id, skipStartOptions);

                Assert.NotEqual(firstInvitations[0].Invitee.Login, secondInvitations[0].Invitee.Login);
            }
        }
 public bool RemoveCollaborator(int noteID, CollaboratorRequest collaborator)
 {
     try
     {
         var collaboratorsData = _context.Collaborators.
                                 Where(collab => collab.UserID == collaborator.UserID && collab.NoteID == noteID).FirstOrDefault();
         if (collaboratorsData != null)
         {
             _context.Remove(collaboratorsData);
             _context.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
示例#16
0
        /// <summary>
        /// Invites a user as a collaborator to a repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
        /// </remarks>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="user">The username of the prospective collaborator</param>
        /// <param name="permission">The permission to set. Only valid on organization-owned repositories.</param>
        public IObservable <RepositoryInvitation> Invite(string owner, string name, string user, CollaboratorRequest permission)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
            Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
            Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
            Ensure.ArgumentNotNull(permission, nameof(permission));

            return(_client.Invite(owner, name, user, permission).ToObservable());
        }
        public bool RemoveCollaborator(int noteID, CollaboratorRequest collaborator)
        {
            bool data = _userNoteRepository.RemoveCollaborator(noteID, collaborator);

            return(data);
        }
        /// <summary>
        /// Adds a new collaborator to the repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The id of the repository</param>
        /// <param name="user">Username of the new collaborator</param>
        /// <param name="permission">The permission to set. Only valid on organization-owned repositories.</param>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        public IObservable<bool> Add(long repositoryId, string user, CollaboratorRequest permission)
        {
            Ensure.ArgumentNotNullOrEmptyString(user, "user");
            Ensure.ArgumentNotNull(permission, "permission");

            return _client.Add(repositoryId, user, permission).ToObservable();
        }
        /// <summary>
        /// Invites a user as a collaborator to a repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The id of the repository</param>
        /// <param name="user">The username of the prospective collaborator</param>
        /// <param name="permission">The permission to set. Only valid on organization-owned repositories.</param>
        public IObservable <RepositoryInvitation> Invite(long repositoryId, string user, CollaboratorRequest permission)
        {
            Ensure.ArgumentNotNullOrEmptyString(user, "user");
            Ensure.ArgumentNotNull(permission, "psermission");

            return(_client.Invite(repositoryId, user, permission).ToObservable());
        }
        /// <summary>
        /// Invites a user as a collaborator to a repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
        /// </remarks>
        /// <param name="repositoryId">The id of the repository</param>
        /// <param name="user">The username of the prospective collaborator</param>   
        /// <param name="permission">The permission to set. Only valid on organization-owned repositories.</param>
        public IObservable<RepositoryInvitation> Invite(int repositoryId, string user, CollaboratorRequest permission)
        {
            Ensure.ArgumentNotNullOrEmptyString(user, "user");
            Ensure.ArgumentNotNull(permission, "psermission");

            return _client.Invite(repositoryId, user, permission).ToObservable();
        }
        /// <summary>
        /// Invites a user as a collaborator to a repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
        /// </remarks>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="user">The username of the prospective collaborator</param>
        /// <param name="permission">The permission to set. Only valid on organization-owned repositories.</param>
        public IObservable<RepositoryInvitation> Invite(string owner, string name, string user, CollaboratorRequest permission)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNullOrEmptyString(user, "user");
            Ensure.ArgumentNotNull(permission, "psermission");

            return _client.Invite(owner, name, user, permission).ToObservable();
        }
        /// <summary>
        /// Adds a new collaborator to the repository.
        /// </summary>
        /// <remarks>
        /// See the <a href="http://developer.github.com/v3/repos/collaborators/#add-collaborator">API documentation</a> for more information.
        /// </remarks>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="user">Username of the new collaborator</param>
        /// <param name="permission">The permission to set. Only valid on organization-owned repositories.</param>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        public IObservable<bool> Add(string owner, string name, string user, CollaboratorRequest permission)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNullOrEmptyString(user, "user");
            Ensure.ArgumentNotNull(permission, "permission");

            return _client.Add(owner, name, user, permission).ToObservable();
        }
            public void CallsInviteOnRegularDeploymentsClient()
            {
                SetupWithoutNonReactiveClient();
                var permission = new CollaboratorRequest(Permission.Push);

                _client.Invite("owner", "repo", "user", permission);

                _githubClient.Repository.Collaborator.Received(1).Invite(Arg.Is("owner"),
                    Arg.Is("repo"),
                    Arg.Is("user"),
                    Arg.Is(permission));
            }
            public async Task EnsuresNonWhitespaceArguments()
            {
                SetupWithNonReactiveClient();
                var permission = new CollaboratorRequest(Permission.Push);

                await AssertEx.ThrowsWhenGivenWhitespaceArgument(
                    async whitespace => await _client.Invite(whitespace, "repo", "user", permission));
                await AssertEx.ThrowsWhenGivenWhitespaceArgument(
                    async whitespace => await _client.Invite("owner", whitespace, "user", permission));
                await AssertEx.ThrowsWhenGivenWhitespaceArgument(
                    async whitespace => await _client.Invite("owner", "repo", whitespace, permission));
            }
            public async Task EnsuresNonNullArguments()
            {
                var client = new RepoCollaboratorsClient(Substitute.For<IApiConnection>());
                var permission = new CollaboratorRequest(Permission.Push);

                await Assert.ThrowsAsync<ArgumentNullException>(() => client.Invite(null, "test", "user1", permission));
                await Assert.ThrowsAsync<ArgumentException>(() => client.Invite("", "test", "user1", permission));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.Invite("owner", null, "user1", permission));
                await Assert.ThrowsAsync<ArgumentException>(() => client.Invite("owner", "", "user1", permission));
                await Assert.ThrowsAsync<ArgumentException>(() => client.Invite("owner", "test", "", permission));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.Invite("owner", "test", null, permission));
                await Assert.ThrowsAsync<ArgumentNullException>(() => client.Invite("owner", "test", "user1", null));
            }
        public async Task ReturnsDistinctInvitationsBasedOnStart()
        {
            var github    = Helper.GetAuthenticatedClient();
            var repoNames = Enumerable.Range(0, 2).Select(i => Helper.MakeNameWithTimestamp($"public-repo{i}")).ToList();

            var contexts = new List <RepositoryContext>();

            try
            {
                foreach (var repoName in repoNames)
                {
                    contexts.Add(await github.CreateRepositoryContext(new NewRepository(repoName)));
                }
                var fixture    = github.Repository.Collaborator;
                var permission = new CollaboratorRequest(Permission.Push);

                // invite a collaborator to all repos
                foreach (var context in contexts)
                {
                    var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission);

                    Assert.Equal(context.RepositoryOwner, response.Invitee.Login);
                    Assert.Equal(InvitationPermissionType.Write, response.Permissions);
                }

                var startOptions = new ApiOptions
                {
                    PageSize  = 1,
                    PageCount = 1
                };

                var skipStartOptions = new ApiOptions
                {
                    PageSize  = 1,
                    PageCount = 1,
                    StartPage = 2
                };

                var firstInvitations = await github.Repository.Invitation.GetAllForCurrent(startOptions);

                var secondInvitations = await github.Repository.Invitation.GetAllForCurrent(skipStartOptions);

                var invitations       = firstInvitations.Concat(secondInvitations).ToArray();
                var invitationsLength = invitations.Length;
                for (int i = 0; i < invitationsLength; i++)
                {
                    for (int j = i + 1; j < invitationsLength; j++)
                    {
                        Assert.NotEqual(invitations[i].Repository.FullName, invitations[j].Repository.FullName);
                    }
                }
            }
            finally
            {
                if (contexts != null)
                {
                    foreach (var context in contexts)
                    {
                        context?.Dispose();
                    }
                }
            }
        }
            public void EnsuresNonEmptyArguments()
            {
                SetupWithNonReactiveClient();
                var permission = new CollaboratorRequest(Permission.Push);

                Assert.Throws<ArgumentException>(() => _client.Invite("", "repo", "user", permission));
                Assert.Throws<ArgumentException>(() => _client.Invite("owner", "", "user", permission));
                Assert.Throws<ArgumentException>(() => _client.Invite("owner", "repo", "", permission));
            }
            public void RequestsCorrectUrl()
            {
                var connection = Substitute.For<IApiConnection>();
                var client = new RepoCollaboratorsClient(connection);

                var permission = new CollaboratorRequest(Permission.Push);

                client.Invite("owner", "test", "user1", permission);
                connection.Received().Put<RepositoryInvitation>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/test/collaborators/user1"), Arg.Is<CollaboratorRequest>(permission), Arg.Any<string>(), Arg.Is<string>("application/vnd.github.swamp-thing-preview+json"));
            }