/// <summary>
		/// Removes a user from a team.
		/// </summary>
		public async Task RemoveUserFromTeamAsync(
			string organizationName,
			GitHubTeam team,
			string userName)
		{
			await _client.Organization.Team.RemoveMembership(team.Id, userName);
		}
        /// <summary>
        /// Creates a new repository.
        /// </summary>
        public async Task <GitHubRepository> CreateRepositoryAsync(
            string organizationName,
            string repositoryName,
            GitHubTeam team,
            bool overwrite)
        {
            var repository = await RetryGitHubOperationIfNeededAsync
                             (
                () => _client.Repository.Create
                (
                    organizationName,
                    new NewRepository(repositoryName)
            {
                TeamId   = team.Id,
                AutoInit = true,
                Private  = true
            }
                )
                             );

            return(ToModelRepository(repository));
        }
Esempio n. 3
0
        /// <summary>
        /// Removes a user from a team.
        /// </summary>
        public Task RemoveUserFromTeamAsync(
            string organizationName,
            GitHubTeam team,
            string userName)
        {
            return(RetryGitHubOperationIfNeededAsync
                   (
                       async() =>
            {
                var result = await _client.Organization.Team.RemoveMembership
                             (
                    team.Id,
                    userName
                             );

                if (!result)
                {
                    throw new ApiException
                    (
                        $"User {userName} not removed from team {team.Name}",
                        HttpStatusCode.NotFound
                    );
                }

                var teamMembers = await _client.Organization.Team
                                  .GetAllMembers(team.Id);

                if (teamMembers.Any(u => u.Login == userName))
                {
                    throw new ApiException
                    (
                        $"User {userName} still on team {team.Name}",
                        HttpStatusCode.NotFound
                    );
                }
            }
                   ));
        }
		/// <summary>
		/// Returns a mock GitHub team client.
		/// </summary>
		private static Mock<IGitHubTeamClient> GetMockGitHubTeamClient(string classroomName)
		{
			var team = new GitHubTeam(1, "LastNameFirstName");

			var gitHubTeamClient = new Mock<IGitHubTeamClient>();
			gitHubTeamClient
				.Setup(gc => gc.CreateTeamAsync($"{classroomName}GitHubOrg", "LastNameFirstName"))
				.ReturnsAsync(team);
			gitHubTeamClient
				.Setup(gc => gc.GetTeamAsync($"{classroomName}GitHubOrg", "LastNameFirstName"))
				.ReturnsAsync(team);
			gitHubTeamClient
				.Setup(gc => gc.InviteUserToTeamAsync($"{classroomName}GitHubOrg", team, "GitHubUser"))
				.Returns(Task.CompletedTask);
			gitHubTeamClient
				.Setup(gc => gc.RemoveUserFromTeamAsync($"{classroomName}GitHubOrg", team, "OldGitHubUser"))
				.Returns(Task.CompletedTask);

			return gitHubTeamClient;
		}