diff --git a/Octokit.Tests.Integration/AutoCompleteClientTests.cs b/Octokit.Tests.Integration/AutoCompleteClientTests.cs
index 9b32b1ab..26197315 100644
--- a/Octokit.Tests.Integration/AutoCompleteClientTests.cs
+++ b/Octokit.Tests.Integration/AutoCompleteClientTests.cs
@@ -1,6 +1,5 @@
using System.Threading.Tasks;
using FluentAssertions;
-using Octokit.Http;
using Xunit;
namespace Octokit.Tests.Integration
@@ -9,12 +8,12 @@ namespace Octokit.Tests.Integration
{
public class TheGetEmojisMethod
{
- [Fact]
+ [IntegrationTest]
public async Task GetsAllTheEmojis()
{
var github = new GitHubClient
{
- Credentials = new Credentials("xapitestaccountx", "octocat11")
+ Credentials = AutomationSettings.Current.GitHubCredentials
};
var emojis = await github.AutoComplete.GetEmojis();
diff --git a/Octokit.Tests.Integration/AutomationSettings.cs b/Octokit.Tests.Integration/AutomationSettings.cs
new file mode 100644
index 00000000..fca5ac97
--- /dev/null
+++ b/Octokit.Tests.Integration/AutomationSettings.cs
@@ -0,0 +1,61 @@
+using System;
+using Octokit.Http;
+
+namespace Octokit.Tests.Integration
+{
+ ///
+ /// Settings for executing automated tests.
+ ///
+ public class AutomationSettings
+ {
+ static readonly Lazy automationSettingsThunk = new Lazy(() =>
+ {
+ var githubUsername = Environment.GetEnvironmentVariable("OCTOKIT_GITHUBUSERNAME");
+ var githubPassword = Environment.GetEnvironmentVariable("OCTOKIT_GITHUBPASSWORD");
+
+ return new AutomationSettings(githubUsername, githubPassword);
+ });
+
+ ///
+ /// The current automation settings.
+ ///
+ public static AutomationSettings Current
+ {
+ get
+ {
+ return automationSettingsThunk.Value;
+ }
+ }
+
+ ///
+ /// Creates a new instance of settings for executing automated tests.
+ ///
+ /// Username of a GitHub test account (DO NOT USE A "REAL" ACCOUNT)
+ /// Password for a GitHub test account (DO NOT USE A "REAL" ACCOUNT)
+ public AutomationSettings(string githubUsername, string githubPassword)
+ {
+ GitHubUsername = githubUsername;
+ GitHubPassword = githubPassword;
+
+ if (GitHubUsername != null && GitHubPassword != null)
+ GitHubCredentials = new Credentials(
+ GitHubUsername,
+ GitHubPassword);
+ }
+
+ ///
+ /// for a GitHub test account (DO NOT USE A "REAL" ACCOUNT).
+ ///
+ public Credentials GitHubCredentials { get; private set; }
+
+ ///
+ /// Password for a GitHub test account (DO NOT USE A "REAL" ACCOUNT).
+ ///
+ public string GitHubPassword { get; private set; }
+
+ ///
+ /// Username of a GitHub test account (DO NOT USE A "REAL" ACCOUNT).
+ ///
+ public string GitHubUsername { get; private set; }
+ }
+}
diff --git a/Octokit.Tests.Integration/IntegrationTestAttribute.cs b/Octokit.Tests.Integration/IntegrationTestAttribute.cs
new file mode 100644
index 00000000..a86d957a
--- /dev/null
+++ b/Octokit.Tests.Integration/IntegrationTestAttribute.cs
@@ -0,0 +1,17 @@
+using System.Collections.Generic;
+using Xunit;
+using Xunit.Sdk;
+
+namespace Octokit.Tests.Integration
+{
+ public class IntegrationTestAttribute : FactAttribute
+ {
+ protected override IEnumerable EnumerateTestCommands(IMethodInfo testMethod)
+ {
+ if (AutomationSettings.Current.GitHubCredentials == null)
+ yield return new SkipCommand(testMethod, MethodUtility.GetDisplayName(testMethod), "Automation settings not configured. Please set the OCTOKIT_GITHUBUSERNAME and OCTOKIT_GITHUBPASSWORD environment variables to a GitHub test account (i.e, DO NOT USE A \"REAL\" ACCOUNT).");
+ else
+ yield return new FactCommand(testMethod);
+ }
+ }
+}
diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj
index 68b7cf4f..6d4f7ffb 100644
--- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj
+++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj
@@ -50,6 +50,8 @@
+
+
diff --git a/Octokit.Tests.Integration/RepositoriesClientTests.cs b/Octokit.Tests.Integration/RepositoriesClientTests.cs
index 7c8c5aed..21110194 100644
--- a/Octokit.Tests.Integration/RepositoriesClientTests.cs
+++ b/Octokit.Tests.Integration/RepositoriesClientTests.cs
@@ -1,6 +1,5 @@
using System.Threading.Tasks;
using FluentAssertions;
-using Octokit.Http;
using Xunit;
namespace Octokit.Tests.Integration
@@ -9,12 +8,12 @@ namespace Octokit.Tests.Integration
{
public class TheGetAsyncMethod
{
- [Fact]
+ [IntegrationTest]
public async Task ReturnsSpecifiedUser()
{
var github = new GitHubClient
{
- Credentials = new Credentials("xapitestaccountx", "octocat11")
+ Credentials = AutomationSettings.Current.GitHubCredentials
};
var repository = await github.Repository.Get("ReactiveCocoa", "ReactiveCocoa");
@@ -25,12 +24,12 @@ namespace Octokit.Tests.Integration
public class TheGetAllForOrgMethod
{
- [Fact]
+ [IntegrationTest]
public async Task ReturnsAllRepositoriesForOrganization()
{
var github = new GitHubClient
{
- Credentials = new Credentials("xapitestaccountx", "octocat11")
+ Credentials = AutomationSettings.Current.GitHubCredentials
};
var repositories = await github.Repository.GetAllForOrg("github");
@@ -41,12 +40,12 @@ namespace Octokit.Tests.Integration
public class TheGetReadmeMethod
{
- [Fact]
+ [IntegrationTest]
public async Task ReturnsReadmeForOctokit()
{
var github = new GitHubClient
{
- Credentials = new Credentials("xapitestaccountx", "octocat11")
+ Credentials = AutomationSettings.Current.GitHubCredentials
};
// TODO: Change this to request github/Octokit.net once we make this OSS.
diff --git a/Octokit.Tests.Integration/UsersClientTests.cs b/Octokit.Tests.Integration/UsersClientTests.cs
index ec441011..b06c517c 100644
--- a/Octokit.Tests.Integration/UsersClientTests.cs
+++ b/Octokit.Tests.Integration/UsersClientTests.cs
@@ -1,6 +1,4 @@
-using System;
-using System.Net;
-using System.Net.Http;
+using System.Net;
using System.Threading.Tasks;
using FluentAssertions;
using Octokit.Http;
@@ -13,12 +11,12 @@ namespace Octokit.Tests.Integration
{
public class TheGetMethod
{
- [Fact]
+ [IntegrationTest]
public async Task ReturnsSpecifiedUser()
{
var github = new GitHubClient
{
- Credentials = new Credentials("xapitestaccountx", "octocat11")
+ Credentials = AutomationSettings.Current.GitHubCredentials
};
// Get a user by username
@@ -30,29 +28,29 @@ namespace Octokit.Tests.Integration
public class TheCurrentMethod
{
- [Fact]
+ [IntegrationTest]
public async Task ReturnsSpecifiedUser()
{
var github = new GitHubClient
{
- Credentials = new Credentials("xapitestaccountx", "octocat11")
+ Credentials = AutomationSettings.Current.GitHubCredentials
};
var user = await github.User.Current();
- user.Login.Should().Be("xapitestaccountx");
+ user.Login.Should().Be(AutomationSettings.Current.GitHubUsername);
}
}
public class TheUpdateMethod
{
- [Fact]
+ [IntegrationTest]
public async Task FailsWhenNotAuthenticated()
{
var github = new GitHubClient();
var userUpdate = new UserUpdate
- {
- Name = "xapitestaccountx",
+ {
+ Name = AutomationSettings.Current.GitHubUsername,
Bio = "UPDATED BIO"
};
@@ -61,16 +59,16 @@ namespace Octokit.Tests.Integration
e.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
}
- [Fact]
+ [IntegrationTest]
public async Task FailsWhenAuthenticatedWithBadCredentials()
{
var github = new GitHubClient
{
- Credentials = new Credentials("xapitestaccountx", "bad-password")
+ Credentials = new Credentials(AutomationSettings.Current.GitHubUsername, "bad-password")
};
var userUpdate = new UserUpdate
- {
- Name = "xapitestaccountx",
+ {
+ Name = AutomationSettings.Current.GitHubUsername,
Bio = "UPDATED BIO"
};
diff --git a/Octokit.msbuild b/Octokit.msbuild
index e16c92ab..2b40f814 100644
--- a/Octokit.msbuild
+++ b/Octokit.msbuild
@@ -17,9 +17,15 @@
-
+
+
+
+
+
+
+
diff --git a/README.md b/README.md
index b9d1a761..8f970c77 100644
--- a/README.md
+++ b/README.md
@@ -38,6 +38,18 @@ cd Octokit
.\build.cmd
```
+## Integration Tests
+
+Octokit has integration tests that access the GitHub API, but they must be configured before they will be executed.
+To configure the tests, create a test GitHub account (i.e., **don't use your real GitHub account**) and then set
+the following two environment variables:
+
+- `OCTOKIT_GITHUBUSERNAME` (set this to the test account's username)
+- `OCTOKIT_GITHUBPASSWORD` (set this to the test account's password)
+
+Once both of these are set, the integration tests will be executed both when running the `FullBuild` MSBuild target,
+and when running the `Octokit.Tests.Integration` assembly through an xUnit.net-friendly test runner.
+
## Problems?
Octokit is 100% certified to be bug free. If you find an issue with our