forked from octokit/octokit.net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
169 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using NSubstitute; | ||
using Octokit.Tests.Helpers; | ||
using Xunit; | ||
|
||
namespace Octokit.Tests.Clients | ||
{ | ||
/// <summary> | ||
/// Client tests mostly just need to make sure they call the IApiConnection with the correct | ||
/// relative Uri. No need to fake up the response. All *those* tests are in ApiConnectionTests.cs. | ||
/// </summary> | ||
public class TeamsClientTests | ||
{ | ||
public class TheConstructor | ||
{ | ||
[Fact] | ||
public void EnsuresNonNullArguments() | ||
{ | ||
Assert.Throws<ArgumentNullException>(() => new TeamsClient(null)); | ||
} | ||
} | ||
|
||
public class TheGetAllMethod | ||
{ | ||
[Fact] | ||
public void RequestsTheCorrectUrl() | ||
{ | ||
var client = Substitute.For<IApiConnection>(); | ||
var orgs = new TeamsClient(client); | ||
|
||
orgs.GetAllTeams("username"); | ||
|
||
client.Received().GetAll<Team>(Arg.Is<Uri>(u => u.ToString() == "users/username/orgs")); | ||
} | ||
|
||
[Fact] | ||
public async Task EnsuresNonNullArguments() | ||
{ | ||
var teams = new TeamsClient(Substitute.For<IApiConnection>()); | ||
|
||
AssertEx.Throws<ArgumentNullException>(async () => await teams.GetAllTeams(null)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#if NET_45 | ||
using System.Collections.Generic; | ||
#endif | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Threading.Tasks; | ||
|
||
namespace Octokit | ||
{ | ||
/// <summary> | ||
/// A client for GitHub's Org Teams API. | ||
/// </summary> | ||
/// <remarks> | ||
/// See the <a href="http://developer.github.com/v3/orgs/teams/">Orgs API documentation</a> for more information. | ||
/// </remarks> | ||
public interface ITeamsClient | ||
{ | ||
/// <summary> | ||
/// Returns all <see cref="Team" />s for the current org. | ||
/// </summary> | ||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception> | ||
/// <returns>A list of the orgs's teams <see cref="Team"/>s.</returns> | ||
Task<IReadOnlyList<Team>> GetAllTeams(string org); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#if NET_45 | ||
using System.Collections.Generic; | ||
#endif | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Threading.Tasks; | ||
|
||
namespace Octokit | ||
{ | ||
|
||
/// <summary> | ||
/// A client for GitHub's Org Teams API. | ||
/// </summary> | ||
/// <remarks> | ||
/// See the <a href="http://developer.github.com/v3/orgs/teams/">Orgs API documentation</a> for more information. | ||
/// </remarks> | ||
public class TeamsClient : ApiClient, ITeamsClient | ||
{ | ||
/// <summary> | ||
/// Initializes a new GitHub Orgs Team API client. | ||
/// </summary> | ||
/// <param name="apiConnection">An API connection.</param> | ||
public TeamsClient(IApiConnection apiConnection) | ||
: base(apiConnection) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Returns all <see cref="Team" />s for the current org. | ||
/// </summary> | ||
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception> | ||
/// <returns>A list of the orgs's teams <see cref="Team"/>s.</returns> | ||
public Task<IReadOnlyList<Team>> GetAllTeams(string org) | ||
{ | ||
Ensure.ArgumentNotNullOrEmptyString(org, "org"); | ||
|
||
var endpoint = "orgs/{0}/teams".FormatUri(org); | ||
|
||
return ApiConnection.GetAll<Team>(endpoint); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Globalization; | ||
|
||
namespace Octokit | ||
{ | ||
public enum Permission | ||
{ | ||
/// <summary> | ||
/// team members can pull, push and administer these repositories. | ||
/// </summary> | ||
Admin, | ||
|
||
/// <summary> | ||
/// team members can pull and push, but not administer these repositories | ||
/// </summary> | ||
Push, | ||
|
||
/// <summary> | ||
/// team members can pull, but not push to or administer these repositories | ||
/// </summary> | ||
Pull | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Globalization; | ||
|
||
namespace Octokit | ||
{ | ||
/// <summary> | ||
/// organization teams | ||
/// </summary> | ||
public class Team | ||
{ | ||
/// <summary> | ||
/// team id | ||
/// </summary> | ||
public int Id { get; set; } | ||
|
||
/// <summary> | ||
/// team name | ||
/// </summary> | ||
public string Name { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters