From 770422e67a7c074d5332c9ca4f9e5df011c78371 Mon Sep 17 00:00:00 2001 From: gdziadkiewicz Date: Wed, 18 Oct 2017 17:04:52 +0200 Subject: [PATCH] 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