added some integration tests around creating commit status

This commit is contained in:
Brendan Forster
2014-05-17 11:34:56 +10:00
parent 6858f31713
commit e532bb21b0
@@ -1,4 +1,6 @@
using System.Threading.Tasks;
using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Octokit;
using Octokit.Tests.Integration;
using Xunit;
@@ -26,4 +28,87 @@ public class CommitStatusClientTests
Assert.Equal(CommitState.Pending, statuses[1].State);
}
}
public class TheCreateMethod : IDisposable
{
readonly IGitHubClient _client;
readonly Repository _repository;
readonly string _owner;
public TheCreateMethod()
{
_client = new GitHubClient(new ProductHeaderValue("OctokitTests"))
{
Credentials = Helper.Credentials
};
var repoName = Helper.MakeNameWithTimestamp("public-repo");
_repository = _client.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }).Result;
_owner = _repository.Owner.Login;
}
[IntegrationTest]
public async Task CanAssignPendingToCommit()
{
var commit = await SetupCommitForRepository(_client);
var status = new NewCommitStatus
{
State = CommitState.Pending,
Description = "this is a test status"
};
var result = await _client.Repository.CommitStatus.Create(_owner, _repository.Name, commit.Sha, status);
Assert.Equal(CommitState.Pending, result.State);
}
[IntegrationTest]
public async Task CanRetrievePendingStatus()
{
var commit = await SetupCommitForRepository(_client);
var status = new NewCommitStatus
{
State = CommitState.Pending,
Description = "this is a test status"
};
await _client.Repository.CommitStatus.Create(_owner, _repository.Name, commit.Sha, status);
var statuses = await _client.Repository.CommitStatus.GetAll(_owner, _repository.Name, commit.Sha);
Assert.Equal(1, statuses.Count);
Assert.Equal(CommitState.Pending, statuses[0].State);
}
async Task<Commit> SetupCommitForRepository(IGitHubClient client)
{
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);
return await client.GitDatabase.Commit.Create(_owner, _repository.Name, newCommit);
}
public void Dispose()
{
_client.Repository.Delete(_owner, _repository.Name).Wait();
}
}
}