Refactors a whole bunch of tests

This commit is contained in:
William Barbosa
2015-09-26 23:37:54 -03:00
parent b794c3581b
commit 42e480c2c0
7 changed files with 178 additions and 190 deletions

View File

@@ -4,11 +4,12 @@ using Octokit;
using Octokit.Tests.Integration;
using System.Threading.Tasks;
using Xunit;
using Octokit.Tests.Integration.Helpers;
public class BlobClientTests : IDisposable
{
readonly IBlobsClient _fixture;
readonly Repository _repository;
readonly RepositoryContext _context;
readonly string _owner;
public BlobClientTests()
@@ -16,9 +17,8 @@ public class BlobClientTests : IDisposable
var client = Helper.GetAuthenticatedClient();
_fixture = client.GitDatabase.Blob;
var repoName = Helper.MakeNameWithTimestamp("public-repo");
_repository = client.Repository.Create(new NewRepository(repoName) { AutoInit = true }).Result;
_owner = _repository.Owner.Login;
_context = client.CreateRepositoryContext("public-repo").Result;
_owner = _context.Repository.Owner.Login;
}
[IntegrationTest]
@@ -30,7 +30,7 @@ public class BlobClientTests : IDisposable
Encoding = EncodingType.Utf8
};
var result = await _fixture.Create(_owner, _repository.Name, blob);
var result = await _fixture.Create(_owner, _context.Repository.Name, blob);
Assert.False(String.IsNullOrWhiteSpace(result.Sha));
}
@@ -47,7 +47,7 @@ public class BlobClientTests : IDisposable
Encoding = EncodingType.Base64
};
var result = await _fixture.Create(_owner, _repository.Name, blob);
var result = await _fixture.Create(_owner, _context.Repository.Name, blob);
Assert.False(String.IsNullOrWhiteSpace(result.Sha));
}
@@ -61,8 +61,8 @@ public class BlobClientTests : IDisposable
Encoding = EncodingType.Utf8
};
var result = await _fixture.Create(_owner, _repository.Name, newBlob);
var blob = await _fixture.Get(_owner, _repository.Name, result.Sha);
var result = await _fixture.Create(_owner, _context.Repository.Name, newBlob);
var blob = await _fixture.Get(_owner, _context.Repository.Name, result.Sha);
Assert.Equal(result.Sha, blob.Sha);
Assert.Equal(EncodingType.Base64, blob.Encoding);
@@ -84,8 +84,8 @@ public class BlobClientTests : IDisposable
Encoding = EncodingType.Base64
};
var result = await _fixture.Create(_owner, _repository.Name, newBlob);
var blob = await _fixture.Get(_owner, _repository.Name, result.Sha);
var result = await _fixture.Create(_owner, _context.Repository.Name, newBlob);
var blob = await _fixture.Get(_owner, _context.Repository.Name, result.Sha);
Assert.Equal(result.Sha, blob.Sha);
Assert.Equal(EncodingType.Base64, blob.Encoding);
@@ -98,6 +98,6 @@ public class BlobClientTests : IDisposable
public void Dispose()
{
Helper.DeleteRepo(_repository);
_context.Dispose();
}
}

View File

