Skip to content

Commit

Permalink
Merge pull request #466 from kzu/GetMembers
Browse files Browse the repository at this point in the history
Get members
  • Loading branch information
haacked committed Apr 22, 2014
2 parents 0e54ca8 + 6b15848 commit bad2aa4
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Octokit.Reactive/Clients/IObservableTeamsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ public interface IObservableTeamsClient
/// <returns>A list of the orgs's teams <see cref="Team"/>s.</returns>
IObservable<Team> GetAll(string org);

/// <summary>
/// Returns all members of the given team.
/// </summary>
/// <param name="id">The team identifier</param>
/// <remarks>
/// https://developer.github.com/v3/orgs/teams/#list-team-members
/// </remarks>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A list of the team's member <see cref="User"/>s.</returns>
IObservable<User> GetMembers(int id);

/// <summary>
/// Returns newly created <see cref="Team" /> for the current org.
/// </summary>
Expand Down
14 changes: 14 additions & 0 deletions Octokit.Reactive/Clients/ObservableTeamsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ public IObservable<Team> GetAll(string org)
return _connection.GetAndFlattenAllPages<Team>(ApiUrls.OrganizationTeams(org));
}

/// <summary>
/// Returns all members of the given team.
/// </summary>
/// <param name="id">The team identifier</param>
/// <remarks>
/// https://developer.github.com/v3/orgs/teams/#list-team-members
/// </remarks>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A list of the team's member <see cref="User"/>s.</returns>
public IObservable<User> GetMembers(int id)
{
return _connection.GetAndFlattenAllPages<User>(ApiUrls.TeamMembers(id));
}

/// <summary>
/// Returns newly created <see cref="Team" /> for the current org.
/// </summary>
Expand Down
25 changes: 25 additions & 0 deletions Octokit.Tests.Integration/Clients/TeamsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
3 changes: 2 additions & 1 deletion Octokit.Tests.Integration/Octokit.Tests.Integration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<Compile Include="Helper.cs" />
<Compile Include="Clients\UsersClientTests.cs" />
<Compile Include="Reactive\ObservableUserEmailsClientTests.cs" />
<Compile Include="Reactive\ObservableTeamsClientTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Octokit.Reactive\Octokit.Reactive.csproj">
Expand Down Expand Up @@ -123,4 +124,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
43 changes: 43 additions & 0 deletions Octokit.Tests.Integration/Reactive/ObservableTeamsClientTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
14 changes: 14 additions & 0 deletions Octokit.Tests/Clients/TeamsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ public void EnsuresNonNullArguments()
}
}

public class TheGetMembersMethod
{
[Fact]
public void RequestsTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new TeamsClient(connection);

client.GetMembers(1);

connection.Received().GetAll<User>(Arg.Is<Uri>(u => u.ToString() == "teams/1/members"));
}
}

public class TheCreateTeamMethod
{
[Fact]
Expand Down
10 changes: 10 additions & 0 deletions Octokit/Clients/ITeamsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ public interface ITeamsClient
/// <returns>A list of the orgs's teams <see cref="Team"/>s.</returns>
Task<IReadOnlyList<Team>> GetAll(string org);

/// <summary>
/// Returns all members of the given team.
/// </summary>
/// <param name="id">The team identifier</param>
/// <remarks>
/// https://developer.github.com/v3/orgs/teams/#list-team-members
/// </remarks>
/// <returns>A list of the team's member <see cref="User"/>s.</returns>
Task<IReadOnlyList<User>> GetMembers(int id);

/// <summary>
/// Returns newly created <see cref="Team" /> for the current org.
/// </summary>
Expand Down
14 changes: 14 additions & 0 deletions Octokit/Clients/TeamsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ public Task<IReadOnlyList<Team>> GetAll(string org)
return ApiConnection.GetAll<Team>(endpoint);
}

/// <summary>
/// Returns all members of the given team.
/// </summary>
/// <param name="id">The team identifier</param>
/// <remarks>
/// https://developer.github.com/v3/orgs/teams/#list-team-members
/// </remarks>
/// <returns>A list of the team's member <see cref="User"/>s.</returns>
public Task<IReadOnlyList<User>> GetMembers(int id)
{
var endpoint = ApiUrls.TeamMembers(id);

return ApiConnection.GetAll<User>(endpoint);
}

/// <summary>
/// Returns newly created <see cref="Team" /> for the current org.
Expand Down
11 changes: 10 additions & 1 deletion Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ public static Uri Teams(int id)
}

/// <summary>
/// returns the <see cref="Uri"/> for team members
/// returns the <see cref="Uri"/> for team member
/// </summary>
/// <param name="id">The team id</param>
/// <param name="login">The user login.</param>
Expand All @@ -955,6 +955,15 @@ public static Uri TeamMember(int id, string login)
return "teams/{0}/members/{1}".FormatUri(id, login);
}

/// <summary>
/// returns the <see cref="Uri"/> for team members list
/// </summary>
/// <param name="id">The team id</param>
public static Uri TeamMembers(int id)
{
return "teams/{0}/members".FormatUri(id);
}

/// <summary>
/// returns the <see cref="Uri"/> for teams
/// use for update or deleting a team
Expand Down

0 comments on commit bad2aa4

Please sign in to comment.