Skip to content

Commit

Permalink
Merge pull request #1063 from octokit/remove-trivial-extension-methods
Browse files Browse the repository at this point in the history
remove Get<T> extension method to make tests more clear
  • Loading branch information
haacked committed Jan 26, 2016
2 parents 0c4fff0 + 46d9e1f commit 615b690
Show file tree
Hide file tree
Showing 26 changed files with 53 additions and 58 deletions.
3 changes: 1 addition & 2 deletions Octokit.Tests/Clients/BlobClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public void RequestsCorrectUrl()

client.Get("fake", "repo", "123456ABCD");

connection.Received().Get<Blob>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/git/blobs/123456ABCD"),
null);
connection.Received().Get<Blob>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/git/blobs/123456ABCD"));
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion Octokit.Tests/Clients/CommitStatusClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void RequestsCorrectUrl()
client.GetCombined("fake", "repo", "sha");

connection.Received()
.Get<CombinedCommitStatus>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/commits/sha/status"), null);
.Get<CombinedCommitStatus>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/commits/sha/status"));
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion Octokit.Tests/Clients/CommitsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void RequestsCorrectUrl()

client.Get("owner", "repo", "reference");

connection.Received().Get<Commit>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/git/commits/reference"), null);
connection.Received().Get<Commit>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/git/commits/reference"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion Octokit.Tests/Clients/FeedsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void RequestsCorrectUrl()

feedsClient.GetFeeds();

connection.Received().Get<Feed>(Arg.Is<Uri>(u => u.ToString() == "feeds"), null);
connection.Received().Get<Feed>(Arg.Is<Uri>(u => u.ToString() == "feeds"));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Octokit.Tests/Clients/GistCommentsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task RequestsCorrectUrl()

await client.Get("24", 1337);

connection.Received().Get<GistComment>(Arg.Is<Uri>(u => u.ToString() == "gists/24/comments/1337"), null);
connection.Received().Get<GistComment>(Arg.Is<Uri>(u => u.ToString() == "gists/24/comments/1337"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion Octokit.Tests/Clients/GistsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void RequestsCorrectUrl()

client.Get("1");

connection.Received().Get<Gist>(Arg.Is<Uri>(u => u.ToString() == "gists/1"), null);
connection.Received().Get<Gist>(Arg.Is<Uri>(u => u.ToString() == "gists/1"));
}
}

Expand Down
3 changes: 1 addition & 2 deletions Octokit.Tests/Clients/IssueCommentsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public void RequestsCorrectUrl()

client.Get("fake", "repo", 42);

connection.Received().Get<IssueComment>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/comments/42"),
null);
connection.Received().Get<IssueComment>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/comments/42"));
}

[Fact]
Expand Down
3 changes: 1 addition & 2 deletions Octokit.Tests/Clients/IssuesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public void RequestsCorrectUrl()

client.Get("fake", "repo", 42);

connection.Received().Get<Issue>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42"),
null);
connection.Received().Get<Issue>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42"));
}

[Fact]
Expand Down
3 changes: 1 addition & 2 deletions Octokit.Tests/Clients/IssuesEventsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ public void RequestsCorrectUrl()

client.Get("fake", "repo", 42);

connection.Received().Get<IssueEvent>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/events/42"),
null);
connection.Received().Get<IssueEvent>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/events/42"));
}

[Fact]
Expand Down
3 changes: 1 addition & 2 deletions Octokit.Tests/Clients/IssuesLabelsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public void RequestsCorrectUrl()

client.Get("fake", "repo", "label");

connection.Received().Get<Label>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/labels/label"),
null);
connection.Received().Get<Label>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/labels/label"));
}

[Fact]
Expand Down
3 changes: 1 addition & 2 deletions Octokit.Tests/Clients/MilestonesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public void RequestsCorrectUrl()

client.Get("fake", "repo", 42);

connection.Received().Get<Milestone>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/milestones/42"),
null);
connection.Received().Get<Milestone>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/milestones/42"));
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion Octokit.Tests/Clients/OrganizationsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void RequestsCorrectUrl()

