-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #855 from Red-Folder/master
Access to the last ApiInfo object
- Loading branch information
Showing
26 changed files
with
537 additions
and
8 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
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,83 @@ | ||
using Octokit; | ||
using Octokit.Tests.Integration; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
public class GitHubClientTests | ||
{ | ||
public class TheLastApiInfoProperty | ||
{ | ||
[IntegrationTest] | ||
public async Task CanRetrieveLastApiInfoWithEtag() | ||
{ | ||
// To check for etag, I'm using a new repository | ||
// As per suggestion here -> https://github.com/octokit/octokit.net/pull/855#issuecomment-126966532 | ||
var github = Helper.GetAuthenticatedClient(); | ||
var repoName = Helper.MakeNameWithTimestamp("public-repo"); | ||
|
||
var createdRepository = await github.Repository.Create(new NewRepository(repoName)); | ||
|
||
try | ||
{ | ||
var result = github.GetLastApiInfo(); | ||
|
||
Assert.True(result.Links.Count == 0); | ||
Assert.True(result.AcceptedOauthScopes.Count > -1); | ||
Assert.True(result.OauthScopes.Count > -1); | ||
Assert.False(String.IsNullOrEmpty(result.Etag)); | ||
Assert.True(result.RateLimit.Limit > 0); | ||
Assert.True(result.RateLimit.Remaining > -1); | ||
Assert.NotNull(result.RateLimit.Reset); | ||
} | ||
finally | ||
{ | ||
Helper.DeleteRepo(createdRepository); | ||
} | ||
} | ||
|
||
[IntegrationTest] | ||
public async Task CanRetrieveLastApiInfoWithLinks() | ||
{ | ||
// To check for links, I'm doing a list of all contributors to the octokit.net project | ||
// Adapted from suggestion here -> https://github.com/octokit/octokit.net/pull/855#issuecomment-126966532 | ||
var github = Helper.GetAuthenticatedClient(); | ||
|
||
await github.Repository.GetAllContributors("octokit", "octokit.net"); | ||
|
||
var result = github.GetLastApiInfo(); | ||
|
||
Assert.True(result.Links.Count > 0); | ||
Assert.True(result.AcceptedOauthScopes.Count > -1); | ||
Assert.True(result.OauthScopes.Count > -1); | ||
Assert.False(String.IsNullOrEmpty(result.Etag)); | ||
Assert.True(result.RateLimit.Limit > 0); | ||
Assert.True(result.RateLimit.Remaining > -1); | ||
Assert.NotNull(result.RateLimit.Reset); | ||
} | ||
|
||
[PersonalAccessTokenTest] | ||
public async Task CanRetrieveLastApiInfoAcceptedOauth() | ||
{ | ||
// To check for OAuth & AcceptedOAuth I'm getting the octokit user | ||
// Adapted from suggestion here -> https://github.com/octokit/octokit.net/pull/855#issuecomment-126966532 | ||
var github = Helper.GetAuthenticatedClient(); | ||
|
||
await github.User.Get("octokit"); | ||
|
||
var result = github.GetLastApiInfo(); | ||
|
||
Assert.True(result.Links.Count == 0); | ||
Assert.True(result.AcceptedOauthScopes.Count > 0); | ||
Assert.True(result.OauthScopes.Count > 0); | ||
Assert.False(String.IsNullOrEmpty(result.Etag)); | ||
Assert.True(result.RateLimit.Limit > 0); | ||
Assert.True(result.RateLimit.Remaining > -1); | ||
Assert.NotNull(result.RateLimit.Reset); | ||
} | ||
|
||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
Octokit.Tests.Integration/Helpers/PersonalAccessTokenTestAttribute.cs
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,30 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace Octokit.Tests.Integration | ||
{ | ||
public class PersonalAccessTokenTestDiscoverer : IXunitTestCaseDiscoverer | ||
{ | ||
readonly IMessageSink diagnosticMessageSink; | ||
|
||
public PersonalAccessTokenTestDiscoverer(IMessageSink diagnosticMessageSink) | ||
{ | ||
this.diagnosticMessageSink = diagnosticMessageSink; | ||
} | ||
|
||
public IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute) | ||
{ | ||
return Helper.IsUsingToken | ||
? new[] { new XunitTestCase(diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod) } | ||
: Enumerable.Empty<IXunitTestCase>(); | ||
} | ||
} | ||
|
||
[XunitTestCaseDiscoverer("Octokit.Tests.Integration.PersonalAccessTokenTestDiscoverer", "Octokit.Tests.Integration")] | ||
public class PersonalAccessTokenTestAttribute : FactAttribute | ||
{ | ||
} | ||
} |
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
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,100 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Octokit.Tests.Http | ||
{ | ||
public class ApiInfoTests | ||
{ | ||
public class TheMethods | ||
{ | ||
[Fact] | ||
public void CanClone() | ||
{ | ||
var original = new ApiInfo( | ||
new Dictionary<string, Uri> | ||
{ | ||
{ | ||
"next", | ||
new Uri("https://api.github.com/repos/rails/rails/issues?page=4&per_page=5") | ||
}, | ||
{ | ||
"last", | ||
new Uri("https://api.github.com/repos/rails/rails/issues?page=131&per_page=5") | ||
}, | ||
{ | ||
"first", | ||
new Uri("https://api.github.com/repos/rails/rails/issues?page=1&per_page=5") | ||
}, | ||
{ | ||
"prev", | ||
new Uri("https://api.github.com/repos/rails/rails/issues?page=2&per_page=5") | ||
} | ||
}, | ||
new List<string> | ||
{ | ||
"user", | ||
}, | ||
new List<string> | ||
{ | ||
"user", | ||
"public_repo", | ||
"repo", | ||
"gist" | ||
}, | ||
"5634b0b187fd2e91e3126a75006cc4fa", | ||
new RateLimit(100, 75, 1372700873) | ||
); | ||
|
||
var clone = original.Clone(); | ||
|
||
// Note the use of Assert.NotSame tests for value types - this should continue to test should the underlying | ||
// model are changed to Object types | ||
Assert.NotSame(original, clone); | ||
|
||
Assert.Equal(original.Etag, clone.Etag); | ||
Assert.NotSame(original.Etag, clone.Etag); | ||
|
||
Assert.Equal(original.AcceptedOauthScopes.Count, clone.AcceptedOauthScopes.Count); | ||
Assert.NotSame(original.AcceptedOauthScopes, clone.AcceptedOauthScopes); | ||
for (int i = 0; i < original.AcceptedOauthScopes.Count; i++) | ||
{ | ||
Assert.Equal(original.AcceptedOauthScopes[i], clone.AcceptedOauthScopes[i]); | ||
Assert.NotSame(original.AcceptedOauthScopes[i], clone.AcceptedOauthScopes[i]); | ||
} | ||
|
||
Assert.Equal(original.Links.Count, clone.Links.Count); | ||
Assert.NotSame(original.Links, clone.Links); | ||
for (int i = 0; i < original.Links.Count; i++) | ||
{ | ||
Assert.Equal(original.Links.Keys.ToArray()[i], clone.Links.Keys.ToArray()[i]); | ||
Assert.NotSame(original.Links.Keys.ToArray()[i], clone.Links.Keys.ToArray()[i]); | ||
Assert.Equal(original.Links.Values.ToArray()[i].ToString(), clone.Links.Values.ToArray()[i].ToString()); | ||
Assert.NotSame(original.Links.Values.ToArray()[i], clone.Links.Values.ToArray()[i]); | ||
} | ||
|
||
Assert.Equal(original.OauthScopes.Count, clone.OauthScopes.Count); | ||
Assert.NotSame(original.OauthScopes, clone.OauthScopes); | ||
for (int i = 0; i < original.OauthScopes.Count; i++) | ||
{ | ||
Assert.Equal(original.OauthScopes[i], clone.OauthScopes[i]); | ||
Assert.NotSame(original.OauthScopes[i], clone.OauthScopes[i]); | ||
} | ||
|
||
Assert.NotSame(original.RateLimit, clone.RateLimit); | ||
Assert.Equal(original.RateLimit.Limit, clone.RateLimit.Limit); | ||
Assert.NotSame(original.RateLimit.Limit, clone.RateLimit.Limit); | ||
Assert.Equal(original.RateLimit.Remaining, clone.RateLimit.Remaining); | ||
Assert.NotSame(original.RateLimit.Remaining, clone.RateLimit.Remaining); | ||
Assert.Equal(original.RateLimit.ResetAsUtcEpochSeconds, clone.RateLimit.ResetAsUtcEpochSeconds); | ||
Assert.NotSame(original.RateLimit.ResetAsUtcEpochSeconds, clone.RateLimit.ResetAsUtcEpochSeconds); | ||
Assert.Equal(original.RateLimit.Reset, clone.RateLimit.Reset); | ||
Assert.NotSame(original.RateLimit.Reset, clone.RateLimit.Reset); | ||
} | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.