Added integration tests for new methods on...

RepositoriesClient
This commit is contained in:
Peter MacNaughton
2014-02-10 00:19:11 -07:00
parent d12a609b33
commit 8b30dcf70d
@@ -1,4 +1,6 @@
using System.Net.Http.Headers;
using System;
using System.Linq;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Octokit;
using Octokit.Tests.Integration;
@@ -299,6 +301,116 @@ public class RepositoriesClientTests
// TODO: Add a test for the team_id param once an overload that takes an oranization is added
}
private static IGitHubClient CreateGitHubClient()
{
return new GitHubClient(new ProductHeaderValue("OctokitTests"))
{
Credentials = Helper.Credentials
};
}
public class TheEditMethod : IDisposable
{
Repository _repository;
[IntegrationTest]
public async Task UpdatesName()
{
var github = CreateGitHubClient();
var repoName = Helper.MakeNameWithTimestamp("public-repo");
_repository = await github.Repository.Create(new NewRepository { Name = repoName, AutoInit = true });
var updatedName = Helper.MakeNameWithTimestamp("updated-repo");
var update = new RepositoryUpdate { Name = updatedName };
_repository = await github.Repository.Edit(Helper.UserName, repoName, update);
Assert.Equal(update.Name, _repository.Name);
}
[IntegrationTest]
public async Task UpdatesDescription()
{
var github = CreateGitHubClient();
var repoName = Helper.MakeNameWithTimestamp("public-repo");
_repository = await github.Repository.Create(new NewRepository { Name = repoName, AutoInit = true });
var update = new RepositoryUpdate { Name = repoName, Description = "Updated description" };
_repository = await github.Repository.Edit(Helper.UserName, repoName, update);
Assert.Equal("Updated description", _repository.Description);
}
[IntegrationTest]
public async Task UpdatesHomepage()
{
var github = CreateGitHubClient();
var repoName = Helper.MakeNameWithTimestamp("public-repo");
_repository = await github.Repository.Create(new NewRepository { Name = repoName, AutoInit = true });
var update = new RepositoryUpdate { Name = repoName, Homepage = "http://aUrl.to/nowhere" };
_repository = await github.Repository.Edit(Helper.UserName, repoName, update);
Assert.Equal("http://aUrl.to/nowhere", _repository.Homepage);
}
[IntegrationTest]
public async Task UpdatesPrivate()
{
var github = CreateGitHubClient();
var repoName = Helper.MakeNameWithTimestamp("public-repo");
_repository = await github.Repository.Create(new NewRepository { Name = repoName, AutoInit = true });
var update = new RepositoryUpdate { Name = repoName, Private = true };
_repository = await github.Repository.Edit(Helper.UserName, repoName, update);
Assert.Equal(true, _repository.Private);
}
[IntegrationTest]
public async Task UpdatesHasDownloads()
{
var github = CreateGitHubClient();
var repoName = Helper.MakeNameWithTimestamp("public-repo");
_repository = await github.Repository.Create(new NewRepository { Name = repoName, AutoInit = true });
var update = new RepositoryUpdate { Name = repoName, HasDownloads = false };
_repository = await github.Repository.Edit(Helper.UserName, repoName, update);
Assert.Equal(false, _repository.HasDownloads);
}
[IntegrationTest]
public async Task UpdatesHasIssues()
{
var github = CreateGitHubClient();
var repoName = Helper.MakeNameWithTimestamp("public-repo");
_repository = await github.Repository.Create(new NewRepository { Name = repoName, AutoInit = true });
var update = new RepositoryUpdate { Name = repoName, HasIssues = false };
_repository = await github.Repository.Edit(Helper.UserName, repoName, update);
Assert.Equal(false, _repository.HasIssues);
}
[IntegrationTest]
public async Task UpdatesHasWiki()
{
var github = CreateGitHubClient();
var repoName = Helper.MakeNameWithTimestamp("public-repo");
_repository = await github.Repository.Create(new NewRepository { Name = repoName, AutoInit = true });
var update = new RepositoryUpdate { Name = repoName, HasWiki = false };
_repository = await github.Repository.Edit(Helper.UserName, repoName, update);
Assert.Equal(false, _repository.HasWiki);
}
public void Dispose()
{
Helper.DeleteRepo(_repository);
}
}
public class TheDeleteMethod
{
[IntegrationTest]
@@ -395,4 +507,58 @@ public class RepositoriesClientTests
Assert.Contains("<p><strong>WARNING: This is some haacky code.", readmeHtml);
}
}
public class TheGetAllContributorsMethod
{
[IntegrationTest]
public async Task GetsContributors()
{
var github = CreateGitHubClient();
var contributors = await github.Repository.GetAllContributors("octokit", "octokit.net");
Assert.True(contributors.Any(c => c.Login == "pmacn"));
}
}
public class TheGetAllLanguagesMethod
{
[IntegrationTest]
public async Task GetsLanguages()
{
var github = CreateGitHubClient();
var languages = await github.Repository.GetAllLanguages("octokit", "octokit.net");
Assert.NotEmpty(languages);
Assert.True(languages.Any(l => l.Name == "C#"));
}
}
public class TheGetAllTagsMethod
{
[IntegrationTest]
public async Task GetsTags()
{
var github = CreateGitHubClient();
var tags = await github.Repository.GetAllTags("octokit", "octokit.net");
Assert.True(tags.Any(t => t.Name == "v0.1.0"));
}
}
public class TheGetBranchMethod
{
[IntegrationTest]
public async Task GetsABranch()
{
var github = CreateGitHubClient();
var branch = await github.Repository.GetBranch("octokit", "octokit.net", "master");
Assert.NotNull(branch);
Assert.Equal("master", branch.Name);
}
}
}