From 6660f1be809272dc9527db622bc923b7b2b460d1 Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Tue, 22 Apr 2014 17:45:17 -0300 Subject: [PATCH 1/3] Added GetMembers to retrieve all team members. --- .../Clients/IObservableTeamsClient.cs | 11 ++++++++ .../Clients/ObservableTeamsClient.cs | 14 +++++++++++ .../Clients/TeamsClientTests.cs | 25 +++++++++++++++++++ Octokit.Tests/Clients/TeamsClientTests.cs | 14 +++++++++++ Octokit/Clients/ITeamsClient.cs | 10 ++++++++ Octokit/Clients/TeamsClient.cs | 14 +++++++++++ Octokit/Helpers/ApiUrls.cs | 11 +++++++- 7 files changed, 98 insertions(+), 1 deletion(-) diff --git a/Octokit.Reactive/Clients/IObservableTeamsClient.cs b/Octokit.Reactive/Clients/IObservableTeamsClient.cs index 67db723dac..d11df7867d 100644 --- a/Octokit.Reactive/Clients/IObservableTeamsClient.cs +++ b/Octokit.Reactive/Clients/IObservableTeamsClient.cs @@ -31,6 +31,17 @@ public interface IObservableTeamsClient /// A list of the orgs's teams s. IObservable GetAll(string org); + /// + /// Returns all members of the given team. + /// + /// The team identifier + /// + /// https://developer.github.com/v3/orgs/teams/#list-team-members + /// + /// Thrown when a general API error occurs. + /// A list of the team's member s. + IObservable GetMembers(int id); + /// /// Returns newly created for the current org. /// diff --git a/Octokit.Reactive/Clients/ObservableTeamsClient.cs b/Octokit.Reactive/Clients/ObservableTeamsClient.cs index b295ac1ad3..bdbdff8ce3 100644 --- a/Octokit.Reactive/Clients/ObservableTeamsClient.cs +++ b/Octokit.Reactive/Clients/ObservableTeamsClient.cs @@ -51,6 +51,20 @@ public IObservable GetAll(string org) return _connection.GetAndFlattenAllPages(ApiUrls.OrganizationTeams(org)); } + /// + /// Returns all members of the given team. + /// + /// The team identifier + /// + /// https://developer.github.com/v3/orgs/teams/#list-team-members + /// + /// Thrown when a general API error occurs. + /// A list of the team's member s. + public IObservable GetMembers(int id) + { + return _connection.GetAndFlattenAllPages(ApiUrls.TeamMembers(id)); + } + /// /// Returns newly created for the current org. /// diff --git a/Octokit.Tests.Integration/Clients/TeamsClientTests.cs b/Octokit.Tests.Integration/Clients/TeamsClientTests.cs index 8e2f8d2445..82acd4e348 100644 --- a/Octokit.Tests.Integration/Clients/TeamsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/TeamsClientTests.cs @@ -120,4 +120,29 @@ public async Task GetsIsMemberFalseForNonMemberWhenAuthenticated() Assert.False(isMember); } } + + public class TheGetMembersMethod + { + readonly Team team; + + public TheGetMembersMethod() + { + var github = new GitHubClient(new ProductHeaderValue("OctokitTests")) { Credentials = Helper.Credentials }; + + team = github.Organization.Team.GetAll(Helper.Organization).Result.First(); + } + + [OrganizationTest] + public async Task GetsAllMembersWhenAuthenticated() + { + var github = new GitHubClient(new ProductHeaderValue("OctokitTests")) + { + Credentials = Helper.Credentials + }; + + var members = await github.Organization.Team.GetMembers(team.Id); + + Assert.Contains(Helper.UserName, members.Select(u => u.Login)); + } + } } diff --git a/Octokit.Tests/Clients/TeamsClientTests.cs b/Octokit.Tests/Clients/TeamsClientTests.cs index 377dd2a638..d49e6a5f94 100644 --- a/Octokit.Tests/Clients/TeamsClientTests.cs +++ b/Octokit.Tests/Clients/TeamsClientTests.cs @@ -43,6 +43,20 @@ public void EnsuresNonNullArguments() } } + public class TheGetMembersMethod + { + [Fact] + public void RequestsTheCorrectUrl() + { + var connection = Substitute.For(); + var client = new TeamsClient(connection); + + client.GetMembers(1); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "teams/1/members")); + } + } + public class TheCreateTeamMethod { [Fact] diff --git a/Octokit/Clients/ITeamsClient.cs b/Octokit/Clients/ITeamsClient.cs index be759a8e68..91b44aea10 100644 --- a/Octokit/Clients/ITeamsClient.cs +++ b/Octokit/Clients/ITeamsClient.cs @@ -33,6 +33,16 @@ public interface ITeamsClient /// A list of the orgs's teams s. Task> GetAll(string org); + /// + /// Returns all members of the given team. + /// + /// The team identifier + /// + /// https://developer.github.com/v3/orgs/teams/#list-team-members + /// + /// A list of the team's member s. + Task> GetMembers(int id); + /// /// Returns newly created for the current org. /// diff --git a/Octokit/Clients/TeamsClient.cs b/Octokit/Clients/TeamsClient.cs index 48310ff5c1..a2dcceabc5 100644 --- a/Octokit/Clients/TeamsClient.cs +++ b/Octokit/Clients/TeamsClient.cs @@ -52,6 +52,20 @@ public Task> GetAll(string org) return ApiConnection.GetAll(endpoint); } + /// + /// Returns all members of the given team. + /// + /// The team identifier + /// + /// https://developer.github.com/v3/orgs/teams/#list-team-members + /// + /// A list of the team's member s. + public Task> GetMembers(int id) + { + var endpoint = ApiUrls.TeamMembers(id); + + return ApiConnection.GetAll(endpoint); + } /// /// Returns newly created for the current org. diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 5f87286787..3d863ef995 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -946,7 +946,7 @@ public static Uri Teams(int id) } /// - /// returns the for team members + /// returns the for team member /// /// The team id /// The user login. @@ -955,6 +955,15 @@ public static Uri TeamMember(int id, string login) return "teams/{0}/members/{1}".FormatUri(id, login); } + /// + /// returns the for team members list + /// + /// The team id + public static Uri TeamMembers(int id) + { + return "teams/{0}/members".FormatUri(id); + } + /// /// returns the for teams /// use for update or deleting a team From 120b05b709222ca1b9d50cea9aaf41c521d08875 Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Tue, 22 Apr 2014 17:47:53 -0300 Subject: [PATCH 2/3] Fixed indenting. Conflicts: Octokit.Tests/Clients/TeamsClientTests.cs --- .../Clients/IObservableTeamsClient.cs | 16 +++++++------- .../Clients/TeamsClientTests.cs | 2 +- Octokit/Clients/ITeamsClient.cs | 16 +++++++------- Octokit/Clients/TeamsClient.cs | 22 +++++++++---------- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableTeamsClient.cs b/Octokit.Reactive/Clients/IObservableTeamsClient.cs index d11df7867d..10e48abba6 100644 --- a/Octokit.Reactive/Clients/IObservableTeamsClient.cs +++ b/Octokit.Reactive/Clients/IObservableTeamsClient.cs @@ -31,16 +31,16 @@ public interface IObservableTeamsClient /// A list of the orgs's teams s. IObservable GetAll(string org); - /// - /// Returns all members of the given team. - /// - /// The team identifier - /// - /// https://developer.github.com/v3/orgs/teams/#list-team-members - /// + /// + /// Returns all members of the given team. + /// + /// The team identifier + /// + /// https://developer.github.com/v3/orgs/teams/#list-team-members + /// /// Thrown when a general API error occurs. /// A list of the team's member s. - IObservable GetMembers(int id); + IObservable GetMembers(int id); /// /// Returns newly created for the current org. diff --git a/Octokit.Tests.Integration/Clients/TeamsClientTests.cs b/Octokit.Tests.Integration/Clients/TeamsClientTests.cs index 82acd4e348..720ed4e298 100644 --- a/Octokit.Tests.Integration/Clients/TeamsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/TeamsClientTests.cs @@ -142,7 +142,7 @@ public async Task GetsAllMembersWhenAuthenticated() var members = await github.Organization.Team.GetMembers(team.Id); - Assert.Contains(Helper.UserName, members.Select(u => u.Login)); + Assert.Contains(Helper.UserName, members.Select(u => u.Login)); } } } diff --git a/Octokit/Clients/ITeamsClient.cs b/Octokit/Clients/ITeamsClient.cs index 91b44aea10..8b9a11b77e 100644 --- a/Octokit/Clients/ITeamsClient.cs +++ b/Octokit/Clients/ITeamsClient.cs @@ -33,15 +33,15 @@ public interface ITeamsClient /// A list of the orgs's teams s. Task> GetAll(string org); - /// - /// Returns all members of the given team. - /// - /// The team identifier - /// - /// https://developer.github.com/v3/orgs/teams/#list-team-members - /// + /// + /// Returns all members of the given team. + /// + /// The team identifier + /// + /// https://developer.github.com/v3/orgs/teams/#list-team-members + /// /// A list of the team's member s. - Task> GetMembers(int id); + Task> GetMembers(int id); /// /// Returns newly created for the current org. diff --git a/Octokit/Clients/TeamsClient.cs b/Octokit/Clients/TeamsClient.cs index a2dcceabc5..31fd88c3fd 100644 --- a/Octokit/Clients/TeamsClient.cs +++ b/Octokit/Clients/TeamsClient.cs @@ -52,20 +52,20 @@ public Task> GetAll(string org) return ApiConnection.GetAll(endpoint); } - /// - /// Returns all members of the given team. - /// - /// The team identifier - /// - /// https://developer.github.com/v3/orgs/teams/#list-team-members - /// - /// A list of the team's member s. - public Task> GetMembers(int id) - { + /// + /// Returns all members of the given team. + /// + /// The team identifier + /// + /// https://developer.github.com/v3/orgs/teams/#list-team-members + /// + /// A list of the team's member s. + public Task> GetMembers(int id) + { var endpoint = ApiUrls.TeamMembers(id); return ApiConnection.GetAll(endpoint); - } + } /// /// Returns newly created for the current org. From 6b15848e58f5034d7f8b2b75b827b9f837cb07b6 Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Tue, 22 Apr 2014 18:03:40 -0300 Subject: [PATCH 3/3] Added tests for the observable teams client. --- .../Octokit.Tests.Integration.csproj | 3 +- .../Reactive/ObservableTeamsClientTests.cs | 43 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 Octokit.Tests.Integration/Reactive/ObservableTeamsClientTests.cs diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index dc62d36612..8ed7758e8c 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -92,6 +92,7 @@ + @@ -123,4 +124,4 @@ --> - + \ No newline at end of file diff --git a/Octokit.Tests.Integration/Reactive/ObservableTeamsClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableTeamsClientTests.cs new file mode 100644 index 0000000000..bed5daa4de --- /dev/null +++ b/Octokit.Tests.Integration/Reactive/ObservableTeamsClientTests.cs @@ -0,0 +1,43 @@ +using System.Linq; +using System.Net; +using System.Reactive.Linq; +using System.Threading.Tasks; +using Octokit; +using Octokit.Internal; +using Octokit.Tests.Helpers; +using Octokit.Tests.Integration; +using Xunit; +using System; +using System.Collections.Generic; +using Xunit.Sdk; +using Octokit.Reactive; + +public class ObservableTeamsClientTests +{ + public class TheGetMembersMethod + { + readonly Team team; + + public TheGetMembersMethod() + { + var github = new GitHubClient(new ProductHeaderValue("OctokitTests")) { Credentials = Helper.Credentials }; + + team = github.Organization.Team.GetAll(Helper.Organization).Result.First(); + } + + [OrganizationTest] + public async Task GetsAllMembersWhenAuthenticated() + { + var github = new GitHubClient(new ProductHeaderValue("OctokitTests")) + { + Credentials = Helper.Credentials + }; + + var client = new ObservableTeamsClient(github); + + var member = await client.GetMembers(team.Id); + + Assert.Equal(Helper.UserName, member.Login); + } + } +}