diff --git a/Octokit.Tests.Integration/Clients/GitHubClientTests.cs b/Octokit.Tests.Integration/Clients/GitHubClientTests.cs index 14ca8894..9ce45f8b 100644 --- a/Octokit.Tests.Integration/Clients/GitHubClientTests.cs +++ b/Octokit.Tests.Integration/Clients/GitHubClientTests.cs @@ -1,4 +1,5 @@ -using Octokit.Tests.Integration; +using Octokit; +using Octokit.Tests.Integration; using System; using System.Collections.Generic; using System.Linq; @@ -11,22 +12,72 @@ public class GitHubClientTests public class TheLastApiInfoProperty { [IntegrationTest] - public async Task CanRetrieveLastApiInfo() + 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.LastApiInfo; + + 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(); - // Doesn't matter which API gets called - await github.Miscellaneous.GetRateLimits(); + await github.Repository.GetAllContributors("octokit", "octokit.net"); var result = github.LastApiInfo; - //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.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.LastApiInfo; + + 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); + } + } } diff --git a/Octokit.Tests.Integration/Helper.cs b/Octokit.Tests.Integration/Helper.cs index 69596520..8e623528 100644 --- a/Octokit.Tests.Integration/Helper.cs +++ b/Octokit.Tests.Integration/Helper.cs @@ -12,7 +12,7 @@ namespace Octokit.Tests.Integration var githubUsername = Environment.GetEnvironmentVariable("OCTOKIT_GITHUBUSERNAME"); UserName = githubUsername; Organization = Environment.GetEnvironmentVariable("OCTOKIT_GITHUBORGANIZATION"); - + var githubToken = Environment.GetEnvironmentVariable("OCTOKIT_OAUTHTOKEN"); if (githubToken != null) @@ -52,6 +52,14 @@ namespace Octokit.Tests.Integration public static Credentials ApplicationCredentials { get { return _oauthApplicationCredentials.Value; } } + public static bool IsUsingToken + { + get + { + return !String.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("OCTOKIT_OAUTHTOKEN")); + } + } + public static bool IsPaidAccount { get diff --git a/Octokit.Tests.Integration/Helpers/PersonalAccessTokenTestAttribute.cs b/Octokit.Tests.Integration/Helpers/PersonalAccessTokenTestAttribute.cs new file mode 100644 index 00000000..0fd107ec --- /dev/null +++ b/Octokit.Tests.Integration/Helpers/PersonalAccessTokenTestAttribute.cs @@ -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 Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute) + { + return Helper.IsUsingToken + ? new[] { new XunitTestCase(diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod) } + : Enumerable.Empty(); + } + } + + [XunitTestCaseDiscoverer("Octokit.Tests.Integration.PersonalAccessTokenTestDiscoverer", "Octokit.Tests.Integration")] + public class PersonalAccessTokenTestAttribute : FactAttribute + { + } +} diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 45b1fb1e..f6154d28 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -102,6 +102,7 @@ +