added new integration tests

This commit is contained in:
aedampir@gmail.com
2016-06-16 16:15:06 +07:00
parent 6575652b9c
commit 1580f16c82
@@ -35,6 +35,20 @@ public class ReferencesClientTests : IDisposable
Assert.False(string.IsNullOrWhiteSpace(@ref.Object.Sha));
}
[IntegrationTest]
public async Task CanGetAReferenceWithRepositoryId()
{
var @ref = await _fixture.Get(7528679, "heads/master");
// validate the top-level properties
Assert.Equal("refs/heads/master", @ref.Ref);
Assert.Equal("https://api.github.com/repos/octokit/octokit.net/git/refs/heads/master", @ref.Url);
// validate the git reference
Assert.Equal(TaggedType.Commit, @ref.Object.Type);
Assert.False(string.IsNullOrWhiteSpace(@ref.Object.Sha));
}
[IntegrationTest]
public async Task WhenReferenceDoesNotExistAnExceptionIsThrown()
{
@@ -49,6 +63,13 @@ public class ReferencesClientTests : IDisposable
Assert.NotEmpty(list);
}
[IntegrationTest(Skip = "This is paging for a long long time")]
public async Task CanGetListOfReferencesWithRepositoryId()
{
var list = await _fixture.GetAll(7528679);
Assert.NotEmpty(list);
}
[IntegrationTest]
public async Task CanGetListOfReferencesInNamespace()
{
@@ -56,6 +77,13 @@ public class ReferencesClientTests : IDisposable
Assert.NotEmpty(list);
}
[IntegrationTest]
public async Task CanGetListOfReferencesInNamespaceWithRepositoryId()
{
var list = await _fixture.GetAllForSubNamespace(7528679, "heads");
Assert.NotEmpty(list);
}
[IntegrationTest]
public async Task CanGetErrorForInvalidNamespace()
{
@@ -99,6 +127,37 @@ public class ReferencesClientTests : IDisposable
Assert.Equal(commitResult.Sha, result.Object.Sha);
}
[IntegrationTest]
public async Task CanCreateAReferenceWithRepositoryId()
{
var blob = new NewBlob
{
Content = "Hello World!",
Encoding = EncodingType.Utf8
};
var blobResult = await _github.Git.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, 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 _github.Git.Tree.Create(_context.RepositoryOwner, _context.RepositoryName, newTree);
var newCommit = new NewCommit("This is a new commit", treeResult.Sha);
var commitResult = await _github.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit);
var newReference = new NewReference("heads/develop", commitResult.Sha);
var result = await _fixture.Create(_context.Repository.Id, newReference);
Assert.Equal(commitResult.Sha, result.Object.Sha);
}
[IntegrationTest]
public async Task CanUpdateAReference()
{
@@ -152,6 +211,59 @@ public class ReferencesClientTests : IDisposable
Assert.Equal(secondCommitResult.Sha, result.Object.Sha);
}
[IntegrationTest]
public async Task CanUpdateAReferenceWithRepositoryId()
{
var firstBlob = new NewBlob
{
Content = "Hello World!",
Encoding = EncodingType.Utf8
};
var firstBlobResult = await _github.Git.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, firstBlob);
var secondBlob = new NewBlob
{
Content = "This is a test!",
Encoding = EncodingType.Utf8
};
var secondBlobResult = await _github.Git.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, secondBlob);
var firstTree = new NewTree();
firstTree.Tree.Add(new NewTreeItem
{
Mode = FileMode.File,
Type = TreeType.Blob,
Path = "README.md",
Sha = firstBlobResult.Sha
});
var firstTreeResult = await _github.Git.Tree.Create(_context.RepositoryOwner, _context.RepositoryName, firstTree);
var firstCommit = new NewCommit("This is a new commit", firstTreeResult.Sha);
var firstCommitResult = await _github.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, firstCommit);
var newReference = new NewReference("heads/develop", firstCommitResult.Sha);
await _fixture.Create(_context.Repository.Id, newReference);
var secondTree = new NewTree();
secondTree.Tree.Add(new NewTreeItem
{
Mode = FileMode.File,
Type = TreeType.Blob,
Path = "README.md",
Sha = secondBlobResult.Sha
});
var secondTreeResult = await _github.Git.Tree.Create(_context.RepositoryOwner, _context.RepositoryName, secondTree);
var secondCommit = new NewCommit("This is a new commit", secondTreeResult.Sha, firstCommitResult.Sha);
var secondCommitResult = await _github.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, secondCommit);
var referenceUpdate = new ReferenceUpdate(secondCommitResult.Sha);
var result = await _fixture.Update(_context.Repository.Id, "heads/develop", referenceUpdate);
Assert.Equal(secondCommitResult.Sha, result.Object.Sha);
}
[IntegrationTest]
public async Task CanDeleteAReference()
{
@@ -187,6 +299,41 @@ public class ReferencesClientTests : IDisposable
Assert.Empty(all.Where(r => r.Ref == "heads/develop"));
}
[IntegrationTest]
public async Task CanDeleteAReferenceWithRepositoryId()
{
var blob = new NewBlob
{
Content = "Hello World!",
Encoding = EncodingType.Utf8
};
var blobResult = await _github.Git.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, 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 _github.Git.Tree.Create(_context.RepositoryOwner, _context.RepositoryName, newTree);
var newCommit = new NewCommit("This is a new commit", treeResult.Sha);
var commitResult = await _github.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit);
var newReference = new NewReference("heads/develop", commitResult.Sha);
await _fixture.Create(_context.Repository.Id, newReference);
await _fixture.Delete(_context.Repository.Id, "heads/develop");
var all = await _fixture.GetAll(_context.Repository.Id);
Assert.Empty(all.Where(r => r.Ref == "heads/develop"));
}
public void Dispose()
{
_context.Dispose();