orgsClient.Get("orgName");

client.Received().Get<Organization>(Arg.Is<Uri>(u => u.ToString() == "orgs/orgName"), null);
client.Received().Get<Organization>(Arg.Is<Uri>(u => u.ToString() == "orgs/orgName"));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ public void RequestsCorrectUrl()

client.GetComment("fakeOwner", "fakeRepoName", 53);

connection.Received().Get<PullRequestReviewComment>(Arg.Is<Uri>(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/comments/53"),
null);
connection.Received().Get<PullRequestReviewComment>(Arg.Is<Uri>(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/comments/53"));
}

[Fact]
Expand Down
3 changes: 1 addition & 2 deletions Octokit.Tests/Clients/PullRequestsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public void RequestsCorrectUrl()

client.Get("fake", "repo", 42);

connection.Received().Get<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pulls/42"),
null);
connection.Received().Get<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pulls/42"));
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion Octokit.Tests/Clients/ReferencesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task RequestsCorrectUrl()

await client.Get("owner", "repo", "heads/develop");

connection.Received().Get<Reference>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/git/refs/heads/develop"), null);
connection.Received().Get<Reference>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/git/refs/heads/develop"));
}
}

Expand Down
5 changes: 2 additions & 3 deletions Octokit.Tests/Clients/ReleasesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public void RequestsTheCorrectUrl()

client.Get("fake", "repo", 1);

connection.Received().Get<Release>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/releases/1"),
null);
connection.Received().Get<Release>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/releases/1"));
}

[Fact]
Expand Down Expand Up @@ -228,7 +227,7 @@ public void RequestsTheCorrectUrl()

client.GetAsset("fake", "repo", 1);

connection.Received().Get<ReleaseAsset>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/releases/assets/1"), null);
connection.Received().Get<ReleaseAsset>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/releases/assets/1"));
}

[Fact]
Expand Down
10 changes: 5 additions & 5 deletions Octokit.Tests/Clients/RepositoriesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public void RequestsCorrectUrl()

client.Get("fake", "repo");

connection.Received().Get<Repository>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo"), null);
connection.Received().Get<Repository>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo"));
}

[Fact]
Expand Down Expand Up @@ -487,7 +487,7 @@ public void GetsCorrectUrl()
client.GetAllLanguages("owner", "name");

connection.Received()
.Get<Dictionary<string, long>>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/languages"), null);
.Get<Dictionary<string, long>>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/languages"));
}

[Fact]
Expand Down Expand Up @@ -641,7 +641,7 @@ public void GetsCorrectUrl()
client.Compare("owner", "repo", "base", "head");

connection.Received()
.Get<CompareResult>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/compare/base...head"), null);
.Get<CompareResult>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/compare/base...head"));
}

[Fact]
Expand All @@ -654,7 +654,7 @@ public void EncodesUrl()
client.Compare("owner", "repo", "base", "shiftkey/my-cool-branch");

connection.Received()
.Get<CompareResult>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/compare/base...shiftkey%2Fmy-cool-branch"), null);
.Get<CompareResult>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/compare/base...shiftkey%2Fmy-cool-branch"));
}
}

Expand Down Expand Up @@ -684,7 +684,7 @@ public void GetsCorrectUrl()
client.Get("owner", "name", "reference");

connection.Received()
.Get<GitHubCommit>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/commits/reference"), null);
.Get<GitHubCommit>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/commits/reference"));
}
}

Expand Down
3 changes: 1 addition & 2 deletions Octokit.Tests/Clients/RepositoryCommentsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public void RequestsCorrectUrl()

client.Get("fake", "repo", 42);

connection.Received().Get<CommitComment>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/comments/42"),
null);
connection.Received().Get<CommitComment>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/comments/42"));
}

[Fact]
Expand Down
3 changes: 1 addition & 2 deletions Octokit.Tests/Clients/RepositoryDeployKeysClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public void GetsADeployKey()

deployKeysClient.Get("user", "repo", 42);