@@ -4,6 +4,7 @@ using System.Threading.Tasks;
using Octokit;
using Octokit.Tests.Integration;
using Xunit;
using Octokit.Tests.Integration.Helpers;
public class CommitStatusClientTests
{
@@ -47,17 +48,16 @@ public class CommitStatusClientTests
public class TheCreateMethod : IDisposable
{
readonly IGitHubClient _client;
readonly Repository _repository;
readonly string _owner;
private readonly IGitHubClient _client;
private readonly RepositoryContext _context;
private readonly string _owner;
public TheCreateMethod()
{
_client = Helper.GetAuthenticatedClient();
var repoName = Helper.MakeNameWithTimestamp("public-repo");
_repository = _client.Repository.Create(new NewRepository(repoName) { AutoInit = true }).Result;
_owner = _repository.Owner.Login;
_context = _client.CreateRepositoryContext("public-repo").Result;
_owner = _context.Repository.Owner.Login;
}
[IntegrationTest]
@@ -71,7 +71,7 @@ public class CommitStatusClientTests
Description = "this is a test status"
};
var result = await _client.Repository.CommitStatus.Create(_owner, _repository.Name, commit.Sha, status);
var result = await _client.Repository.CommitStatus.Create(_owner, _context.Repository.Name, commit.Sha, status);
Assert.Equal(CommitState.Pending, result.State);
}
@@ -87,9 +87,9 @@ public class CommitStatusClientTests
Description = "this is a test status"
};
await _client.Repository.CommitStatus.Create(_owner, _repository.Name, commit.Sha, status);
await _client.Repository.CommitStatus.Create(_owner, _context.Repository.Name, commit.Sha, status);
var statuses = await _client.Repository.CommitStatus.GetAll(_owner, _repository.Name, commit.Sha);
var statuses = await _client.Repository.CommitStatus.GetAll(_owner, _context.Repository.Name, commit.Sha);
Assert.Equal(1, statuses.Count);
Assert.Equal(CommitState.Pending, statuses[0].State);
@@ -106,13 +106,13 @@ public class CommitStatusClientTests
Description = "this is a test status"
};
await _client.Repository.CommitStatus.Create(_owner, _repository.Name, commit.Sha, status);
await _client.Repository.CommitStatus.Create(_owner, _context.Repository.Name, commit.Sha, status);
status.State = CommitState.Success;
await _client.Repository.CommitStatus.Create(_owner, _repository.Name, commit.Sha, status);
await _client.Repository.CommitStatus.Create(_owner, _context.Repository.Name, commit.Sha, status);
var statuses = await _client.Repository.CommitStatus.GetAll(_owner, _repository.Name, commit.Sha);
var statuses = await _client.Repository.CommitStatus.GetAll(_owner, _context.Repository.Name, commit.Sha);
Assert.Equal(2, statuses.Count);
Assert.Equal(CommitState.Success, statuses[0].State);
@@ -129,9 +129,9 @@ public class CommitStatusClientTests
Description = "this is a test status"
};
await _client.Repository.CommitStatus.Create(_owner, _repository.Name, commit.Sha, status);
await _client.Repository.CommitStatus.Create(_owner, _context.Repository.Name, commit.Sha, status);
var statuses = await _client.Repository.CommitStatus.GetAll(_owner, _repository.Name, commit.Sha);
var statuses = await _client.Repository.CommitStatus.GetAll(_owner, _context.Repository.Name, commit.Sha);
Assert.Equal(1, statuses.Count);
Assert.Equal("default", statuses[0].Context);
@@ -149,27 +149,27 @@ public class CommitStatusClientTests
Context = "System A"
};
await _client.Repository.CommitStatus.Create(_owner, _repository.Name, commit.Sha, status);
await _client.Repository.CommitStatus.Create(_owner, _context.Repository.Name, commit.Sha, status);
status.Context = "System B";
await _client.Repository.CommitStatus.Create(_owner, _repository.Name, commit.Sha, status);
await _client.Repository.CommitStatus.Create(_owner, _context.Repository.Name, commit.Sha, status);
var statuses = await _client.Repository.CommitStatus.GetAll(_owner, _repository.Name, commit.Sha);
var statuses = await _client.Repository.CommitStatus.GetAll(_owner, _context.Repository.Name, commit.Sha);
Assert.Equal(2, statuses.Count);
Assert.Equal("System B", statuses[0].Context);
Assert.Equal("System A", statuses[1].Context);
}
async Task<Commit> SetupCommitForRepository(IGitHubClient client)
private 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 blobResult = await client.GitDatabase.Blob.Create(_owner, _context.Repository.Name, blob);
var newTree = new NewTree();
newTree.Tree.Add(new NewTreeItem
@@ -180,16 +180,16 @@ public class CommitStatusClientTests
Sha = blobResult.Sha
});
var treeResult = await client.GitDatabase.Tree.Create(_owner, _repository.Name, newTree);
var treeResult = await client.GitDatabase.Tree.Create(_owner, _context.Repository.Name, newTree);
var newCommit = new NewCommit("test-commit", treeResult.Sha);
return await client.GitDatabase.Commit.Create(_owner, _repository.Name, newCommit);
return await client.GitDatabase.Commit.Create(_owner, _context.Repository.Name, newCommit);
}
public void Dispose()
{
_client.Repository.Delete(_owner, _repository.Name).Wait();
_context.Dispose();
}
}
}

View File

