mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-07 20:30:41 +00:00
Added further integration tests for LastApiInfo
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -102,6 +102,7 @@
|
||||
<Compile Include="fixtures\RepositoriesHooksCollection.cs" />
|
||||
<Compile Include="fixtures\RepositoriesHooksFixture.cs" />
|
||||
<Compile Include="Helpers\ApplicationTestAttribute.cs" />
|
||||
<Compile Include="Helpers\PersonalAccessTokenTestAttribute.cs" />
|
||||
<Compile Include="Helpers\PaidAccountTestAttribute.cs" />
|
||||
<Compile Include="Helpers\RepositorySetupHelper.cs" />
|
||||
<Compile Include="HttpClientAdapterTests.cs" />
|
||||
|
||||
Reference in New Issue
Block a user