From 0793e036d681a517be239d66475b0eee51f8baea Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Thu, 19 May 2016 16:59:46 +0700 Subject: [PATCH] added integration tests for RepositoryCollaboratorClientTests --- .../RepositoryCollaboratorClientTests.cs | 172 +++++++++++++++++- 1 file changed, 171 insertions(+), 1 deletion(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs index 1035ab35..d9400995 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryCollaboratorClientTests.cs @@ -29,6 +29,25 @@ public class RepositoryCollaboratorClientTests } } + [IntegrationTest] + public async Task ReturnsAllCollaboratorsWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = github.Repository.Collaborator; + + // add a collaborator + await fixture.Add(context.Repository.Id, "m-zuber-octokit-integration-tests"); + + var collaborators = await fixture.GetAll(context.Repository.Id); + Assert.NotNull(collaborators); + Assert.Equal(2, collaborators.Count); + } + } + [IntegrationTest] public async Task ReturnsCorrectCountOfCollaboratorsWithoutStart() { @@ -54,6 +73,31 @@ public class RepositoryCollaboratorClientTests } } + [IntegrationTest] + public async Task ReturnsCorrectCountOfCollaboratorsWithoutStartAndRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = github.Repository.Collaborator; + + // add some collaborators + await fixture.Add(context.Repository.Id, "m-zuber-octokit-integration-tests"); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1 + }; + + var collaborators = await fixture.GetAll(context.Repository.Id, options); + Assert.NotNull(collaborators); + Assert.Equal(1, collaborators.Count); + } + } + [IntegrationTest] public async Task ReturnsCorrectCountOfCollaboratorsWithStart() { @@ -80,6 +124,32 @@ public class RepositoryCollaboratorClientTests } } + [IntegrationTest] + public async Task ReturnsCorrectCountOfCollaboratorsWithStartAndRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = github.Repository.Collaborator; + + // add some collaborators + await fixture.Add(context.Repository.Id, "m-zuber-octokit-integration-tests"); + + var options = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var collaborators = await fixture.GetAll(context.Repository.Id, options); + Assert.NotNull(collaborators); + Assert.Equal(1, collaborators.Count); + } + } + [IntegrationTest] public async Task ReturnsDistinctResultsBasedOnStartPage() { @@ -113,6 +183,40 @@ public class RepositoryCollaboratorClientTests Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); } } + + [IntegrationTest] + public async Task ReturnsDistinctResultsBasedOnStartPageWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = github.Repository.Collaborator; + + // add some collaborators + await fixture.Add(context.Repository.Id, "m-zuber-octokit-integration-tests"); + + var startOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1 + }; + + var firstPage = await fixture.GetAll(context.Repository.Id, startOptions); + + var skipStartOptions = new ApiOptions + { + PageSize = 1, + PageCount = 1, + StartPage = 2 + }; + + var secondPage = await fixture.GetAll(context.Repository.Id, skipStartOptions); + + Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); + } + } } public class TheIsCollaboratorMethod @@ -128,12 +232,78 @@ public class RepositoryCollaboratorClientTests var fixture = github.Repository.Collaborator; // add a collaborator - fixture.Add(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); + await fixture.Add(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); var isCollab = await fixture.IsCollaborator(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); Assert.True(isCollab); } } + + [IntegrationTest] + public async Task ReturnsTrueIfUserIsCollaboratorWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = github.Repository.Collaborator; + + // add a collaborator + await fixture.Add(context.Repository.Id, "m-zuber-octokit-integration-tests"); + + var isCollab = await fixture.IsCollaborator(context.Repository.Id, "m-zuber-octokit-integration-tests"); + + Assert.True(isCollab); + } + } + } + + public class TheDeleteMethod + { + [IntegrationTest] + public async Task CheckDeleteMethod() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = github.Repository.Collaborator; + + // add a collaborator + await fixture.Add(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); + + // and remove + await fixture.Delete(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); + + var isCollab = await fixture.IsCollaborator(context.RepositoryOwner, context.RepositoryName, "m-zuber-octokit-integration-tests"); + + Assert.False(isCollab); + } + } + + [IntegrationTest] + public async Task CheckDeleteMethodWithRepositoryId() + { + var github = Helper.GetAuthenticatedClient(); + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + + using (var context = await github.CreateRepositoryContext(new NewRepository(repoName))) + { + var fixture = github.Repository.Collaborator; + + // add a collaborator + await fixture.Add(context.Repository.Id, "m-zuber-octokit-integration-tests"); + + // and remove + await fixture.Delete(context.Repository.Id, "m-zuber-octokit-integration-tests"); + + var isCollab = await fixture.IsCollaborator(context.Repository.Id, "m-zuber-octokit-integration-tests"); + + Assert.False(isCollab); + } + } } } \ No newline at end of file