updated the integration tests for createing a commit and a tree 👯

This commit is contained in:
Brendan Forster
2013-11-27 12:40:26 -08:00
parent 06737995ed
commit 1429141b42
2 changed files with 94 additions and 54 deletions
@@ -2,53 +2,62 @@
using System.Linq;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Octokit;
using Octokit.Tests.Integration;
using Xunit;
namespace Octokit.Tests.Integration
public class CommitsClientTests : IDisposable
{
public class CommitsClientTests : IDisposable
readonly IGitHubClient _client;
readonly Repository _repository;
readonly ICommitsClient _fixture;
readonly string _owner;
public CommitsClientTests()
{
readonly IGitHubClient _gitHubClient;
readonly Repository _repository;
readonly ICommitsClient _commitsClient;
public CommitsClientTests()
_client = new GitHubClient(new ProductHeaderValue("OctokitTests"))
{
this._gitHubClient = new GitHubClient(new ProductHeaderValue("OctokitTests"))
{
Credentials = Helper.Credentials
};
Credentials = Helper.Credentials
};
var repoName = Helper.MakeNameWithTimestamp("public-repo");
this._commitsClient = this._gitHubClient.GitDatabase.Commit;
this._repository = this._gitHubClient.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }).Result;
}
[IntegrationTest(Skip = "Requires Tree Api implementation to create a commit")]
public async Task CanCreateAndRetrieveCommit()
{
string owner = this._repository.Owner.Login;
var author = new Signature { Name = "author", Email = "test-author@example.com", Date = DateTime.UtcNow };
var commiter = new Signature { Name = "commiter", Email = "test-commiter@example.com", Date = DateTime.Today };
var newCommit = new NewCommit("test-commit", "[Change this to tree sha]", Enumerable.Empty<string>())
{
Author = author,
Committer = commiter
};
var commit = await this._commitsClient.Create(owner, this._repository.Name, newCommit);
Assert.NotNull(commit);
var retrieved = await this._commitsClient.Get(owner, this._repository.Name, commit.Sha);
Assert.NotNull(retrieved);
}
public void Dispose()
{
Helper.DeleteRepo(this._repository);
}
var repoName = Helper.MakeNameWithTimestamp("public-repo");
_fixture = _client.GitDatabase.Commit;
_repository = _client.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }).Result;
_owner = _repository.Owner.Login;
}
}
[IntegrationTest]
public async Task CanCreateAndRetrieveCommit()
{
var blob = new NewBlob
{
Content = "Hello World!",
Encoding = EncodingType.Utf8
};
var blobResult = await _client.GitDatabase.Blob.Create(_owner, _repository.Name, blob);
var newTree = new NewTree();
newTree.Tree.Add(new NewTreeItem
{
Type = TreeType.Blob,
Mode = FileMode.File,
Path = "README.md",
Sha = blobResult.Sha
});
var treeResult = await _client.GitDatabase.Tree.Create(_owner, _repository.Name, newTree);
var newCommit = new NewCommit("test-commit", treeResult.Sha, Enumerable.Empty<string>());
var commit = await _fixture.Create(_owner, _repository.Name, newCommit);
Assert.NotNull(commit);
var retrieved = await _fixture.Get(_owner, _repository.Name, commit.Sha);
Assert.NotNull(retrieved);
}
public void Dispose()
{
Helper.DeleteRepo(_repository);
}
}
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Octokit;
@@ -6,17 +7,24 @@ using Octokit.Tests.Helpers;
using Octokit.Tests.Integration;
using Xunit;
public class ReferencesClientTests
public class ReferencesClientTests : IDisposable
{
readonly IReferencesClient _fixture;
readonly Repository _repository;
readonly GitHubClient _client;
readonly string _owner;
public ReferencesClientTests()
{
var client = new GitHubClient(new ProductHeaderValue("OctokitTests"))
_client = new GitHubClient(new ProductHeaderValue("OctokitTests"))
{
Credentials = Helper.Credentials
};
_fixture = client.GitDatabase.Reference;
_fixture = _client.GitDatabase.Reference;
var repoName = Helper.MakeNameWithTimestamp("public-repo");
_repository = _client.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }).Result;
_owner = _repository.Owner.Login;
}
[IntegrationTest]
@@ -47,22 +55,40 @@ public class ReferencesClientTests
Assert.NotEmpty(list);
}
[IntegrationTest(Skip="TODO")]
[IntegrationTest(Skip="See ")]
public async Task CanGetErrorForInvalidNamespace()
{
await AssertEx.Throws<Exception>(
async () => { await _fixture.GetAllForSubNamespace("octokit", "octokit.net", "666"); });
}
[IntegrationTest(Skip = "TODO")]
[IntegrationTest(Skip = "Investigating a 'Server Error' API response when creating a commit")]
public async Task CanCreateAReference()
{
// TODO: create a blob
// TODO: create a tree
// TODO: create a commit
// TODO: use the SHA to create a reference
var newReference = new NewReference("heads/develop", "sha");
var result = await _fixture.Create("owner", "repo", newReference);
var blob = new NewBlob
{
Content = "Hello World!",
Encoding = EncodingType.Utf8
};
var blobResult = await _client.GitDatabase.Blob.Create(_owner, _repository.Name, blob);
var newTree = new NewTree();
newTree.Tree.Add(new NewTreeItem
{
Mode = FileMode.File,
Type = TreeType.Blob,
Path = "README.md",
Sha = blobResult.Sha
});
var treeResult = await _client.GitDatabase.Tree.Create(_owner, _repository.Name, newTree);
var newCommit = new NewCommit("This is a new commit", treeResult.Sha, Enumerable.Empty<string>());
var commitResult = await _client.GitDatabase.Commit.Create(_owner, _repository.Name, newCommit);
var newReference = new NewReference("heads/develop", commitResult.Sha);
var result = await _fixture.Create(_owner, _repository.Name, newReference);
Assert.NotNull(result);
}
@@ -98,4 +124,9 @@ public class ReferencesClientTests
await _fixture.Delete("owner", "repo", "heads/develop");
}
public void Dispose()
{
Helper.DeleteRepo(_repository);
}
}