@@ -3,29 +3,23 @@ using System.Threading.Tasks;
using Octokit;
using Octokit.Tests.Integration;
using Xunit;
using Octokit.Tests.Integration.Helpers;
public class DeploymentStatusClientTests : IDisposable
{
IGitHubClient _gitHubClient;
IDeploymentsClient _deploymentsClient;
Repository _repository;
Commit _commit;
Deployment _deployment;
string _repositoryOwner;
private readonly IDeploymentsClient _deploymentsClient;
private readonly RepositoryContext _context;
private readonly Commit _commit;
private readonly Deployment _deployment;
private readonly string _repositoryOwner;
public DeploymentStatusClientTests()
{
_gitHubClient = Helper.GetAuthenticatedClient();
var github = Helper.GetAuthenticatedClient();
_deploymentsClient = _gitHubClient.Repository.Deployment;
var newRepository = new NewRepository(Helper.MakeNameWithTimestamp("public-repo"))
{
AutoInit = true
};
_repository = _gitHubClient.Repository.Create(newRepository).Result;
_repositoryOwner = _repository.Owner.Login;
_deploymentsClient = github.Repository.Deployment;
_context = github.CreateRepositoryContext("public-repo").Result;
_repositoryOwner = _context.Repository.Owner.Login;
var blob = new NewBlob
{
@@ -33,7 +27,7 @@ public class DeploymentStatusClientTests : IDisposable
Encoding = EncodingType.Utf8
};
var blobResult = _gitHubClient.GitDatabase.Blob.Create(_repositoryOwner, _repository.Name, blob).Result;
var blobResult = github.GitDatabase.Blob.Create(_repositoryOwner, _context.Repository.Name, blob).Result;
var newTree = new NewTree();
newTree.Tree.Add(new NewTreeItem
@@ -44,12 +38,12 @@ public class DeploymentStatusClientTests : IDisposable
Sha = blobResult.Sha
});
var treeResult = _gitHubClient.GitDatabase.Tree.Create(_repositoryOwner, _repository.Name, newTree).Result;
var treeResult = github.GitDatabase.Tree.Create(_repositoryOwner, _context.Repository.Name, newTree).Result;
var newCommit = new NewCommit("test-commit", treeResult.Sha);
_commit = _gitHubClient.GitDatabase.Commit.Create(_repositoryOwner, _repository.Name, newCommit).Result;
_commit = github.GitDatabase.Commit.Create(_repositoryOwner, _context.Repository.Name, newCommit).Result;
var newDeployment = new NewDeployment { Ref = _commit.Sha, AutoMerge = false };
_deployment = _deploymentsClient.Create(_repositoryOwner, _repository.Name, newDeployment).Result;
_deployment = _deploymentsClient.Create(_repositoryOwner, _context.Repository.Name, newDeployment).Result;
}
[IntegrationTest]
@@ -57,7 +51,7 @@ public class DeploymentStatusClientTests : IDisposable
{
var newStatus = new NewDeploymentStatus { State = DeploymentState.Success };
var status = await _deploymentsClient.Status.Create(_repositoryOwner, _repository.Name, _deployment.Id, newStatus);
var status = await _deploymentsClient.Status.Create(_repositoryOwner, _context.Repository.Name, _deployment.Id, newStatus);
Assert.NotNull(status);
Assert.Equal(DeploymentState.Success, status.State);
@@ -67,9 +61,9 @@ public class DeploymentStatusClientTests : IDisposable
public async Task CanReadDeploymentStatuses()
{
var newStatus = new NewDeploymentStatus { State = DeploymentState.Success };
await _deploymentsClient.Status.Create(_repositoryOwner, _repository.Name, _deployment.Id, newStatus);
await _deploymentsClient.Status.Create(_repositoryOwner, _context.Repository.Name, _deployment.Id, newStatus);
var statuses = await _deploymentsClient.Status.GetAll(_repositoryOwner, _repository.Name, _deployment.Id);
var statuses = await _deploymentsClient.Status.GetAll(_repositoryOwner, _context.Repository.Name, _deployment.Id);
Assert.NotEmpty(statuses);
Assert.Equal(DeploymentState.Success, statuses[0].State);
@@ -77,7 +71,7 @@ public class DeploymentStatusClientTests : IDisposable
public void Dispose()
{
Helper.DeleteRepo(_repository);
_context.Dispose();
}
}

View File

@@ -3,28 +3,22 @@ using System.Threading.Tasks;
using Octokit;
using Octokit.Tests.Integration;
using Xunit;
using Octokit.Tests.Integration.Helpers;
public class DeploymentsClientTests : IDisposable
{
readonly IGitHubClient _gitHubClient;
readonly IDeploymentsClient _deploymentsClient;
readonly Repository _repository;
readonly Commit _commit;
readonly string _repositoryOwner;
private readonly IDeploymentsClient _deploymentsClient;
private readonly RepositoryContext _context;
private readonly Commit _commit;
private readonly string _repositoryOwner;
public DeploymentsClientTests()
{
_gitHubClient = Helper.GetAuthenticatedClient();
var github = Helper.GetAuthenticatedClient();
_deploymentsClient = _gitHubClient.Repository.Deployment;
var newRepository = new NewRepository(Helper.MakeNameWithTimestamp("public-repo"))
{
AutoInit = true
};
_repository = _gitHubClient.Repository.Create(newRepository).Result;
_repositoryOwner = _repository.Owner.Login;
_deploymentsClient = github.Repository.Deployment;
_context = github.CreateRepositoryContext("public-repo").Result;
_repositoryOwner = _context.Repository.Owner.Login;
var blob = new NewBlob
{
@@ -32,7 +26,7 @@ public class DeploymentsClientTests : IDisposable
Encoding = EncodingType.Utf8
};
var blobResult = _gitHubClient.GitDatabase.Blob.Create(_repositoryOwner, _repository.Name, blob).Result;
var blobResult = github.GitDatabase.Blob.Create(_repositoryOwner, _context.Repository.Name, blob).Result;
var newTree = new NewTree();
newTree.Tree.Add(new NewTreeItem
@@ -43,9 +37,9 @@ public class DeploymentsClientTests : IDisposable
Sha = blobResult.Sha
});
var treeResult = _gitHubClient.GitDatabase.Tree.Create(_repositoryOwner, _repository.Name, newTree).Result;
var treeResult = github.GitDatabase.Tree.Create(_repositoryOwner, _context.Repository.Name, newTree).Result;
var newCommit = new NewCommit("test-commit", treeResult.Sha);
_commit = _gitHubClient.GitDatabase.Commit.Create(_repositoryOwner, _repository.Name, newCommit).Result;
_commit = github.GitDatabase.Commit.Create(_repositoryOwner, _context.Repository.Name, newCommit).Result;
}
[IntegrationTest]
@@ -53,7 +47,7 @@ public class DeploymentsClientTests : IDisposable
{
var newDeployment = new NewDeployment { Ref = _commit.Sha, AutoMerge = false };
var deployment = await _deploymentsClient.Create(_repositoryOwner, _repository.Name, newDeployment);
var deployment = await _deploymentsClient.Create(_repositoryOwner, _context.Repository.Name, newDeployment);
Assert.NotNull(deployment);
}
@@ -62,15 +56,15 @@ public class DeploymentsClientTests : IDisposable
public async Task CanGetDeployments()
{
var newDeployment = new NewDeployment { Ref = _commit.Sha, AutoMerge = false };
await _deploymentsClient.Create(_repositoryOwner, _repository.Name, newDeployment);
var deployments = await _deploymentsClient.GetAll(_repositoryOwner, _repository.Name);
await _deploymentsClient.Create(_repositoryOwner, _context.Repository.Name, newDeployment);
var deployments = await _deploymentsClient.GetAll(_repositoryOwner, _context.Repository.Name);
Assert.NotEmpty(deployments);
}
public void Dispose()
{
Helper.DeleteRepo(_repository);
_context.Dispose();
}
}

