From 7e4112c6ff791506be83bd535f2ab7541c23c29b Mon Sep 17 00:00:00 2001 From: gdziadkiewicz Date: Tue, 17 Oct 2017 13:40:09 +0200 Subject: [PATCH 01/10] Add ApiOptions overloads to repository invitations. --- .../IObservableRepositoryInvitationsClient.cs | 20 ++++++++++++ .../ObservableRepositoryInvitationsClient.cs | 29 +++++++++++++++-- .../Clients/IRepositoryInvitationsClient.cs | 22 +++++++++++++ .../Clients/RepositoryInvitationsClient.cs | 31 +++++++++++++++++-- 4 files changed, 98 insertions(+), 4 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs index fdb89318db..2f339c8fca 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryInvitationsClient.cs @@ -43,6 +43,16 @@ public interface IObservableRepositoryInvitationsClient [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] IObservable GetAllForCurrent(); + /// + /// Gets all invitations for the current user. + /// + /// + /// See the API documentation for more information. + /// + /// Options for changing the API response + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + IObservable GetAllForCurrent(ApiOptions options); + /// /// Gets all the invitations on a repository. /// @@ -52,6 +62,16 @@ public interface IObservableRepositoryInvitationsClient /// The id of the repository IObservable GetAllForRepository(long repositoryId); + /// + /// Gets all the invitations on a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the repository + /// /// Options for changing the API response + IObservable GetAllForRepository(long repositoryId, ApiOptions options); + /// /// Updates a repository invitation. /// diff --git a/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs index d8368e6d4a..24047f9355 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs @@ -80,7 +80,19 @@ public IObservable Edit(long repositoryId, int invitationI /// public IObservable GetAllForCurrent() { - return _connection.GetAndFlattenAllPages(ApiUrls.UserInvitations(), null, AcceptHeaders.InvitationsApiPreview, ApiOptions.None); + return GetAllForCurrent(ApiOptions.None); + } + + /// + /// Gets all invitations for the current user. + /// + /// + /// See the API documentation for more information. + /// + /// Options for changing the API response + public IObservable GetAllForCurrent(ApiOptions options) + { + return _connection.GetAndFlattenAllPages(ApiUrls.UserInvitations(), null, AcceptHeaders.InvitationsApiPreview, options); } /// @@ -92,7 +104,20 @@ public IObservable GetAllForCurrent() /// The id of the repository public IObservable GetAllForRepository(long repositoryId) { - return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryInvitations(repositoryId), null, AcceptHeaders.InvitationsApiPreview, ApiOptions.None); + return GetAllForRepository(repositoryId, ApiOptions.None); + } + + /// + /// Gets all the invitations on a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the repository + /// Options for changing the API response + public IObservable GetAllForRepository(long repositoryId, ApiOptions options) + { + return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryInvitations(repositoryId), null, AcceptHeaders.InvitationsApiPreview, options); } } } diff --git a/Octokit/Clients/IRepositoryInvitationsClient.cs b/Octokit/Clients/IRepositoryInvitationsClient.cs index a24682fafa..4749fbea73 100644 --- a/Octokit/Clients/IRepositoryInvitationsClient.cs +++ b/Octokit/Clients/IRepositoryInvitationsClient.cs @@ -54,6 +54,17 @@ public interface IRepositoryInvitationsClient [ExcludeFromPaginationApiOptionsConventionTest("TODO: Implement pagination for this method")] Task> GetAllForCurrent(); + /// + /// Gets all invitations for the current user. + /// + /// + /// See the API documentation for more information. + /// + /// Options for changing the API response + /// Thrown when a general API error occurs. + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + Task> GetAllForCurrent(ApiOptions options); + /// /// Gets all the invitations on a repository. /// @@ -65,6 +76,17 @@ public interface IRepositoryInvitationsClient [ExcludeFromPaginationApiOptionsConventionTest("TODO: Implement pagination for this method")] Task> GetAllForRepository(long repositoryId); + /// + /// Gets all the invitations on a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the repository + /// Options for changing the API response + /// Thrown when a general API error occurs. + Task> GetAllForRepository(long repositoryId, ApiOptions options); + /// /// Updates a repository invitation. /// diff --git a/Octokit/Clients/RepositoryInvitationsClient.cs b/Octokit/Clients/RepositoryInvitationsClient.cs index 92a50cba6c..85f0e3774f 100644 --- a/Octokit/Clients/RepositoryInvitationsClient.cs +++ b/Octokit/Clients/RepositoryInvitationsClient.cs @@ -91,7 +91,20 @@ public async Task Delete(long repositoryId, int invitationId) /// Thrown when a general API error occurs. public Task> GetAllForCurrent() { - return ApiConnection.GetAll(ApiUrls.UserInvitations(), AcceptHeaders.InvitationsApiPreview); + return GetAllForCurrent(ApiOptions.None); + } + + /// + /// Gets all invitations for the current user. + /// + /// + /// See the API documentation for more information. + /// + /// Options for changing the API response + /// Thrown when a general API error occurs. + public Task> GetAllForCurrent(ApiOptions options) + { + return ApiConnection.GetAll(ApiUrls.UserInvitations(), null, AcceptHeaders.InvitationsApiPreview, options); } /// @@ -104,7 +117,21 @@ public Task> GetAllForCurrent() /// Thrown when a general API error occurs. public Task> GetAllForRepository(long repositoryId) { - return ApiConnection.GetAll(ApiUrls.RepositoryInvitations(repositoryId), AcceptHeaders.InvitationsApiPreview); + return GetAllForRepository(repositoryId, ApiOptions.None); + } + + /// + /// Gets all the invitations on a repository. + /// + /// + /// See the API documentation for more information. + /// + /// The id of the repository + /// Options for changing the API response + /// Thrown when a general API error occurs. + public Task> GetAllForRepository(long repositoryId, ApiOptions options) + { + return ApiConnection.GetAll(ApiUrls.RepositoryInvitations(repositoryId), null, AcceptHeaders.InvitationsApiPreview, options); } /// From 4477a8c58b2214de88087a46389e2eb39cc04ed3 Mon Sep 17 00:00:00 2001 From: gdziadkiewicz Date: Wed, 18 Oct 2017 10:51:42 +0200 Subject: [PATCH 02/10] Remove ExcludeFromPaginationApiOptionsConvention for RepositoryInvitationsClient --- Octokit/Clients/IRepositoryInvitationsClient.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Octokit/Clients/IRepositoryInvitationsClient.cs b/Octokit/Clients/IRepositoryInvitationsClient.cs index 4749fbea73..d733471483 100644 --- a/Octokit/Clients/IRepositoryInvitationsClient.cs +++ b/Octokit/Clients/IRepositoryInvitationsClient.cs @@ -51,7 +51,6 @@ public interface IRepositoryInvitationsClient /// /// Thrown when a general API error occurs. [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] - [ExcludeFromPaginationApiOptionsConventionTest("TODO: Implement pagination for this method")] Task> GetAllForCurrent(); /// @@ -73,7 +72,6 @@ public interface IRepositoryInvitationsClient /// /// The id of the repository /// Thrown when a general API error occurs. - [ExcludeFromPaginationApiOptionsConventionTest("TODO: Implement pagination for this method")] Task> GetAllForRepository(long repositoryId); /// From 552b05c27bf3019ff2968c400c3b0b3caeebcd74 Mon Sep 17 00:00:00 2001 From: gdziadkiewicz Date: Wed, 18 Oct 2017 11:04:52 +0200 Subject: [PATCH 03/10] Adjust tests to new call form. --- Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs index d103e51292..2b69bf75ff 100644 --- a/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs @@ -2,6 +2,7 @@ using Octokit; using System; using System.Threading.Tasks; +using Octokit.Tests; using Xunit; public class RepositoryInvitationsClientTests @@ -25,7 +26,7 @@ public async Task RequestsCorrectUrl() await client.GetAllForRepository(1); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/invitations"), "application/vnd.github.swamp-thing-preview+json"); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/invitations"), null, "application/vnd.github.swamp-thing-preview+json", Args.ApiOptions); } } @@ -39,7 +40,7 @@ public async Task RequestsCorrectUrl() await client.GetAllForCurrent(); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "user/repository_invitations"), "application/vnd.github.swamp-thing-preview+json"); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "user/repository_invitations"), null, "application/vnd.github.swamp-thing-preview+json", Args.ApiOptions); } } From d0f3252eac42f75e845d39fe24066e19e287f3b4 Mon Sep 17 00:00:00 2001 From: gdziadkiewicz Date: Wed, 18 Oct 2017 11:19:32 +0200 Subject: [PATCH 04/10] Add null check and null check test for RepositoryInvitations. --- .../ObservableRepositoryInvitationsClient.cs | 2 ++ .../RepositoryInvitationsClientTests.cs | 18 ++++++++++++++++++ ...servableRepositoryInvitationsClientTests.cs | 18 ++++++++++++++++++ Octokit/Clients/RepositoryInvitationsClient.cs | 2 ++ 4 files changed, 40 insertions(+) diff --git a/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs index 24047f9355..25e565fb9f 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryInvitationsClient.cs @@ -92,6 +92,7 @@ public IObservable GetAllForCurrent() /// Options for changing the API response public IObservable GetAllForCurrent(ApiOptions options) { + Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.UserInvitations(), null, AcceptHeaders.InvitationsApiPreview, options); } @@ -117,6 +118,7 @@ public IObservable GetAllForRepository(long repositoryId) /// Options for changing the API response public IObservable GetAllForRepository(long repositoryId, ApiOptions options) { + Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryInvitations(repositoryId), null, AcceptHeaders.InvitationsApiPreview, options); } } diff --git a/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs index 2b69bf75ff..cfb23c44bf 100644 --- a/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryInvitationsClientTests.cs @@ -18,6 +18,15 @@ public void EnsuresNonNullArguments() public class TheGetAllForRepositoryMethod { + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new RepositoryInvitationsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAllForRepository(1, null)); + } + [Fact] public async Task RequestsCorrectUrl() { @@ -32,6 +41,15 @@ public async Task RequestsCorrectUrl() public class TheGetAllForCurrentMethod { + [Fact] + public async Task EnsuresNonNullArguments() + { + var connection = Substitute.For(); + var client = new RepositoryInvitationsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAllForCurrent(null)); + } + [Fact] public async Task RequestsCorrectUrl() { diff --git a/Octokit.Tests/Reactive/ObservableRepositoryInvitationsClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoryInvitationsClientTests.cs index 2a7d9bfe83..fedadb185b 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoryInvitationsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoryInvitationsClientTests.cs @@ -18,6 +18,15 @@ public void EnsuresNonNullArguments() public class TheGetAllForRepositoryMethod { + [Fact] + public void EnsuresNonNullArguments() + { + var gitHub = Substitute.For(); + var client = new ObservableRepositoryInvitationsClient(gitHub); + + Assert.Throws(() => client.GetAllForRepository(42, null)); + } + [Fact] public void RequestsCorrectUrl() { @@ -32,6 +41,15 @@ public void RequestsCorrectUrl() public class TheGetAllForCurrentMethod { + [Fact] + public void EnsuresNonNullArguments() + { + var gitHub = Substitute.For(); + var client = new ObservableRepositoryInvitationsClient(gitHub); + + Assert.Throws(() => client.GetAllForCurrent(null)); + } + [Fact] public void RequestsCorrectUrl() { diff --git a/Octokit/Clients/RepositoryInvitationsClient.cs b/Octokit/Clients/RepositoryInvitationsClient.cs index 85f0e3774f..fa326a3547 100644 --- a/Octokit/Clients/RepositoryInvitationsClient.cs +++ b/Octokit/Clients/RepositoryInvitationsClient.cs @@ -104,6 +104,7 @@ public Task> GetAllForCurrent() /// Thrown when a general API error occurs. public Task> GetAllForCurrent(ApiOptions options) { + Ensure.ArgumentNotNull(options, "options"); return ApiConnection.GetAll(ApiUrls.UserInvitations(), null, AcceptHeaders.InvitationsApiPreview, options); } @@ -131,6 +132,7 @@ public Task> GetAllForRepository(long reposi /// Thrown when a general API error occurs. public Task> GetAllForRepository(long repositoryId, ApiOptions options) { + Ensure.ArgumentNotNull(options, "options"); return ApiConnection.GetAll(ApiUrls.RepositoryInvitations(repositoryId), null, AcceptHeaders.InvitationsApiPreview, options); } From 770422e67a7c074d5332c9ca4f9e5df011c78371 Mon Sep 17 00:00:00 2001 From: gdziadkiewicz Date: Wed, 18 Oct 2017 17:04:52 +0200 Subject: [PATCH 05/10] Add integration tests draft. --- .../RepositoryInvitationsClientTests.cs | 263 +++++++++++++++++- 1 file changed, 262 insertions(+), 1 deletion(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs index 17df3f2022..d8bf8e5348 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs @@ -1,4 +1,5 @@ -using Octokit; +using System; +using Octokit; using Octokit.Tests.Integration; using Octokit.Tests.Integration.Helpers; using System.Linq; @@ -38,6 +39,115 @@ public async Task CanGetAllInvitations() Assert.Equal(invitations[0].Repository.Id, response.Repository.Id); } } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfInvitationsWithStart() + { + var collaborator1 = "octocat"; + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = github.Repository.Collaborator; + var permission = new CollaboratorRequest(Permission.Push); + + // invite a collaborator + var response1 = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, collaborator1, permission); + + Assert.Equal(collaborator1, response1.Invitee.Login); + Assert.Equal(InvitationPermissionType.Write, response1.Permissions); + + var response2 = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission); + + Assert.Equal(context.RepositoryOwner, response2.Invitee.Login); + Assert.Equal(InvitationPermissionType.Write, response2.Permissions); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var invitations = await github.Repository.Invitation.GetAllForRepository(context.Repository.Id, options); + + Assert.Equal(1, invitations.Count); + } + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfInvitationsWithoutStart() + { + var collaborator = "octocat"; + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = github.Repository.Collaborator; + var permission = new CollaboratorRequest(Permission.Push); + + // invite a collaborator + var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, collaborator, permission); + + Assert.Equal(collaborator, response.Invitee.Login); + Assert.Equal(InvitationPermissionType.Write, response.Permissions); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + }; + + var invitations = await github.Repository.Invitation.GetAllForRepository(context.Repository.Id, options); + + Assert.Equal(1, invitations.Count); + } + } + + [IntegrationTest] + public async Task ReturnsDistinctInvitationsBasedOnStart() + { + var collaborator1 = "octocat"; + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = github.Repository.Collaborator; + var permission = new CollaboratorRequest(Permission.Push); + + // invite a collaborator + var response1 = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, collaborator1, permission); + + Assert.Equal(collaborator1, response1.Invitee.Login); + Assert.Equal(InvitationPermissionType.Write, response1.Permissions); + + var response2 = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission); + + Assert.Equal(context.RepositoryOwner, response2.Invitee.Login); + Assert.Equal(InvitationPermissionType.Write, response2.Permissions); + + var startOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1 + }; + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var firstInvitations = await github.Repository.Invitation.GetAllForRepository(context.Repository.Id, startOptions); + var secondInvitations = await github.Repository.Invitation.GetAllForRepository(context.Repository.Id, skipStartOptions); + + Assert.NotEqual(firstInvitations[0].Invitee.Login, secondInvitations[0].Invitee.Login); + } + } } public class TheGetAllForCurrentMethod @@ -70,6 +180,157 @@ public async Task CanGetAllInvitations() Assert.NotNull(invitations.FirstOrDefault(i => i.Repository.Id == response.Repository.Id)); } } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfInvitationsWithStart() + { + var github = Helper.GetAuthenticatedClient(); + var repoNames = Enumerable.Range(0, 6).Select(i => Helper.MakeNameWithTimestamp($"public-repo{i}")).ToList(); + + RepositoryContext[] contexts = null; + try + { + contexts = await Task.WhenAll(repoNames.Select(x => github.CreateRepositoryContext(new NewRepository(x)))); + var fixture = github.Repository.Collaborator; + var permission = new CollaboratorRequest(Permission.Push); + + // invite a collaborator to all repos + foreach (var context in contexts) + { + var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission); + + Assert.Equal(context.RepositoryOwner, response.Invitee.Login); + Assert.Equal(InvitationPermissionType.Write, response.Permissions); + } + + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + + var invitations = await github.Repository.Invitation.GetAllForCurrent(startOptions); + Assert.Equal(1, invitations.Count); + } + finally + { + if (contexts != null) + { + foreach (var context in contexts) + { + context?.Dispose(); + } + } + } + } + + [IntegrationTest] + public async Task ReturnsCorrectCountOfInvitationsWithoutStart() + { + var github = Helper.GetAuthenticatedClient(); + var repoNames = Enumerable.Range(0, 10) + .Select(i => Helper.MakeNameWithTimestamp($"public-repo{i}")) + .ToList(); + + RepositoryContext[] contexts = null; + try + { + contexts = await Task.WhenAll(repoNames.Select(x => github.CreateRepositoryContext(new NewRepository(x)))); + var fixture = github.Repository.Collaborator; + var permission = new CollaboratorRequest(Permission.Push); + + // invite a collaborator to all repos + foreach (var context in contexts) + { + var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission); + + Assert.Equal(context.RepositoryOwner, response.Invitee.Login); + Assert.Equal(InvitationPermissionType.Write, response.Permissions); + } + + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + + var invitations = await github.Repository.Invitation.GetAllForCurrent(startOptions); + Assert.Equal(5, invitations.Count); + } + finally + { + if (contexts != null) + { + foreach (var context in contexts) + { + context?.Dispose(); + } + } + } + } + + [IntegrationTest] + public async Task ReturnsDistinctInvitationsBasedOnStart() + { + var github = Helper.GetAuthenticatedClient(); + var repoNames = Enumerable.Range(0, 10).Select(i => Helper.MakeNameWithTimestamp($"public-repo{i}")).ToList(); + + RepositoryContext[] contexts = null; + try + { + contexts = await Task.WhenAll(repoNames.Select(x => github.CreateRepositoryContext(new NewRepository(x)))); + var fixture = github.Repository.Collaborator; + var permission = new CollaboratorRequest(Permission.Push); + + // invite a collaborator to all repos + foreach (var context in contexts) + { + var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission); + + Assert.Equal(context.RepositoryOwner, response.Invitee.Login); + Assert.Equal(InvitationPermissionType.Write, response.Permissions); + } + + var startOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1 + }; + + var skipStartOptions = new ApiOptions + { + PageSize = 5, + PageCount = 1, + StartPage = 2 + }; + + var firstInvitations = await github.Repository.Invitation.GetAllForCurrent(startOptions); + var secondInvitations = await github.Repository.Invitation.GetAllForCurrent(skipStartOptions); + + var invitations = firstInvitations.Concat(secondInvitations).ToArray(); + var invitationsLength = invitations.Length; + for (int i = 0; i < invitationsLength; i++) + { + for (int j = i+1; j < invitationsLength; j++) + { + Assert.NotEqual(invitations[i].Repository.FullName, invitations[j].Repository.FullName); + } + } + } + finally + { + if(contexts != null) + { + foreach (var context in contexts) + { + context?.Dispose(); + } + } + } + } } public class TheAcceptMethod From ce60bc6f712bec663a4093acafe9f0515e85cbe7 Mon Sep 17 00:00:00 2001 From: gdziadkiewicz Date: Wed, 18 Oct 2017 22:55:51 +0200 Subject: [PATCH 06/10] Remove redundant using. --- .../Clients/RepositoryInvitationsClientTests.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs index d8bf8e5348..93816388bc 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs @@ -1,5 +1,4 @@ -using System; -using Octokit; +using Octokit; using Octokit.Tests.Integration; using Octokit.Tests.Integration.Helpers; using System.Linq; From 7d8cc5fd61960dc7001b95eb100c49ea32a6607e Mon Sep 17 00:00:00 2001 From: gdziadkiewicz Date: Sun, 12 Nov 2017 01:51:57 +0100 Subject: [PATCH 07/10] Replace Octocat with dual account test second user. --- .../Clients/RepositoryInvitationsClientTests.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs index 93816388bc..5ad32196ca 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs @@ -39,10 +39,10 @@ public async Task CanGetAllInvitations() } } - [IntegrationTest] + [DualAccountTest] public async Task ReturnsCorrectCountOfInvitationsWithStart() { - var collaborator1 = "octocat"; + var collaborator1 = Helper.CredentialsSecondUser.Login; var github = Helper.GetAuthenticatedClient(); var repoName = Helper.MakeNameWithTimestamp("public-repo"); @@ -75,10 +75,10 @@ public async Task ReturnsCorrectCountOfInvitationsWithStart() } } - [IntegrationTest] + [DualAccountTest] public async Task ReturnsCorrectCountOfInvitationsWithoutStart() { - var collaborator = "octocat"; + var collaborator = Helper.CredentialsSecondUser.Login; var github = Helper.GetAuthenticatedClient(); var repoName = Helper.MakeNameWithTimestamp("public-repo"); @@ -108,7 +108,7 @@ public async Task ReturnsCorrectCountOfInvitationsWithoutStart() [IntegrationTest] public async Task ReturnsDistinctInvitationsBasedOnStart() { - var collaborator1 = "octocat"; + var collaborator1 = Helper.CredentialsSecondUser.Login; var github = Helper.GetAuthenticatedClient(); var repoName = Helper.MakeNameWithTimestamp("public-repo"); From 8342eecc50dbadaa2542d9d44b7af379b3e3319e Mon Sep 17 00:00:00 2001 From: gdziadkiewicz Date: Sun, 12 Nov 2017 02:25:55 +0100 Subject: [PATCH 08/10] Fix mass repository creation by making it synchronous and fix last RepositoryInvitationsClient test utilizing Octokit user. --- .../Clients/RepositoryInvitationsClientTests.cs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs index 5ad32196ca..757a755d38 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs @@ -12,7 +12,6 @@ public class TheGetAllForRepositoryMethod [IntegrationTest] public async Task CanGetAllInvitations() { - var collaborator = "octocat"; var github = Helper.GetAuthenticatedClient(); var repoName = Helper.MakeNameWithTimestamp("public-repo"); @@ -22,9 +21,9 @@ public async Task CanGetAllInvitations() var permission = new CollaboratorRequest(Permission.Push); // invite a collaborator - var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, collaborator, permission); + var response = await fixture.Invite(context.RepositoryOwner, context.RepositoryName, context.RepositoryOwner, permission); - Assert.Equal(collaborator, response.Invitee.Login); + Assert.Equal(context.RepositoryOwner, response.Invitee.Login); Assert.Equal(InvitationPermissionType.Write, response.Permissions); var invitations = await github.Repository.Invitation.GetAllForRepository(context.Repository.Id); @@ -189,7 +188,7 @@ public async Task ReturnsCorrectCountOfInvitationsWithStart() RepositoryContext[] contexts = null; try { - contexts = await Task.WhenAll(repoNames.Select(x => github.CreateRepositoryContext(new NewRepository(x)))); + contexts = repoNames.Select(x => github.CreateRepositoryContext(new NewRepository(x)).Result).ToArray(); var fixture = github.Repository.Collaborator; var permission = new CollaboratorRequest(Permission.Push); @@ -229,14 +228,12 @@ public async Task ReturnsCorrectCountOfInvitationsWithStart() public async Task ReturnsCorrectCountOfInvitationsWithoutStart() { var github = Helper.GetAuthenticatedClient(); - var repoNames = Enumerable.Range(0, 10) - .Select(i => Helper.MakeNameWithTimestamp($"public-repo{i}")) - .ToList(); + var repoNames = Enumerable.Range(0, 6).Select(i => Helper.MakeNameWithTimestamp($"public-repo{i}")).ToList(); RepositoryContext[] contexts = null; try { - contexts = await Task.WhenAll(repoNames.Select(x => github.CreateRepositoryContext(new NewRepository(x)))); + contexts = repoNames.Select( x => github.CreateRepositoryContext(new NewRepository(x)).Result).ToArray(); var fixture = github.Repository.Collaborator; var permission = new CollaboratorRequest(Permission.Push); @@ -280,7 +277,7 @@ public async Task ReturnsDistinctInvitationsBasedOnStart() RepositoryContext[] contexts = null; try { - contexts = await Task.WhenAll(repoNames.Select(x => github.CreateRepositoryContext(new NewRepository(x)))); + contexts = repoNames.Select(x => github.CreateRepositoryContext(new NewRepository(x)).Result).ToArray(); var fixture = github.Repository.Collaborator; var permission = new CollaboratorRequest(Permission.Push); From 206d3a2fd18979f7e4899a13721f8721372f05df Mon Sep 17 00:00:00 2001 From: gdziadkiewicz Date: Thu, 30 Nov 2017 13:28:15 +0100 Subject: [PATCH 09/10] Refactor async hack. --- .../Clients/RepositoryInvitationsClientTests.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs index 757a755d38..6b0776281d 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs @@ -1,4 +1,5 @@ -using Octokit; +using System.Collections.Generic; +using Octokit; using Octokit.Tests.Integration; using Octokit.Tests.Integration.Helpers; using System.Linq; @@ -185,10 +186,13 @@ public async Task ReturnsCorrectCountOfInvitationsWithStart() var github = Helper.GetAuthenticatedClient(); var repoNames = Enumerable.Range(0, 6).Select(i => Helper.MakeNameWithTimestamp($"public-repo{i}")).ToList(); - RepositoryContext[] contexts = null; + var contexts = new List(); try { - contexts = repoNames.Select(x => github.CreateRepositoryContext(new NewRepository(x)).Result).ToArray(); + foreach (var repoName in repoNames) + { + contexts.Add(await github.CreateRepositoryContext(new NewRepository(repoName))); + } var fixture = github.Repository.Collaborator; var permission = new CollaboratorRequest(Permission.Push); From 036e0cde3fbc95655adadf1d15f06a315a152145 Mon Sep 17 00:00:00 2001 From: gdziadkiewicz Date: Fri, 1 Dec 2017 13:44:22 +0100 Subject: [PATCH 10/10] Reduce number of created test repos. --- .../RepositoryInvitationsClientTests.cs | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs index 6b0776281d..39b552b57e 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs @@ -184,7 +184,7 @@ public async Task CanGetAllInvitations() public async Task ReturnsCorrectCountOfInvitationsWithStart() { var github = Helper.GetAuthenticatedClient(); - var repoNames = Enumerable.Range(0, 6).Select(i => Helper.MakeNameWithTimestamp($"public-repo{i}")).ToList(); + var repoNames = Enumerable.Range(0, 2).Select(i => Helper.MakeNameWithTimestamp($"public-repo{i}")).ToList(); var contexts = new List(); try @@ -207,7 +207,7 @@ public async Task ReturnsCorrectCountOfInvitationsWithStart() var startOptions = new ApiOptions { - PageSize = 5, + PageSize = 1, PageCount = 1, StartPage = 2 }; @@ -232,12 +232,15 @@ public async Task ReturnsCorrectCountOfInvitationsWithStart() public async Task ReturnsCorrectCountOfInvitationsWithoutStart() { var github = Helper.GetAuthenticatedClient(); - var repoNames = Enumerable.Range(0, 6).Select(i => Helper.MakeNameWithTimestamp($"public-repo{i}")).ToList(); + var repoNames = Enumerable.Range(0, 2).Select(i => Helper.MakeNameWithTimestamp($"public-repo{i}")).ToList(); - RepositoryContext[] contexts = null; + var contexts = new List(); try { - contexts = repoNames.Select( x => github.CreateRepositoryContext(new NewRepository(x)).Result).ToArray(); + foreach (var repoName in repoNames) + { + contexts.Add(await github.CreateRepositoryContext(new NewRepository(repoName))); + } var fixture = github.Repository.Collaborator; var permission = new CollaboratorRequest(Permission.Push); @@ -252,13 +255,13 @@ public async Task ReturnsCorrectCountOfInvitationsWithoutStart() var startOptions = new ApiOptions { - PageSize = 5, + PageSize = 1, PageCount = 1 }; var invitations = await github.Repository.Invitation.GetAllForCurrent(startOptions); - Assert.Equal(5, invitations.Count); + Assert.Equal(1, invitations.Count); } finally { @@ -276,12 +279,15 @@ public async Task ReturnsCorrectCountOfInvitationsWithoutStart() public async Task ReturnsDistinctInvitationsBasedOnStart() { var github = Helper.GetAuthenticatedClient(); - var repoNames = Enumerable.Range(0, 10).Select(i => Helper.MakeNameWithTimestamp($"public-repo{i}")).ToList(); + var repoNames = Enumerable.Range(0, 2).Select(i => Helper.MakeNameWithTimestamp($"public-repo{i}")).ToList(); - RepositoryContext[] contexts = null; + var contexts = new List(); try { - contexts = repoNames.Select(x => github.CreateRepositoryContext(new NewRepository(x)).Result).ToArray(); + foreach (var repoName in repoNames) + { + contexts.Add(await github.CreateRepositoryContext(new NewRepository(repoName))); + } var fixture = github.Repository.Collaborator; var permission = new CollaboratorRequest(Permission.Push); @@ -296,13 +302,13 @@ public async Task ReturnsDistinctInvitationsBasedOnStart() var startOptions = new ApiOptions { - PageSize = 5, + PageSize = 1, PageCount = 1 }; var skipStartOptions = new ApiOptions { - PageSize = 5, + PageSize = 1, PageCount = 1, StartPage = 2 };