apiConnection.Received().Get<DeployKey>(Arg.Is<Uri>(u => u.ToString() == "repos/user/repo/keys/42"),
null);
apiConnection.Received().Get<DeployKey>(Arg.Is<Uri>(u => u.ToString() == "repos/user/repo/keys/42"));
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion Octokit.Tests/Clients/RepositoryHooksClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void RequestsCorrectUrl()

client.Hooks.Get("fake", "repo", 12345678);

connection.Received().Get<RepositoryHook>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/hooks/12345678"), null);
connection.Received().Get<RepositoryHook>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/hooks/12345678"));
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion Octokit.Tests/Clients/TagsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void RequestsCorrectUrl()

client.Get("owner", "repo", "reference");

connection.Received().Get<GitTag>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/git/tags/reference"), null);
connection.Received().Get<GitTag>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/git/tags/reference"));
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion Octokit.Tests/Clients/TeamsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void RequestsTheCorrectlUrl()

client.Get(1);

connection.Received().Get<Team>(Arg.Is<Uri>(u => u.ToString() == "teams/1"), null);
connection.Received().Get<Team>(Arg.Is<Uri>(u => u.ToString() == "teams/1"));
}
}

Expand Down
6 changes: 2 additions & 4 deletions Octokit.Tests/Clients/TreesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public void RequestsCorrectUrl()

client.Get("fake", "repo", "123456ABCD");

connection.Received().Get<TreeResponse>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/git/trees/123456ABCD"),
null);
connection.Received().Get<TreeResponse>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/git/trees/123456ABCD"));
}

[Fact]
Expand All @@ -49,8 +48,7 @@ public void RequestsCorrectUrl()

client.GetRecursive("fake", "repo", "123456ABCD");

connection.Received().Get<TreeResponse>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/git/trees/123456ABCD?recursive=1"),
null);
connection.Received().Get<TreeResponse>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/git/trees/123456ABCD?recursive=1"));
}

[Fact]
Expand Down
16 changes: 0 additions & 16 deletions Octokit/Helpers/ApiExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,6 @@ namespace Octokit
/// </summary>
public static class ApiExtensions
{
/// <summary>
/// Gets the API resource at the specified URI.
/// </summary>
/// <typeparam name="T">Type of the API resource to get.</typeparam>
/// <param name="connection">The connection to use</param>
/// <param name="uri">URI of the API resource to get</param>
/// <returns>The API resource.</returns>
/// <exception cref="ApiException">Thrown when an API error occurs.</exception>
public static Task<T> Get<T>(this IApiConnection connection, Uri uri)
{
Ensure.ArgumentNotNull(connection, "connection");
Ensure.ArgumentNotNull(uri, "uri");

return connection.Get<T>(uri, null);
}

/// <summary>
/// Gets all API resources in the list at the specified URI.
/// </summary>
Expand Down
14 changes: 14 additions & 0 deletions Octokit/Http/ApiConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ protected ApiConnection(IConnection connection, IApiPagination pagination)
/// </summary>
public IConnection Connection { get; private set; }

/// <summary>
/// Gets the API resource at the specified URI.
/// </summary>
/// <typeparam name="T">Type of the API resource to get.</typeparam>
/// <param name="uri">URI of the API resource to get</param>
/// <returns>The API resource.</returns>
/// <exception cref="ApiException">Thrown when an API error occurs.</exception>
public Task<T> Get<T>(Uri uri)
{
Ensure.ArgumentNotNull(uri, "uri");

return Get<T>(uri, null);
}

/// <summary>
/// Gets the API resource at the specified URI.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions Octokit/Http/IApiConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ public interface IApiConnection
/// </summary>
IConnection Connection { get; }

/// <summary>
/// Gets the API resource at the specified URI.
/// </summary>
/// <typeparam name="T">Type of the API resource to get.</typeparam>
/// <param name="uri">URI of the API resource to get</param>
/// <returns>The API resource.</returns>
/// <exception cref="ApiException">Thrown when an API error occurs.</exception>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
Task<T> Get<T>(Uri uri);

/// <summary>
/// Gets the API resource at the specified URI.
/// </summary>
Expand Down

0 comments on commit 615b690

Please sign in to comment.