View File

@@ -7,40 +7,40 @@ using Octokit;
using Octokit.Tests.Helpers;
using Octokit.Tests.Integration;
using Xunit;
using Octokit.Tests.Integration.Helpers;
public class IssuesClientTests : IDisposable
{
readonly IGitHubClient _gitHubClient;
readonly Repository _repository;
readonly IIssuesClient _issuesClient;
private readonly RepositoryContext _context;
private readonly IIssuesClient _issuesClient;
public IssuesClientTests()
{
_gitHubClient = Helper.GetAuthenticatedClient();
var github = Helper.GetAuthenticatedClient();
var repoName = Helper.MakeNameWithTimestamp("public-repo");
_issuesClient = _gitHubClient.Issue;
_repository = _gitHubClient.Repository.Create(new NewRepository(repoName)).Result;
_issuesClient = github.Issue;
_context = github.CreateRepositoryContext(new NewRepository(repoName)).Result;
}
[IntegrationTest]
public async Task CanCreateRetrieveAndCloseIssue()
{
string owner = _repository.Owner.Login;
string owner = _context.Repository.Owner.Login;
var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" };
var issue = await _issuesClient.Create(owner, _repository.Name, newIssue);
var issue = await _issuesClient.Create(owner, _context.Repository.Name, newIssue);
try
{
Assert.NotNull(issue);
var retrieved = await _issuesClient.Get(owner, _repository.Name, issue.Number);
var all = await _issuesClient.GetAllForRepository(owner, _repository.Name);
var retrieved = await _issuesClient.Get(owner, _context.Repository.Name, issue.Number);
var all = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name);
Assert.NotNull(retrieved);
Assert.True(all.Any(i => i.Number == retrieved.Number));
}
finally
{
var closed = _issuesClient.Update(owner, _repository.Name, issue.Number,
var closed = _issuesClient.Update(owner, _context.Repository.Name, issue.Number,
new IssueUpdate { State = ItemState.Closed })
.Result;
Assert.NotNull(closed);
@@ -50,21 +50,21 @@ public class IssuesClientTests : IDisposable
[IntegrationTest]
public async Task CanListOpenIssuesWithDefaultSort()
{
string owner = _repository.Owner.Login;
string owner = _context.Repository.Owner.Login;
var newIssue1 = new NewIssue("A test issue1") { Body = "A new unassigned issue" };
var newIssue2 = new NewIssue("A test issue2") { Body = "A new unassigned issue" };
var newIssue3 = new NewIssue("A test issue3") { Body = "A new unassigned issue" };
var newIssue4 = new NewIssue("A test issue4") { Body = "A new unassigned issue" };
await _issuesClient.Create(owner, _repository.Name, newIssue1);
Thread.Sleep(1000);
await _issuesClient.Create(owner, _repository.Name, newIssue2);
Thread.Sleep(1000);
await _issuesClient.Create(owner, _repository.Name, newIssue3);
var closed = await _issuesClient.Create(owner, _repository.Name, newIssue4);
await _issuesClient.Update(owner, _repository.Name, closed.Number,
await _issuesClient.Create(owner, _context.Repository.Name, newIssue1);
Thread.Sleep(1000);
await _issuesClient.Create(owner, _context.Repository.Name, newIssue2);
Thread.Sleep(1000);
await _issuesClient.Create(owner, _context.Repository.Name, newIssue3);
var closed = await _issuesClient.Create(owner, _context.Repository.Name, newIssue4);
await _issuesClient.Update(owner, _context.Repository.Name, closed.Number,
new IssueUpdate { State = ItemState.Closed });
var issues = await _issuesClient.GetAllForRepository(owner, _repository.Name);
var issues = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name);
Assert.Equal(3, issues.Count);
Assert.Equal("A test issue3", issues[0].Title);
@@ -75,22 +75,22 @@ public class IssuesClientTests : IDisposable
[IntegrationTest]
public async Task CanListIssuesWithAscendingSort()
{
string owner = _repository.Owner.Login;
string owner = _context.Repository.Owner.Login;
var newIssue1 = new NewIssue("A test issue1") { Body = "A new unassigned issue" };
var newIssue2 = new NewIssue("A test issue2") { Body = "A new unassigned issue" };
var newIssue3 = new NewIssue("A test issue3") { Body = "A new unassigned issue" };
var newIssue4 = new NewIssue("A test issue4") { Body = "A new unassigned issue" };
await _issuesClient.Create(owner, _repository.Name, newIssue1);
await _issuesClient.Create(owner, _context.Repository.Name, newIssue1);
Thread.Sleep(1000);
await _issuesClient.Create(owner, _repository.Name, newIssue2);
await _issuesClient.Create(owner, _context.Repository.Name, newIssue2);
Thread.Sleep(1000);
await _issuesClient.Create(owner, _repository.Name, newIssue3);
var closed = await _issuesClient.Create(owner, _repository.Name, newIssue4);
await _issuesClient.Update(owner, _repository.Name, closed.Number,
await _issuesClient.Create(owner, _context.Repository.Name, newIssue3);
var closed = await _issuesClient.Create(owner, _context.Repository.Name, newIssue4);
await _issuesClient.Update(owner, _context.Repository.Name, closed.Number,
new IssueUpdate { State = ItemState.Closed });
var issues = await _issuesClient.GetAllForRepository(owner, _repository.Name,
var issues = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name,
new RepositoryIssueRequest {SortDirection = SortDirection.Ascending});
Assert.Equal(3, issues.Count);
@@ -102,17 +102,17 @@ public class IssuesClientTests : IDisposable
[IntegrationTest]
public async Task CanListClosedIssues()
{
string owner = _repository.Owner.Login;
string owner = _context.Repository.Owner.Login;
var newIssue1 = new NewIssue("A test issue1") { Body = "A new unassigned issue" };
var newIssue2 = new NewIssue("A closed issue") { Body = "A new unassigned issue" };
await _issuesClient.Create(owner, _repository.Name, newIssue1);
await _issuesClient.Create(owner, _repository.Name, newIssue2);
var closed = await _issuesClient.Create(owner, _repository.Name, newIssue2);
await _issuesClient.Update(owner, _repository.Name, closed.Number,
await _issuesClient.Create(owner, _context.Repository.Name, newIssue1);
await _issuesClient.Create(owner, _context.Repository.Name, newIssue2);
var closed = await _issuesClient.Create(owner, _context.Repository.Name, newIssue2);
await _issuesClient.Update(owner, _context.Repository.Name, closed.Number,
new IssueUpdate { State = ItemState.Closed });
var issues = await _issuesClient.GetAllForRepository(owner, _repository.Name,
var issues = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name,
new RepositoryIssueRequest { State = ItemState.Closed });
Assert.Equal(1, issues.Count);
@@ -122,14 +122,14 @@ public class IssuesClientTests : IDisposable
[IntegrationTest]
public async Task CanListMilestoneIssues()
{
string owner = _repository.Owner.Login;
var milestone = await _issuesClient.Milestone.Create(owner, _repository.Name, new NewMilestone("milestone"));
string owner = _context.Repository.Owner.Login;
var milestone = await _issuesClient.Milestone.Create(owner, _context.Repository.Name, new NewMilestone("milestone"));
var newIssue1 = new NewIssue("A test issue1") { Body = "A new unassigned issue" };
var newIssue2 = new NewIssue("A milestone issue") { Body = "A new unassigned issue", Milestone = milestone.Number };
await _issuesClient.Create(owner, _repository.Name, newIssue1);
await _issuesClient.Create(owner, _repository.Name, newIssue2);
await _issuesClient.Create(owner, _context.Repository.Name, newIssue1);
await _issuesClient.Create(owner, _context.Repository.Name, newIssue2);
var issues = await _issuesClient.GetAllForRepository(owner, _repository.Name,
var issues = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name,
new RepositoryIssueRequest { Milestone = milestone.Number.ToString(CultureInfo.InvariantCulture) });
Assert.Equal(1, issues.Count);
@@ -139,19 +139,19 @@ public class IssuesClientTests : IDisposable
[IntegrationTest(Skip = "This is paging for a long long time")]
public async Task CanRetrieveAllIssues()
{
string owner = _repository.Owner.Login;
string owner = _context.Repository.Owner.Login;
var newIssue1 = new NewIssue("A test issue1") { Body = "A new unassigned issue" };
var newIssue2 = new NewIssue("A test issue2") { Body = "A new unassigned issue" };
var newIssue3 = new NewIssue("A test issue3") { Body = "A new unassigned issue" };
var newIssue4 = new NewIssue("A test issue4") { Body = "A new unassigned issue" };
var issue1 = await _issuesClient.Create(owner, _repository.Name, newIssue1);
var issue2 = await _issuesClient.Create(owner, _repository.Name, newIssue2);
var issue3 = await _issuesClient.Create(owner, _repository.Name, newIssue3);
var issue4 = await _issuesClient.Create(owner, _repository.Name, newIssue4);
await _issuesClient.Update(owner, _repository.Name, issue4.Number,
var issue1 = await _issuesClient.Create(owner, _context.Repository.Name, newIssue1);
var issue2 = await _issuesClient.Create(owner, _context.Repository.Name, newIssue2);
var issue3 = await _issuesClient.Create(owner, _context.Repository.Name, newIssue3);
var issue4 = await _issuesClient.Create(owner, _context.Repository.Name, newIssue4);
await _issuesClient.Update(owner, _context.Repository.Name, issue4.Number,
new IssueUpdate { State = ItemState.Closed });
var retrieved = await _issuesClient.GetAllForRepository(owner, _repository.Name,
var retrieved = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name,
new RepositoryIssueRequest { State = ItemState.All });
Assert.True(retrieved.Count >= 4);
@@ -164,24 +164,24 @@ public class IssuesClientTests : IDisposable
[IntegrationTest]
public async Task CanFilterByAssigned()
{
var owner = _repository.Owner.Login;
var owner = _context.Repository.Owner.Login;
var newIssue1 = new NewIssue("An assigned issue") { Body = "Assigning this to myself", Assignee = owner };
var newIssue2 = new NewIssue("An unassigned issue") { Body = "A new unassigned issue" };
await _issuesClient.Create(owner, _repository.Name, newIssue1);
await _issuesClient.Create(owner, _repository.Name, newIssue2);
await _issuesClient.Create(owner, _context.Repository.Name, newIssue1);
await _issuesClient.Create(owner, _context.Repository.Name, newIssue2);
var allIssues = await _issuesClient.GetAllForRepository(owner, _repository.Name,
var allIssues = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name,
new RepositoryIssueRequest());
Assert.Equal(2, allIssues.Count);
var assignedIssues = await _issuesClient.GetAllForRepository(owner, _repository.Name,
var assignedIssues = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name,
new RepositoryIssueRequest { Assignee = owner });
Assert.Equal(1, assignedIssues.Count);
Assert.Equal("An assigned issue", assignedIssues[0].Title);
var unassignedIssues = await _issuesClient.GetAllForRepository(owner, _repository.Name,
var unassignedIssues = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name,
new RepositoryIssueRequest { Assignee = "none" });
Assert.Equal(1, unassignedIssues.Count);
@@ -191,23 +191,23 @@ public class IssuesClientTests : IDisposable
[IntegrationTest]
public async Task CanFilterByCreator()
{
var owner = _repository.Owner.Login;
var owner = _context.Repository.Owner.Login;
var newIssue1 = new NewIssue("An issue") { Body = "words words words" };
var newIssue2 = new NewIssue("Another issue") { Body = "some other words" };
await _issuesClient.Create(owner, _repository.Name, newIssue1);
await _issuesClient.Create(owner, _repository.Name, newIssue2);
await _issuesClient.Create(owner, _context.Repository.Name, newIssue1);
await _issuesClient.Create(owner, _context.Repository.Name, newIssue2);
var allIssues = await _issuesClient.GetAllForRepository(owner, _repository.Name,
var allIssues = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name,
new RepositoryIssueRequest());
Assert.Equal(2, allIssues.Count);
var issuesCreatedByOwner = await _issuesClient.GetAllForRepository(owner, _repository.Name,
var issuesCreatedByOwner = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name,
new RepositoryIssueRequest { Creator = owner });
Assert.Equal(2, issuesCreatedByOwner.Count);
var issuesCreatedByExternalUser = await _issuesClient.GetAllForRepository(owner, _repository.Name,
var issuesCreatedByExternalUser = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name,
new RepositoryIssueRequest { Creator = "shiftkey" });
Assert.Equal(0, issuesCreatedByExternalUser.Count);
@@ -216,23 +216,23 @@ public class IssuesClientTests : IDisposable
[IntegrationTest]
public async Task CanFilterByMentioned()
{
var owner = _repository.Owner.Login;
var owner = _context.Repository.Owner.Login;
var newIssue1 = new NewIssue("An issue") { Body = "words words words hello there @shiftkey" };
var newIssue2 = new NewIssue("Another issue") { Body = "some other words" };
await _issuesClient.Create(owner, _repository.Name, newIssue1);
await _issuesClient.Create(owner, _repository.Name, newIssue2);
await _issuesClient.Create(owner, _context.Repository.Name, newIssue1);
await _issuesClient.Create(owner, _context.Repository.Name, newIssue2);
var allIssues = await _issuesClient.GetAllForRepository(owner, _repository.Name,
var allIssues = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name,
new RepositoryIssueRequest());
Assert.Equal(2, allIssues.Count);
var mentionsWithShiftkey = await _issuesClient.GetAllForRepository(owner, _repository.Name,
var mentionsWithShiftkey = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name,
new RepositoryIssueRequest { Mentioned = "shiftkey" });
Assert.Equal(1, mentionsWithShiftkey.Count);
var mentionsWithHaacked = await _issuesClient.GetAllForRepository(owner, _repository.Name,
var mentionsWithHaacked = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name,
new RepositoryIssueRequest { Mentioned = "haacked" });
Assert.Equal(0, mentionsWithHaacked.Count);
@@ -241,34 +241,34 @@ public class IssuesClientTests : IDisposable
[IntegrationTest]
public async Task FilteringByInvalidAccountThrowsError()
{
var owner = _repository.Owner.Login;
var owner = _context.Repository.Owner.Login;
await Assert.ThrowsAsync<ApiValidationException>(
() => _issuesClient.GetAllForRepository(owner, _repository.Name,
() => _issuesClient.GetAllForRepository(owner, _context.Repository.Name,
new RepositoryIssueRequest { Assignee = "some-random-account" }));
}
[IntegrationTest]
public async Task CanAssignAndUnassignMilestone()
{
var owner = _repository.Owner.Login;
var owner = _context.Repository.Owner.Login;
var newMilestone = new NewMilestone("a milestone");
var milestone = await _issuesClient.Milestone.Create(owner, _repository.Name, newMilestone);
var milestone = await _issuesClient.Milestone.Create(owner, _context.Repository.Name, newMilestone);
var newIssue1 = new NewIssue("A test issue1")
{
Body = "A new unassigned issue",
Milestone = milestone.Number
};
var issue = await _issuesClient.Create(owner, _repository.Name, newIssue1);
var issue = await _issuesClient.Create(owner, _context.Repository.Name, newIssue1);
Assert.NotNull(issue.Milestone);
var issueUpdate = issue.ToUpdate();
issueUpdate.Milestone = null;
var updatedIssue = await _issuesClient.Update(owner, _repository.Name, issue.Number, issueUpdate);
var updatedIssue = await _issuesClient.Update(owner, _context.Repository.Name, issue.Number, issueUpdate);
Assert.Null(updatedIssue.Milestone);
}
@@ -276,9 +276,9 @@ public class IssuesClientTests : IDisposable
[IntegrationTest]
public async Task DoesNotChangeLabelsByDefault()
{
var owner = _repository.Owner.Login;
var owner = _context.Repository.Owner.Login;
await _issuesClient.Labels.Create(owner, _repository.Name, new NewLabel("something", "FF0000"));
await _issuesClient.Labels.Create(owner, _context.Repository.Name, new NewLabel("something", "FF0000"));
var newIssue = new NewIssue("A test issue1")
{
@@ -286,11 +286,11 @@ public class IssuesClientTests : IDisposable
};
newIssue.Labels.Add("something");
var issue = await _issuesClient.Create(owner, _repository.Name, newIssue);
var issue = await _issuesClient.Create(owner, _context.Repository.Name, newIssue);
var issueUpdate = issue.ToUpdate();
var updatedIssue = await _issuesClient.Update(owner, _repository.Name, issue.Number, issueUpdate);
var updatedIssue = await _issuesClient.Update(owner, _context.Repository.Name, issue.Number, issueUpdate);
Assert.Equal(1, updatedIssue.Labels.Count);
}
@@ -298,11 +298,11 @@ public class IssuesClientTests : IDisposable
[IntegrationTest]
public async Task CanUpdateLabelForAnIssue()
{
var owner = _repository.Owner.Login;
var owner = _context.Repository.Owner.Login;
// create some labels
await _issuesClient.Labels.Create(owner, _repository.Name, new NewLabel("something", "FF0000"));
await _issuesClient.Labels.Create(owner, _repository.Name, new NewLabel("another thing", "0000FF"));
await _issuesClient.Labels.Create(owner, _context.Repository.Name, new NewLabel("something", "FF0000"));
await _issuesClient.Labels.Create(owner, _context.Repository.Name, new NewLabel("another thing", "0000FF"));
// setup us the issue
var newIssue = new NewIssue("A test issue1")
@@ -311,13 +311,13 @@ public class IssuesClientTests : IDisposable
};
newIssue.Labels.Add("something");
var issue = await _issuesClient.Create(owner, _repository.Name, newIssue);
var issue = await _issuesClient.Create(owner, _context.Repository.Name, newIssue);
// update the issue
var issueUpdate = issue.ToUpdate();
issueUpdate.AddLabel("another thing");
var updatedIssue = await _issuesClient.Update(owner, _repository.Name, issue.Number, issueUpdate);
var updatedIssue = await _issuesClient.Update(owner, _context.Repository.Name, issue.Number, issueUpdate);
Assert.Equal("another thing", updatedIssue.Labels[0].Name);
}
@@ -325,11 +325,11 @@ public class IssuesClientTests : IDisposable
[IntegrationTest]
public async Task CanClearLabelsForAnIssue()
{
var owner = _repository.Owner.Login;
var owner = _context.Repository.Owner.Login;
// create some labels
await _issuesClient.Labels.Create(owner, _repository.Name, new NewLabel("something", "FF0000"));
await _issuesClient.Labels.Create(owner, _repository.Name, new NewLabel("another thing", "0000FF"));
await _issuesClient.Labels.Create(owner, _context.Repository.Name, new NewLabel("something", "FF0000"));
await _issuesClient.Labels.Create(owner, _context.Repository.Name, new NewLabel("another thing", "0000FF"));
// setup us the issue
var newIssue = new NewIssue("A test issue1")
@@ -339,14 +339,14 @@ public class IssuesClientTests : IDisposable
newIssue.Labels.Add("something");
newIssue.Labels.Add("another thing");
var issue = await _issuesClient.Create(owner, _repository.Name, newIssue);
var issue = await _issuesClient.Create(owner, _context.Repository.Name, newIssue);
Assert.Equal(2, issue.Labels.Count);
// update the issue
var issueUpdate = issue.ToUpdate();
issueUpdate.ClearLabels();
var updatedIssue = await _issuesClient.Update(owner, _repository.Name, issue.Number, issueUpdate);
var updatedIssue = await _issuesClient.Update(owner, _context.Repository.Name, issue.Number, issueUpdate);
Assert.Empty(updatedIssue.Labels);
}
@@ -355,23 +355,23 @@ public class IssuesClientTests : IDisposable
public async Task CanAccessUrls()
{
var expctedUri = "https://api.github.com/repos/{0}/{1}/issues/{2}/{3}";
var owner = _repository.Owner.Login;
var owner = _context.Repository.Owner.Login;
var newIssue = new NewIssue("A test issue")
{
Body = "A new unassigned issue",
};
var issue = await _issuesClient.Create(owner, _repository.Name, newIssue);
var issue = await _issuesClient.Create(owner, _context.Repository.Name, newIssue);
Assert.NotNull(issue.CommentsUrl);
Assert.Equal(new Uri(string.Format(expctedUri, owner, _repository.Name, issue.Number, "comments")), issue.CommentsUrl);
Assert.Equal(new Uri(string.Format(expctedUri, owner, _context.Repository.Name, issue.Number, "comments")), issue.CommentsUrl);
Assert.NotNull(issue.EventsUrl);
Assert.Equal(new Uri(string.Format(expctedUri, owner, _repository.Name, issue.Number, "events")), issue.EventsUrl);
Assert.Equal(new Uri(string.Format(expctedUri, owner, _context.Repository.Name, issue.Number, "events")), issue.EventsUrl);
}
public void Dispose()
{
Helper.DeleteRepo(_repository);
_context.Dispose();
}
}

View File

@@ -5,27 +5,27 @@ using System.Threading.Tasks;
using Octokit;
using Octokit.Tests.Integration;
using Xunit;
using Octokit.Tests.Integration.Helpers;
public class IssuesEventsClientTests : IDisposable
{
readonly IGitHubClient _gitHubClient;
readonly IIssuesEventsClient _issuesEventsClientClient;
readonly IIssuesClient _issuesClient;
readonly Repository _repository;
readonly string _repositoryOwner;
readonly string _repositoryName;
private readonly IIssuesEventsClient _issuesEventsClientClient;
private readonly IIssuesClient _issuesClient;
private readonly RepositoryContext _context;
private readonly string _repositoryOwner;
private readonly string _repositoryName;
public IssuesEventsClientTests()
{
_gitHubClient = Helper.GetAuthenticatedClient();
var github = Helper.GetAuthenticatedClient();
_issuesEventsClientClient = _gitHubClient.Issue.Events;
_issuesClient = _gitHubClient.Issue;
_issuesEventsClientClient = github.Issue.Events;
_issuesClient = github.Issue;
var repoName = Helper.MakeNameWithTimestamp("public-repo");
_repository = _gitHubClient.Repository.Create(new NewRepository(repoName)).Result;
_repositoryOwner = _repository.Owner.Login;
_repositoryName = _repository.Name;
_context = github.CreateRepositoryContext(new NewRepository(repoName)).Result;
_repositoryOwner = _context.Repository.Owner.Login;
_repositoryName = _context.Repository.Name;
}
[IntegrationTest]
@@ -37,7 +37,7 @@ public class IssuesEventsClientTests : IDisposable
var issueEventInfo = await _issuesEventsClientClient.GetAllForIssue(_repositoryOwner, _repositoryName, issue.Number);
Assert.Empty(issueEventInfo);
var closed = _issuesClient.Update(_repositoryOwner, _repository.Name, issue.Number, new IssueUpdate { State = ItemState.Closed })
var closed = _issuesClient.Update(_repositoryOwner, _context.Repository.Name, issue.Number, new IssueUpdate { State = ItemState.Closed })
.Result;
Assert.NotNull(closed);
issueEventInfo = await _issuesEventsClientClient.GetAllForIssue(_repositoryOwner, _repositoryName, issue.Number);
@@ -52,22 +52,22 @@ public class IssuesEventsClientTests : IDisposable
// create 2 new issues
var newIssue1 = new NewIssue("A test issue1") { Body = "Everything's coming up Millhouse" };
var newIssue2 = new NewIssue("A test issue2") { Body = "A new unassigned issue" };
var issue1 = await _issuesClient.Create(_repositoryOwner, _repository.Name, newIssue1);
var issue1 = await _issuesClient.Create(_repositoryOwner, _context.Repository.Name, newIssue1);
Thread.Sleep(1000);
var issue2 = await _issuesClient.Create(_repositoryOwner, _repository.Name, newIssue2);
var issue2 = await _issuesClient.Create(_repositoryOwner, _context.Repository.Name, newIssue2);
Thread.Sleep(1000);
// close and open issue1
var closed1 = _issuesClient.Update(_repositoryOwner, _repository.Name, issue1.Number,new IssueUpdate { State = ItemState.Closed })
var closed1 = _issuesClient.Update(_repositoryOwner, _context.Repository.Name, issue1.Number, new IssueUpdate { State = ItemState.Closed })
.Result;
Assert.NotNull(closed1);
var reopened1 = _issuesClient.Update(_repositoryOwner, _repository.Name, issue1.Number, new IssueUpdate { State = ItemState.Open })
var reopened1 = _issuesClient.Update(_repositoryOwner, _context.Repository.Name, issue1.Number, new IssueUpdate { State = ItemState.Open })
.Result;
Assert.NotNull(reopened1);
// close issue2
var closed2 = _issuesClient.Update(_repositoryOwner, _repository.Name, issue2.Number, new IssueUpdate { State = ItemState.Closed })
var closed2 = _issuesClient.Update(_repositoryOwner, _context.Repository.Name, issue2.Number, new IssueUpdate { State = ItemState.Closed })
.Result;
Assert.NotNull(closed2);
@@ -82,7 +82,7 @@ public class IssuesEventsClientTests : IDisposable
{
var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" };
var issue = await _issuesClient.Create(_repositoryOwner, _repositoryName, newIssue);
var closed = _issuesClient.Update(_repositoryOwner, _repository.Name, issue.Number, new IssueUpdate { State = ItemState.Closed })
var closed = _issuesClient.Update(_repositoryOwner, _context.Repository.Name, issue.Number, new IssueUpdate { State = ItemState.Closed })
.Result;
Assert.NotNull(closed);
var issueEvents = await _issuesEventsClientClient.GetAllForRepository(_repositoryOwner, _repositoryName);
@@ -104,6 +104,6 @@ public class IssuesEventsClientTests : IDisposable
public void Dispose()
{
Helper.DeleteRepo(_repository);
_context.Dispose();
}
}

View File

@@ -74,7 +74,7 @@ namespace Octokit.Tests.Integration.Clients
var fixture = client.Repository.Content;
var repoName = Helper.MakeNameWithTimestamp("source-repo");
using(var context = await client.CreateRepositoryContext(new NewRepository(repoName) { AutoInit = true }))
using (var context = await client.CreateRepositoryContext(new NewRepository(repoName) { AutoInit = true }))
{
var repository = context.Repository;