From 847cd1b2c88d9b70b3561766d35f848c69134f28 Mon Sep 17 00:00:00 2001 From: William Barbosa Date: Sun, 27 Sep 2015 00:38:52 -0300 Subject: [PATCH] Adds common properties to RepositoryContext A lot of classes use the name and the owner of the repository, so for consistency I added those as properties of the Context --- .../Clients/AssigneesClientTests.cs | 14 +- .../Clients/AuthorizationClientTests.cs | 52 +++--- .../Clients/BlobClientTests.cs | 24 ++- .../Clients/CommitStatusClientTests.cs | 54 +++--- .../Clients/CommitsClientTests.cs | 10 +- .../Clients/DeploymentStatusClientTests.cs | 16 +- .../Clients/DeploymentsClientTests.cs | 14 +- .../Clients/GistsClientTests.cs | 4 +- .../Clients/IssuesClientTests.cs | 157 ++++++++---------- .../Clients/IssuesEventsClientTests.cs | 32 ++-- .../Helpers/RepositoryContext.cs | 5 + 11 files changed, 175 insertions(+), 207 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/AssigneesClientTests.cs b/Octokit.Tests.Integration/Clients/AssigneesClientTests.cs index 04a2a529..9869c24e 100644 --- a/Octokit.Tests.Integration/Clients/AssigneesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/AssigneesClientTests.cs @@ -7,29 +7,27 @@ using Xunit; public class AssigneesClientTests { - readonly IGitHubClient _gitHubClient; + readonly IGitHubClient _github; readonly RepositoryContext _context; - readonly string _owner; public AssigneesClientTests() { - _gitHubClient = Helper.GetAuthenticatedClient(); + _github = Helper.GetAuthenticatedClient(); var repoName = Helper.MakeNameWithTimestamp("public-repo"); - _context = _gitHubClient.CreateRepositoryContext(new NewRepository(repoName)).Result; - _owner = _context.Repository.Owner.Login; + _context = _github.CreateRepositoryContext(new NewRepository(repoName)).Result; } [IntegrationTest] public async Task CanCheckAssignees() { var isAssigned = await - _gitHubClient.Issue.Assignee.CheckAssignee(_owner, _context.Repository.Name, "FakeHaacked"); + _github.Issue.Assignee.CheckAssignee(_context.RepositoryOwner, _context.RepositoryName, "FakeHaacked"); Assert.False(isAssigned); // Repository owner is always an assignee isAssigned = await - _gitHubClient.Issue.Assignee.CheckAssignee(_owner, _context.Repository.Name, _owner); + _github.Issue.Assignee.CheckAssignee(_context.RepositoryOwner, _context.RepositoryName, _context.RepositoryOwner); Assert.True(isAssigned); } @@ -37,7 +35,7 @@ public class AssigneesClientTests public async Task CanListAssignees() { // Repository owner is always an assignee - var assignees = await _gitHubClient.Issue.Assignee.GetAllForRepository(_owner, _context.Repository.Name); + var assignees = await _github.Issue.Assignee.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName); Assert.True(assignees.Any(u => u.Login == Helper.UserName)); } } \ No newline at end of file diff --git a/Octokit.Tests.Integration/Clients/AuthorizationClientTests.cs b/Octokit.Tests.Integration/Clients/AuthorizationClientTests.cs index 2c9a018c..213326e1 100644 --- a/Octokit.Tests.Integration/Clients/AuthorizationClientTests.cs +++ b/Octokit.Tests.Integration/Clients/AuthorizationClientTests.cs @@ -10,14 +10,14 @@ namespace Octokit.Tests.Integration.Clients [ApplicationTest] public async Task CanCreateAndGetAuthorizationWithoutFingerPrint() { - var client = Helper.GetAuthenticatedClient(); + var github = Helper.GetAuthenticatedClient(); var note = Helper.MakeNameWithTimestamp("Testing authentication"); var newAuthorization = new NewAuthorization( note, new[] { "user" }); // the first call will create the authorization - var created = await client.Authorization.GetOrCreateApplicationAuthentication( + var created = await github.Authorization.GetOrCreateApplicationAuthentication( Helper.ClientId, Helper.ClientSecret, newAuthorization); @@ -27,14 +27,14 @@ namespace Octokit.Tests.Integration.Clients Assert.False(String.IsNullOrWhiteSpace(created.HashedToken)); // we can then query it through the regular API - var get = await client.Authorization.Get(created.Id); + var get = await github.Authorization.Get(created.Id); Assert.Equal(created.Id, get.Id); Assert.Equal(created.Note, get.Note); // but the second time we call this API we get // a different set of data - var getExisting = await client.Authorization.GetOrCreateApplicationAuthentication( + var getExisting = await github.Authorization.GetOrCreateApplicationAuthentication( Helper.ClientId, Helper.ClientSecret, newAuthorization); @@ -47,13 +47,13 @@ namespace Octokit.Tests.Integration.Clients Assert.False(String.IsNullOrWhiteSpace(getExisting.TokenLastEight)); Assert.False(String.IsNullOrWhiteSpace(getExisting.HashedToken)); - await client.Authorization.Delete(created.Id); + await github.Authorization.Delete(created.Id); } [ApplicationTest] public async Task CanCreateAndGetAuthorizationByFingerprint() { - var client = Helper.GetAuthenticatedClient(); + var github = Helper.GetAuthenticatedClient(); var fingerprint = Helper.MakeNameWithTimestamp("authorization-testing"); var note = Helper.MakeNameWithTimestamp("Testing authentication"); var newAuthorization = new NewAuthorization( @@ -61,7 +61,7 @@ namespace Octokit.Tests.Integration.Clients new[] { "user" }, fingerprint); - var created = await client.Authorization.GetOrCreateApplicationAuthentication( + var created = await github.Authorization.GetOrCreateApplicationAuthentication( Helper.ClientId, Helper.ClientSecret, newAuthorization); @@ -70,14 +70,14 @@ namespace Octokit.Tests.Integration.Clients Assert.False(String.IsNullOrWhiteSpace(created.Token)); // we can then query it through the regular API - var get = await client.Authorization.Get(created.Id); + var get = await github.Authorization.Get(created.Id); Assert.Equal(created.Id, get.Id); Assert.Equal(created.Note, get.Note); // but the second time we call this API we get // a different set of data - var getExisting = await client.Authorization.GetOrCreateApplicationAuthentication( + var getExisting = await github.Authorization.GetOrCreateApplicationAuthentication( Helper.ClientId, Helper.ClientSecret, newAuthorization); @@ -93,13 +93,13 @@ namespace Octokit.Tests.Integration.Clients Assert.False(String.IsNullOrWhiteSpace(getExisting.TokenLastEight)); Assert.False(String.IsNullOrWhiteSpace(getExisting.HashedToken)); - await client.Authorization.Delete(created.Id); + await github.Authorization.Delete(created.Id); } [ApplicationTest] public async Task CanCheckApplicationAuthentication() { - var client = Helper.GetAuthenticatedClient(); + var github = Helper.GetAuthenticatedClient(); var fingerprint = Helper.MakeNameWithTimestamp("authorization-testing"); var note = Helper.MakeNameWithTimestamp("Testing authentication"); var newAuthorization = new NewAuthorization( @@ -107,7 +107,7 @@ namespace Octokit.Tests.Integration.Clients new[] { "user" }, fingerprint); - var created = await client.Authorization.GetOrCreateApplicationAuthentication( + var created = await github.Authorization.GetOrCreateApplicationAuthentication( Helper.ClientId, Helper.ClientSecret, newAuthorization); @@ -118,14 +118,14 @@ namespace Octokit.Tests.Integration.Clients Assert.NotNull(applicationAuthorization); Assert.Equal(created.Token, applicationAuthorization.Token); - await client.Authorization.Delete(created.Id); - Assert.ThrowsAsync(() => client.Authorization.Get(created.Id)); + await github.Authorization.Delete(created.Id); + Assert.ThrowsAsync(() => github.Authorization.Get(created.Id)); } [ApplicationTest] public async Task CanResetApplicationAuthentication() { - var client = Helper.GetAuthenticatedClient(); + var github = Helper.GetAuthenticatedClient(); var fingerprint = Helper.MakeNameWithTimestamp("authorization-testing"); var note = Helper.MakeNameWithTimestamp("Testing authentication"); var newAuthorization = new NewAuthorization( @@ -133,7 +133,7 @@ namespace Octokit.Tests.Integration.Clients new[] { "user" }, fingerprint); - var created = await client.Authorization.GetOrCreateApplicationAuthentication( + var created = await github.Authorization.GetOrCreateApplicationAuthentication( Helper.ClientId, Helper.ClientSecret, newAuthorization); @@ -144,14 +144,14 @@ namespace Octokit.Tests.Integration.Clients Assert.NotNull(applicationAuthorization); Assert.NotEqual(created.Token, applicationAuthorization.Token); - await client.Authorization.Delete(created.Id); - Assert.ThrowsAsync(() => client.Authorization.Get(created.Id)); + await github.Authorization.Delete(created.Id); + Assert.ThrowsAsync(() => github.Authorization.Get(created.Id)); } [ApplicationTest] public async Task CanRevokeApplicationAuthentication() { - var client = Helper.GetAuthenticatedClient(); + var github = Helper.GetAuthenticatedClient(); var fingerprint = Helper.MakeNameWithTimestamp("authorization-testing"); var note = Helper.MakeNameWithTimestamp("Testing authentication"); var newAuthorization = new NewAuthorization( @@ -159,7 +159,7 @@ namespace Octokit.Tests.Integration.Clients new[] { "user" }, fingerprint); - var created = await client.Authorization.GetOrCreateApplicationAuthentication( + var created = await github.Authorization.GetOrCreateApplicationAuthentication( Helper.ClientId, Helper.ClientSecret, newAuthorization); @@ -168,17 +168,17 @@ namespace Octokit.Tests.Integration.Clients await applicationClient.Authorization.RevokeApplicationAuthentication(Helper.ClientId, created.Token); Assert.ThrowsAsync(() => applicationClient.Authorization.CheckApplicationAuthentication(Helper.ClientId, created.Token)); - Assert.ThrowsAsync(() => client.Authorization.Get(created.Id)); + Assert.ThrowsAsync(() => github.Authorization.Get(created.Id)); } [ApplicationTest] public async Task CanRevokeAllApplicationAuthentications() { - var client = Helper.GetAuthenticatedClient(); + var github = Helper.GetAuthenticatedClient(); var fingerprint = Helper.MakeNameWithTimestamp("authorization-testing"); var note = Helper.MakeNameWithTimestamp("Testing authentication"); - var token1 = await client.Authorization.GetOrCreateApplicationAuthentication( + var token1 = await github.Authorization.GetOrCreateApplicationAuthentication( Helper.ClientId, Helper.ClientSecret, new NewAuthorization( @@ -188,7 +188,7 @@ namespace Octokit.Tests.Integration.Clients fingerprint = Helper.MakeNameWithTimestamp("authorization-testing-2"); note = Helper.MakeNameWithTimestamp("Testing authentication 2"); - var token2 = await client.Authorization.GetOrCreateApplicationAuthentication( + var token2 = await github.Authorization.GetOrCreateApplicationAuthentication( Helper.ClientId, Helper.ClientSecret, new NewAuthorization( @@ -204,8 +204,8 @@ namespace Octokit.Tests.Integration.Clients Assert.ThrowsAsync(async () => await applicationClient.Authorization.CheckApplicationAuthentication(Helper.ClientId, token2.Token)); - Assert.ThrowsAsync(() => client.Authorization.Get(token1.Id)); - Assert.ThrowsAsync(() => client.Authorization.Get(token2.Id)); + Assert.ThrowsAsync(() => github.Authorization.Get(token1.Id)); + Assert.ThrowsAsync(() => github.Authorization.Get(token2.Id)); } } } diff --git a/Octokit.Tests.Integration/Clients/BlobClientTests.cs b/Octokit.Tests.Integration/Clients/BlobClientTests.cs index 2d382730..7b82bba9 100644 --- a/Octokit.Tests.Integration/Clients/BlobClientTests.cs +++ b/Octokit.Tests.Integration/Clients/BlobClientTests.cs @@ -8,17 +8,15 @@ using Octokit.Tests.Integration.Helpers; public class BlobClientTests : IDisposable { - readonly IBlobsClient _fixture; - readonly RepositoryContext _context; - readonly string _owner; + private readonly IBlobsClient _fixture; + private readonly RepositoryContext _context; public BlobClientTests() { - var client = Helper.GetAuthenticatedClient(); - _fixture = client.GitDatabase.Blob; + var github = Helper.GetAuthenticatedClient(); + _fixture = github.GitDatabase.Blob; - _context = client.CreateRepositoryContext("public-repo").Result; - _owner = _context.Repository.Owner.Login; + _context = github.CreateRepositoryContext("public-repo").Result; } [IntegrationTest] @@ -30,7 +28,7 @@ public class BlobClientTests : IDisposable Encoding = EncodingType.Utf8 }; - var result = await _fixture.Create(_owner, _context.Repository.Name, blob); + var result = await _fixture.Create(_context.RepositoryOwner, _context.RepositoryName, blob); Assert.False(String.IsNullOrWhiteSpace(result.Sha)); } @@ -47,7 +45,7 @@ public class BlobClientTests : IDisposable Encoding = EncodingType.Base64 }; - var result = await _fixture.Create(_owner, _context.Repository.Name, blob); + var result = await _fixture.Create(_context.RepositoryOwner, _context.RepositoryName, blob); Assert.False(String.IsNullOrWhiteSpace(result.Sha)); } @@ -61,8 +59,8 @@ public class BlobClientTests : IDisposable Encoding = EncodingType.Utf8 }; - var result = await _fixture.Create(_owner, _context.Repository.Name, newBlob); - var blob = await _fixture.Get(_owner, _context.Repository.Name, result.Sha); + var result = await _fixture.Create(_context.RepositoryOwner, _context.RepositoryName, newBlob); + var blob = await _fixture.Get(_context.RepositoryOwner, _context.RepositoryName, result.Sha); Assert.Equal(result.Sha, blob.Sha); Assert.Equal(EncodingType.Base64, blob.Encoding); @@ -84,8 +82,8 @@ public class BlobClientTests : IDisposable Encoding = EncodingType.Base64 }; - var result = await _fixture.Create(_owner, _context.Repository.Name, newBlob); - var blob = await _fixture.Get(_owner, _context.Repository.Name, result.Sha); + var result = await _fixture.Create(_context.RepositoryOwner, _context.RepositoryName, newBlob); + var blob = await _fixture.Get(_context.RepositoryOwner, _context.RepositoryName, result.Sha); Assert.Equal(result.Sha, blob.Sha); Assert.Equal(EncodingType.Base64, blob.Encoding); diff --git a/Octokit.Tests.Integration/Clients/CommitStatusClientTests.cs b/Octokit.Tests.Integration/Clients/CommitStatusClientTests.cs index cf912df3..a3fe99c0 100644 --- a/Octokit.Tests.Integration/Clients/CommitStatusClientTests.cs +++ b/Octokit.Tests.Integration/Clients/CommitStatusClientTests.cs @@ -16,8 +16,8 @@ public class CommitStatusClientTests // Figured it was easier to grab the public status of a public repository for now than // to go through the rigamarole of creating it all. But ideally, that's exactly what we'd do. - var githubClient = Helper.GetAuthenticatedClient(); - var statuses = await githubClient.Repository.CommitStatus.GetAll( + var github = Helper.GetAuthenticatedClient(); + var statuses = await github.Repository.CommitStatus.GetAll( "rails", "rails", "94b857899506612956bb542e28e292308accb908"); @@ -32,8 +32,8 @@ public class CommitStatusClientTests [IntegrationTest] public async Task CanRetrieveCombinedStatus() { - var githubClient = Helper.GetAuthenticatedClient(); - var status = await githubClient.Repository.CommitStatus.GetCombined( + var github = Helper.GetAuthenticatedClient(); + var status = await github.Repository.CommitStatus.GetCombined( "libgit2", "libgit2sharp", "f54529997b6ad841be524654d9e9074ab8e7d41d"); @@ -48,22 +48,20 @@ public class CommitStatusClientTests public class TheCreateMethod : IDisposable { - private readonly IGitHubClient _client; + private readonly IGitHubClient _github; private readonly RepositoryContext _context; - private readonly string _owner; public TheCreateMethod() { - _client = Helper.GetAuthenticatedClient(); + _github = Helper.GetAuthenticatedClient(); - _context = _client.CreateRepositoryContext("public-repo").Result; - _owner = _context.Repository.Owner.Login; + _context = _github.CreateRepositoryContext("public-repo").Result; } [IntegrationTest] public async Task CanAssignPendingToCommit() { - var commit = await SetupCommitForRepository(_client); + var commit = await SetupCommitForRepository(_github); var status = new NewCommitStatus { @@ -71,7 +69,7 @@ public class CommitStatusClientTests Description = "this is a test status" }; - var result = await _client.Repository.CommitStatus.Create(_owner, _context.Repository.Name, commit.Sha, status); + var result = await _github.Repository.CommitStatus.Create(_context.RepositoryOwner, _context.RepositoryName, commit.Sha, status); Assert.Equal(CommitState.Pending, result.State); } @@ -79,7 +77,7 @@ public class CommitStatusClientTests [IntegrationTest] public async Task CanRetrievePendingStatus() { - var commit = await SetupCommitForRepository(_client); + var commit = await SetupCommitForRepository(_github); var status = new NewCommitStatus { @@ -87,9 +85,9 @@ public class CommitStatusClientTests Description = "this is a test status" }; - await _client.Repository.CommitStatus.Create(_owner, _context.Repository.Name, commit.Sha, status); + await _github.Repository.CommitStatus.Create(_context.RepositoryOwner, _context.RepositoryName, commit.Sha, status); - var statuses = await _client.Repository.CommitStatus.GetAll(_owner, _context.Repository.Name, commit.Sha); + var statuses = await _github.Repository.CommitStatus.GetAll(_context.RepositoryOwner, _context.RepositoryName, commit.Sha); Assert.Equal(1, statuses.Count); Assert.Equal(CommitState.Pending, statuses[0].State); @@ -98,7 +96,7 @@ public class CommitStatusClientTests [IntegrationTest] public async Task CanUpdatePendingStatusToSuccess() { - var commit = await SetupCommitForRepository(_client); + var commit = await SetupCommitForRepository(_github); var status = new NewCommitStatus { @@ -106,13 +104,13 @@ public class CommitStatusClientTests Description = "this is a test status" }; - await _client.Repository.CommitStatus.Create(_owner, _context.Repository.Name, commit.Sha, status); + await _github.Repository.CommitStatus.Create(_context.RepositoryOwner, _context.RepositoryName, commit.Sha, status); status.State = CommitState.Success; - await _client.Repository.CommitStatus.Create(_owner, _context.Repository.Name, commit.Sha, status); + await _github.Repository.CommitStatus.Create(_context.RepositoryOwner, _context.RepositoryName, commit.Sha, status); - var statuses = await _client.Repository.CommitStatus.GetAll(_owner, _context.Repository.Name, commit.Sha); + var statuses = await _github.Repository.CommitStatus.GetAll(_context.RepositoryOwner, _context.RepositoryName, commit.Sha); Assert.Equal(2, statuses.Count); Assert.Equal(CommitState.Success, statuses[0].State); @@ -121,7 +119,7 @@ public class CommitStatusClientTests [IntegrationTest] public async Task CanProvideACommitStatusWithoutRequiringAContext() { - var commit = await SetupCommitForRepository(_client); + var commit = await SetupCommitForRepository(_github); var status = new NewCommitStatus { @@ -129,9 +127,9 @@ public class CommitStatusClientTests Description = "this is a test status" }; - await _client.Repository.CommitStatus.Create(_owner, _context.Repository.Name, commit.Sha, status); + await _github.Repository.CommitStatus.Create(_context.RepositoryOwner, _context.RepositoryName, commit.Sha, status); - var statuses = await _client.Repository.CommitStatus.GetAll(_owner, _context.Repository.Name, commit.Sha); + var statuses = await _github.Repository.CommitStatus.GetAll(_context.RepositoryOwner, _context.RepositoryName, commit.Sha); Assert.Equal(1, statuses.Count); Assert.Equal("default", statuses[0].Context); @@ -140,7 +138,7 @@ public class CommitStatusClientTests [IntegrationTest] public async Task CanCreateStatusesForDifferentContexts() { - var commit = await SetupCommitForRepository(_client); + var commit = await SetupCommitForRepository(_github); var status = new NewCommitStatus { @@ -149,13 +147,13 @@ public class CommitStatusClientTests Context = "System A" }; - await _client.Repository.CommitStatus.Create(_owner, _context.Repository.Name, commit.Sha, status); + await _github.Repository.CommitStatus.Create(_context.RepositoryOwner, _context.RepositoryName, commit.Sha, status); status.Context = "System B"; - await _client.Repository.CommitStatus.Create(_owner, _context.Repository.Name, commit.Sha, status); + await _github.Repository.CommitStatus.Create(_context.RepositoryOwner, _context.RepositoryName, commit.Sha, status); - var statuses = await _client.Repository.CommitStatus.GetAll(_owner, _context.Repository.Name, commit.Sha); + var statuses = await _github.Repository.CommitStatus.GetAll(_context.RepositoryOwner, _context.RepositoryName, commit.Sha); Assert.Equal(2, statuses.Count); Assert.Equal("System B", statuses[0].Context); @@ -169,7 +167,7 @@ public class CommitStatusClientTests Content = "Hello World!", Encoding = EncodingType.Utf8 }; - var blobResult = await client.GitDatabase.Blob.Create(_owner, _context.Repository.Name, blob); + var blobResult = await client.GitDatabase.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, blob); var newTree = new NewTree(); newTree.Tree.Add(new NewTreeItem @@ -180,11 +178,11 @@ public class CommitStatusClientTests Sha = blobResult.Sha }); - var treeResult = await client.GitDatabase.Tree.Create(_owner, _context.Repository.Name, newTree); + var treeResult = await client.GitDatabase.Tree.Create(_context.RepositoryOwner, _context.RepositoryName, newTree); var newCommit = new NewCommit("test-commit", treeResult.Sha); - return await client.GitDatabase.Commit.Create(_owner, _context.Repository.Name, newCommit); + return await client.GitDatabase.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit); } public void Dispose() diff --git a/Octokit.Tests.Integration/Clients/CommitsClientTests.cs b/Octokit.Tests.Integration/Clients/CommitsClientTests.cs index ba268659..2e781c87 100644 --- a/Octokit.Tests.Integration/Clients/CommitsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/CommitsClientTests.cs @@ -12,10 +12,10 @@ public class CommitsClientTests [IntegrationTest] public async Task CanCreateAndRetrieveCommit() { - var client = Helper.GetAuthenticatedClient(); - var fixture = client.GitDatabase.Commit; + var github = Helper.GetAuthenticatedClient(); + var fixture = github.GitDatabase.Commit; - using (var context = await client.CreateRepositoryContext("public-repo")) + using (var context = await github.CreateRepositoryContext("public-repo")) { var owner = context.Repository.Owner.Login; @@ -24,7 +24,7 @@ public class CommitsClientTests Content = "Hello World!", Encoding = EncodingType.Utf8 }; - var blobResult = await client.GitDatabase.Blob.Create(owner, context.Repository.Name, blob); + var blobResult = await github.GitDatabase.Blob.Create(owner, context.Repository.Name, blob); var newTree = new NewTree(); newTree.Tree.Add(new NewTreeItem @@ -35,7 +35,7 @@ public class CommitsClientTests Sha = blobResult.Sha }); - var treeResult = await client.GitDatabase.Tree.Create(owner, context.Repository.Name, newTree); + var treeResult = await github.GitDatabase.Tree.Create(owner, context.Repository.Name, newTree); var newCommit = new NewCommit("test-commit", treeResult.Sha); diff --git a/Octokit.Tests.Integration/Clients/DeploymentStatusClientTests.cs b/Octokit.Tests.Integration/Clients/DeploymentStatusClientTests.cs index efd9cd4a..d00bc586 100644 --- a/Octokit.Tests.Integration/Clients/DeploymentStatusClientTests.cs +++ b/Octokit.Tests.Integration/Clients/DeploymentStatusClientTests.cs @@ -11,7 +11,6 @@ public class DeploymentStatusClientTests : IDisposable private readonly RepositoryContext _context; private readonly Commit _commit; private readonly Deployment _deployment; - private readonly string _repositoryOwner; public DeploymentStatusClientTests() { @@ -19,7 +18,6 @@ public class DeploymentStatusClientTests : IDisposable _deploymentsClient = github.Repository.Deployment; _context = github.CreateRepositoryContext("public-repo").Result; - _repositoryOwner = _context.Repository.Owner.Login; var blob = new NewBlob { @@ -27,7 +25,7 @@ public class DeploymentStatusClientTests : IDisposable Encoding = EncodingType.Utf8 }; - var blobResult = github.GitDatabase.Blob.Create(_repositoryOwner, _context.Repository.Name, blob).Result; + var blobResult = github.GitDatabase.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, blob).Result; var newTree = new NewTree(); newTree.Tree.Add(new NewTreeItem @@ -38,12 +36,12 @@ public class DeploymentStatusClientTests : IDisposable Sha = blobResult.Sha }); - var treeResult = github.GitDatabase.Tree.Create(_repositoryOwner, _context.Repository.Name, newTree).Result; + var treeResult = github.GitDatabase.Tree.Create(_context.RepositoryOwner, _context.RepositoryName, newTree).Result; var newCommit = new NewCommit("test-commit", treeResult.Sha); - _commit = github.GitDatabase.Commit.Create(_repositoryOwner, _context.Repository.Name, newCommit).Result; + _commit = github.GitDatabase.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit).Result; var newDeployment = new NewDeployment { Ref = _commit.Sha, AutoMerge = false }; - _deployment = _deploymentsClient.Create(_repositoryOwner, _context.Repository.Name, newDeployment).Result; + _deployment = _deploymentsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newDeployment).Result; } [IntegrationTest] @@ -51,7 +49,7 @@ public class DeploymentStatusClientTests : IDisposable { var newStatus = new NewDeploymentStatus { State = DeploymentState.Success }; - var status = await _deploymentsClient.Status.Create(_repositoryOwner, _context.Repository.Name, _deployment.Id, newStatus); + var status = await _deploymentsClient.Status.Create(_context.RepositoryOwner, _context.RepositoryName, _deployment.Id, newStatus); Assert.NotNull(status); Assert.Equal(DeploymentState.Success, status.State); @@ -61,9 +59,9 @@ public class DeploymentStatusClientTests : IDisposable public async Task CanReadDeploymentStatuses() { var newStatus = new NewDeploymentStatus { State = DeploymentState.Success }; - await _deploymentsClient.Status.Create(_repositoryOwner, _context.Repository.Name, _deployment.Id, newStatus); + await _deploymentsClient.Status.Create(_context.RepositoryOwner, _context.RepositoryName, _deployment.Id, newStatus); - var statuses = await _deploymentsClient.Status.GetAll(_repositoryOwner, _context.Repository.Name, _deployment.Id); + var statuses = await _deploymentsClient.Status.GetAll(_context.RepositoryOwner, _context.RepositoryName, _deployment.Id); Assert.NotEmpty(statuses); Assert.Equal(DeploymentState.Success, statuses[0].State); diff --git a/Octokit.Tests.Integration/Clients/DeploymentsClientTests.cs b/Octokit.Tests.Integration/Clients/DeploymentsClientTests.cs index e16dc73f..c07090d9 100644 --- a/Octokit.Tests.Integration/Clients/DeploymentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/DeploymentsClientTests.cs @@ -10,7 +10,6 @@ public class DeploymentsClientTests : IDisposable private readonly IDeploymentsClient _deploymentsClient; private readonly RepositoryContext _context; private readonly Commit _commit; - private readonly string _repositoryOwner; public DeploymentsClientTests() { @@ -18,7 +17,6 @@ public class DeploymentsClientTests : IDisposable _deploymentsClient = github.Repository.Deployment; _context = github.CreateRepositoryContext("public-repo").Result; - _repositoryOwner = _context.Repository.Owner.Login; var blob = new NewBlob { @@ -26,7 +24,7 @@ public class DeploymentsClientTests : IDisposable Encoding = EncodingType.Utf8 }; - var blobResult = github.GitDatabase.Blob.Create(_repositoryOwner, _context.Repository.Name, blob).Result; + var blobResult = github.GitDatabase.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, blob).Result; var newTree = new NewTree(); newTree.Tree.Add(new NewTreeItem @@ -37,9 +35,9 @@ public class DeploymentsClientTests : IDisposable Sha = blobResult.Sha }); - var treeResult = github.GitDatabase.Tree.Create(_repositoryOwner, _context.Repository.Name, newTree).Result; + var treeResult = github.GitDatabase.Tree.Create(_context.RepositoryOwner, _context.RepositoryName, newTree).Result; var newCommit = new NewCommit("test-commit", treeResult.Sha); - _commit = github.GitDatabase.Commit.Create(_repositoryOwner, _context.Repository.Name, newCommit).Result; + _commit = github.GitDatabase.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit).Result; } [IntegrationTest] @@ -47,7 +45,7 @@ public class DeploymentsClientTests : IDisposable { var newDeployment = new NewDeployment { Ref = _commit.Sha, AutoMerge = false }; - var deployment = await _deploymentsClient.Create(_repositoryOwner, _context.Repository.Name, newDeployment); + var deployment = await _deploymentsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newDeployment); Assert.NotNull(deployment); } @@ -56,9 +54,9 @@ public class DeploymentsClientTests : IDisposable public async Task CanGetDeployments() { var newDeployment = new NewDeployment { Ref = _commit.Sha, AutoMerge = false }; - await _deploymentsClient.Create(_repositoryOwner, _context.Repository.Name, newDeployment); + await _deploymentsClient.Create(_context.RepositoryOwner, _context.RepositoryName, newDeployment); - var deployments = await _deploymentsClient.GetAll(_repositoryOwner, _context.Repository.Name); + var deployments = await _deploymentsClient.GetAll(_context.RepositoryOwner, _context.RepositoryName); Assert.NotEmpty(deployments); } diff --git a/Octokit.Tests.Integration/Clients/GistsClientTests.cs b/Octokit.Tests.Integration/Clients/GistsClientTests.cs index 5b3c0ed0..56ef19f1 100644 --- a/Octokit.Tests.Integration/Clients/GistsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/GistsClientTests.cs @@ -13,9 +13,9 @@ public class GistsClientTests public GistsClientTests() { - var client = Helper.GetAuthenticatedClient(); + var github = Helper.GetAuthenticatedClient(); - _fixture = client.Gist; + _fixture = github.Gist; } [IntegrationTest] diff --git a/Octokit.Tests.Integration/Clients/IssuesClientTests.cs b/Octokit.Tests.Integration/Clients/IssuesClientTests.cs index aca4923b..2193a1c0 100644 --- a/Octokit.Tests.Integration/Clients/IssuesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssuesClientTests.cs @@ -25,22 +25,20 @@ public class IssuesClientTests : IDisposable [IntegrationTest] public async Task CanCreateRetrieveAndCloseIssue() { - string owner = _context.Repository.Owner.Login; - var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" }; - var issue = await _issuesClient.Create(owner, _context.Repository.Name, newIssue); + var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); try { Assert.NotNull(issue); - var retrieved = await _issuesClient.Get(owner, _context.Repository.Name, issue.Number); - var all = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name); + var retrieved = await _issuesClient.Get(_context.RepositoryOwner, _context.RepositoryName, issue.Number); + var all = await _issuesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName); Assert.NotNull(retrieved); Assert.True(all.Any(i => i.Number == retrieved.Number)); } finally { - var closed = _issuesClient.Update(owner, _context.Repository.Name, issue.Number, + var closed = _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new IssueUpdate { State = ItemState.Closed }) .Result; Assert.NotNull(closed); @@ -50,21 +48,20 @@ public class IssuesClientTests : IDisposable [IntegrationTest] public async Task CanListOpenIssuesWithDefaultSort() { - 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, _context.Repository.Name, newIssue1); + await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue1); Thread.Sleep(1000); - await _issuesClient.Create(owner, _context.Repository.Name, newIssue2); + await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, 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, + await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue3); + var closed = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue4); + await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, closed.Number, new IssueUpdate { State = ItemState.Closed }); - var issues = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name); + var issues = await _issuesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName); Assert.Equal(3, issues.Count); Assert.Equal("A test issue3", issues[0].Title); @@ -75,22 +72,20 @@ public class IssuesClientTests : IDisposable [IntegrationTest] public async Task CanListIssuesWithAscendingSort() { - 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, _context.Repository.Name, newIssue1); + await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue1); Thread.Sleep(1000); - await _issuesClient.Create(owner, _context.Repository.Name, newIssue2); + await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, 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, + await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue3); + var closed = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue4); + await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, closed.Number, new IssueUpdate { State = ItemState.Closed }); - var issues = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name, + var issues = await _issuesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, new RepositoryIssueRequest {SortDirection = SortDirection.Ascending}); Assert.Equal(3, issues.Count); @@ -102,17 +97,15 @@ public class IssuesClientTests : IDisposable [IntegrationTest] public async Task CanListClosedIssues() { - 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, _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, + await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue1); + await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue2); + var closed = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue2); + await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, closed.Number, new IssueUpdate { State = ItemState.Closed }); - var issues = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name, + var issues = await _issuesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, new RepositoryIssueRequest { State = ItemState.Closed }); Assert.Equal(1, issues.Count); @@ -122,14 +115,13 @@ public class IssuesClientTests : IDisposable [IntegrationTest] public async Task CanListMilestoneIssues() { - string owner = _context.Repository.Owner.Login; - var milestone = await _issuesClient.Milestone.Create(owner, _context.Repository.Name, new NewMilestone("milestone")); + var milestone = await _issuesClient.Milestone.Create(_context.RepositoryOwner, _context.RepositoryName, 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, _context.Repository.Name, newIssue1); - await _issuesClient.Create(owner, _context.Repository.Name, newIssue2); + await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue1); + await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue2); - var issues = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name, + var issues = await _issuesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, new RepositoryIssueRequest { Milestone = milestone.Number.ToString(CultureInfo.InvariantCulture) }); Assert.Equal(1, issues.Count); @@ -139,19 +131,18 @@ public class IssuesClientTests : IDisposable [IntegrationTest(Skip = "This is paging for a long long time")] public async Task CanRetrieveAllIssues() { - 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, _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, + var issue1 = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue1); + var issue2 = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue2); + var issue3 = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue3); + var issue4 = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue4); + await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue4.Number, new IssueUpdate { State = ItemState.Closed }); - var retrieved = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name, + var retrieved = await _issuesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, new RepositoryIssueRequest { State = ItemState.All }); Assert.True(retrieved.Count >= 4); @@ -164,24 +155,23 @@ public class IssuesClientTests : IDisposable [IntegrationTest] public async Task CanFilterByAssigned() { - var owner = _context.Repository.Owner.Login; - var newIssue1 = new NewIssue("An assigned issue") { Body = "Assigning this to myself", Assignee = owner }; + var newIssue1 = new NewIssue("An assigned issue") { Body = "Assigning this to myself", Assignee = _context.RepositoryOwner }; var newIssue2 = new NewIssue("An unassigned issue") { Body = "A new unassigned issue" }; - await _issuesClient.Create(owner, _context.Repository.Name, newIssue1); - await _issuesClient.Create(owner, _context.Repository.Name, newIssue2); + await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue1); + await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue2); - var allIssues = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name, + var allIssues = await _issuesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, new RepositoryIssueRequest()); Assert.Equal(2, allIssues.Count); - var assignedIssues = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name, - new RepositoryIssueRequest { Assignee = owner }); + var assignedIssues = await _issuesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, + new RepositoryIssueRequest { Assignee = _context.RepositoryOwner }); Assert.Equal(1, assignedIssues.Count); Assert.Equal("An assigned issue", assignedIssues[0].Title); - var unassignedIssues = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name, + var unassignedIssues = await _issuesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, new RepositoryIssueRequest { Assignee = "none" }); Assert.Equal(1, unassignedIssues.Count); @@ -191,23 +181,22 @@ public class IssuesClientTests : IDisposable [IntegrationTest] public async Task CanFilterByCreator() { - 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, _context.Repository.Name, newIssue1); - await _issuesClient.Create(owner, _context.Repository.Name, newIssue2); + await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue1); + await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue2); - var allIssues = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name, + var allIssues = await _issuesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, new RepositoryIssueRequest()); Assert.Equal(2, allIssues.Count); - var issuesCreatedByOwner = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name, - new RepositoryIssueRequest { Creator = owner }); + var issuesCreatedByOwner = await _issuesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, + new RepositoryIssueRequest { Creator = _context.RepositoryOwner }); Assert.Equal(2, issuesCreatedByOwner.Count); - var issuesCreatedByExternalUser = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name, + var issuesCreatedByExternalUser = await _issuesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, new RepositoryIssueRequest { Creator = "shiftkey" }); Assert.Equal(0, issuesCreatedByExternalUser.Count); @@ -216,23 +205,22 @@ public class IssuesClientTests : IDisposable [IntegrationTest] public async Task CanFilterByMentioned() { - 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, _context.Repository.Name, newIssue1); - await _issuesClient.Create(owner, _context.Repository.Name, newIssue2); + await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue1); + await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue2); - var allIssues = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name, + var allIssues = await _issuesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, new RepositoryIssueRequest()); Assert.Equal(2, allIssues.Count); - var mentionsWithShiftkey = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name, + var mentionsWithShiftkey = await _issuesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, new RepositoryIssueRequest { Mentioned = "shiftkey" }); Assert.Equal(1, mentionsWithShiftkey.Count); - var mentionsWithHaacked = await _issuesClient.GetAllForRepository(owner, _context.Repository.Name, + var mentionsWithHaacked = await _issuesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, new RepositoryIssueRequest { Mentioned = "haacked" }); Assert.Equal(0, mentionsWithHaacked.Count); @@ -241,34 +229,30 @@ public class IssuesClientTests : IDisposable [IntegrationTest] public async Task FilteringByInvalidAccountThrowsError() { - var owner = _context.Repository.Owner.Login; - await Assert.ThrowsAsync( - () => _issuesClient.GetAllForRepository(owner, _context.Repository.Name, + () => _issuesClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName, new RepositoryIssueRequest { Assignee = "some-random-account" })); } [IntegrationTest] public async Task CanAssignAndUnassignMilestone() { - var owner = _context.Repository.Owner.Login; - var newMilestone = new NewMilestone("a milestone"); - var milestone = await _issuesClient.Milestone.Create(owner, _context.Repository.Name, newMilestone); + var milestone = await _issuesClient.Milestone.Create(_context.RepositoryOwner, _context.RepositoryName, newMilestone); var newIssue1 = new NewIssue("A test issue1") { Body = "A new unassigned issue", Milestone = milestone.Number }; - var issue = await _issuesClient.Create(owner, _context.Repository.Name, newIssue1); + var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue1); Assert.NotNull(issue.Milestone); var issueUpdate = issue.ToUpdate(); issueUpdate.Milestone = null; - var updatedIssue = await _issuesClient.Update(owner, _context.Repository.Name, issue.Number, issueUpdate); + var updatedIssue = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate); Assert.Null(updatedIssue.Milestone); } @@ -276,9 +260,7 @@ public class IssuesClientTests : IDisposable [IntegrationTest] public async Task DoesNotChangeLabelsByDefault() { - var owner = _context.Repository.Owner.Login; - - await _issuesClient.Labels.Create(owner, _context.Repository.Name, new NewLabel("something", "FF0000")); + await _issuesClient.Labels.Create(_context.RepositoryOwner, _context.RepositoryName, new NewLabel("something", "FF0000")); var newIssue = new NewIssue("A test issue1") { @@ -286,11 +268,11 @@ public class IssuesClientTests : IDisposable }; newIssue.Labels.Add("something"); - var issue = await _issuesClient.Create(owner, _context.Repository.Name, newIssue); + var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); var issueUpdate = issue.ToUpdate(); - var updatedIssue = await _issuesClient.Update(owner, _context.Repository.Name, issue.Number, issueUpdate); + var updatedIssue = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate); Assert.Equal(1, updatedIssue.Labels.Count); } @@ -298,11 +280,9 @@ public class IssuesClientTests : IDisposable [IntegrationTest] public async Task CanUpdateLabelForAnIssue() { - var owner = _context.Repository.Owner.Login; - // create some labels - 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")); + await _issuesClient.Labels.Create(_context.RepositoryOwner, _context.RepositoryName, new NewLabel("something", "FF0000")); + await _issuesClient.Labels.Create(_context.RepositoryOwner, _context.RepositoryName, new NewLabel("another thing", "0000FF")); // setup us the issue var newIssue = new NewIssue("A test issue1") @@ -311,13 +291,13 @@ public class IssuesClientTests : IDisposable }; newIssue.Labels.Add("something"); - var issue = await _issuesClient.Create(owner, _context.Repository.Name, newIssue); + var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); // update the issue var issueUpdate = issue.ToUpdate(); issueUpdate.AddLabel("another thing"); - var updatedIssue = await _issuesClient.Update(owner, _context.Repository.Name, issue.Number, issueUpdate); + var updatedIssue = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate); Assert.Equal("another thing", updatedIssue.Labels[0].Name); } @@ -325,11 +305,9 @@ public class IssuesClientTests : IDisposable [IntegrationTest] public async Task CanClearLabelsForAnIssue() { - var owner = _context.Repository.Owner.Login; - // create some labels - 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")); + await _issuesClient.Labels.Create(_context.RepositoryOwner, _context.RepositoryName, new NewLabel("something", "FF0000")); + await _issuesClient.Labels.Create(_context.RepositoryOwner, _context.RepositoryName, new NewLabel("another thing", "0000FF")); // setup us the issue var newIssue = new NewIssue("A test issue1") @@ -339,14 +317,14 @@ public class IssuesClientTests : IDisposable newIssue.Labels.Add("something"); newIssue.Labels.Add("another thing"); - var issue = await _issuesClient.Create(owner, _context.Repository.Name, newIssue); + var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); Assert.Equal(2, issue.Labels.Count); // update the issue var issueUpdate = issue.ToUpdate(); issueUpdate.ClearLabels(); - var updatedIssue = await _issuesClient.Update(owner, _context.Repository.Name, issue.Number, issueUpdate); + var updatedIssue = await _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, issueUpdate); Assert.Empty(updatedIssue.Labels); } @@ -355,19 +333,18 @@ public class IssuesClientTests : IDisposable public async Task CanAccessUrls() { var expctedUri = "https://api.github.com/repos/{0}/{1}/issues/{2}/{3}"; - var owner = _context.Repository.Owner.Login; var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue", }; - var issue = await _issuesClient.Create(owner, _context.Repository.Name, newIssue); + var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); Assert.NotNull(issue.CommentsUrl); - Assert.Equal(new Uri(string.Format(expctedUri, owner, _context.Repository.Name, issue.Number, "comments")), issue.CommentsUrl); + Assert.Equal(new Uri(string.Format(expctedUri, _context.RepositoryOwner, _context.RepositoryName, issue.Number, "comments")), issue.CommentsUrl); Assert.NotNull(issue.EventsUrl); - Assert.Equal(new Uri(string.Format(expctedUri, owner, _context.Repository.Name, issue.Number, "events")), issue.EventsUrl); + Assert.Equal(new Uri(string.Format(expctedUri, _context.RepositoryOwner, _context.RepositoryName, issue.Number, "events")), issue.EventsUrl); } public void Dispose() diff --git a/Octokit.Tests.Integration/Clients/IssuesEventsClientTests.cs b/Octokit.Tests.Integration/Clients/IssuesEventsClientTests.cs index d9ee24b1..3d6fea88 100644 --- a/Octokit.Tests.Integration/Clients/IssuesEventsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/IssuesEventsClientTests.cs @@ -12,8 +12,6 @@ public class IssuesEventsClientTests : IDisposable private readonly IIssuesEventsClient _issuesEventsClientClient; private readonly IIssuesClient _issuesClient; private readonly RepositoryContext _context; - private readonly string _repositoryOwner; - private readonly string _repositoryName; public IssuesEventsClientTests() { @@ -24,23 +22,21 @@ public class IssuesEventsClientTests : IDisposable var repoName = Helper.MakeNameWithTimestamp("public-repo"); _context = github.CreateRepositoryContext(new NewRepository(repoName)).Result; - _repositoryOwner = _context.Repository.Owner.Login; - _repositoryName = _context.Repository.Name; } [IntegrationTest] public async Task CanListEventInfoForAnIssue() { var newIssue = new NewIssue("a test issue") { Body = "A new unassigned issue" }; - var issue = await _issuesClient.Create(_repositoryOwner, _repositoryName, newIssue); + var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); - var issueEventInfo = await _issuesEventsClientClient.GetAllForIssue(_repositoryOwner, _repositoryName, issue.Number); + var issueEventInfo = await _issuesEventsClientClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number); Assert.Empty(issueEventInfo); - var closed = _issuesClient.Update(_repositoryOwner, _context.Repository.Name, issue.Number, new IssueUpdate { State = ItemState.Closed }) + var closed = _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new IssueUpdate { State = ItemState.Closed }) .Result; Assert.NotNull(closed); - issueEventInfo = await _issuesEventsClientClient.GetAllForIssue(_repositoryOwner, _repositoryName, issue.Number); + issueEventInfo = await _issuesEventsClientClient.GetAllForIssue(_context.RepositoryOwner, _context.RepositoryName, issue.Number); Assert.Equal(1, issueEventInfo.Count); Assert.Equal(EventInfoState.Closed, issueEventInfo[0].Event); @@ -53,25 +49,25 @@ public class IssuesEventsClientTests : IDisposable 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, _context.Repository.Name, newIssue1); + var issue1 = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue1); Thread.Sleep(1000); - var issue2 = await _issuesClient.Create(_repositoryOwner, _context.Repository.Name, newIssue2); + var issue2 = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue2); Thread.Sleep(1000); // close and open issue1 - var closed1 = _issuesClient.Update(_repositoryOwner, _context.Repository.Name, issue1.Number, new IssueUpdate { State = ItemState.Closed }) + var closed1 = _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue1.Number, new IssueUpdate { State = ItemState.Closed }) .Result; Assert.NotNull(closed1); - var reopened1 = _issuesClient.Update(_repositoryOwner, _context.Repository.Name, issue1.Number, new IssueUpdate { State = ItemState.Open }) + var reopened1 = _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue1.Number, new IssueUpdate { State = ItemState.Open }) .Result; Assert.NotNull(reopened1); // close issue2 - var closed2 = _issuesClient.Update(_repositoryOwner, _context.Repository.Name, issue2.Number, new IssueUpdate { State = ItemState.Closed }) + var closed2 = _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue2.Number, new IssueUpdate { State = ItemState.Closed }) .Result; Assert.NotNull(closed2); - var issueEvents = await _issuesEventsClientClient.GetAllForRepository(_repositoryOwner, _repositoryName); + var issueEvents = await _issuesEventsClientClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName); Assert.Equal(3, issueEvents.Count); Assert.Equal(2, issueEvents.Count(issueEvent => issueEvent.Issue.Body == "Everything's coming up Millhouse")); @@ -81,14 +77,14 @@ public class IssuesEventsClientTests : IDisposable public async Task CanRetrieveIssueEventById() { 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, _context.Repository.Name, issue.Number, new IssueUpdate { State = ItemState.Closed }) + var issue = await _issuesClient.Create(_context.RepositoryOwner, _context.RepositoryName, newIssue); + var closed = _issuesClient.Update(_context.RepositoryOwner, _context.RepositoryName, issue.Number, new IssueUpdate { State = ItemState.Closed }) .Result; Assert.NotNull(closed); - var issueEvents = await _issuesEventsClientClient.GetAllForRepository(_repositoryOwner, _repositoryName); + var issueEvents = await _issuesEventsClientClient.GetAllForRepository(_context.RepositoryOwner, _context.RepositoryName); int issueEventId = issueEvents[0].Id; - var issueEventLookupById = await _issuesEventsClientClient.Get(_repositoryOwner, _repositoryName, issueEventId); + var issueEventLookupById = await _issuesEventsClientClient.Get(_context.RepositoryOwner, _context.RepositoryName, issueEventId); Assert.Equal(issueEventId, issueEventLookupById.Id); Assert.Equal(issueEvents[0].Event, issueEventLookupById.Event); diff --git a/Octokit.Tests.Integration/Helpers/RepositoryContext.cs b/Octokit.Tests.Integration/Helpers/RepositoryContext.cs index 71cdf86f..d16afd36 100644 --- a/Octokit.Tests.Integration/Helpers/RepositoryContext.cs +++ b/Octokit.Tests.Integration/Helpers/RepositoryContext.cs @@ -11,8 +11,13 @@ namespace Octokit.Tests.Integration.Helpers internal RepositoryContext(Repository repo) { Repository = repo; + RepositoryOwner = repo.Owner.Login; + RepositoryName = repo.Name; } + internal string RepositoryOwner { get; private set; } + internal string RepositoryName { get; private set; } + internal Repository Repository { get; private set; } public void Dispose()