Skip to content

Commit

Permalink
Add integration tests draft.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdziadkiewicz committed Oct 18, 2017
1 parent d0f3252 commit 770422e
Showing 1 changed file with 262 additions and 1 deletion.
263 changes: 262 additions & 1 deletion Octokit.Tests.Integration/Clients/RepositoryInvitationsClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Octokit;
using System;
using Octokit;
using Octokit.Tests.Integration;
using Octokit.Tests.Integration.Helpers;
using System.Linq;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 770422e

Please sign in to comment.