Skip to content

Commit

Permalink
Reimplement ApiOptions overloads
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangribble committed Aug 8, 2017
1 parent 635b42d commit 595e6e2
Show file tree
Hide file tree
Showing 8 changed files with 533 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ public interface IObservableOrganizationOutsideCollaboratorsClient
/// <returns>The users</returns>
IObservable<User> GetAll(string org);

/// <summary>
/// List all users who are outside collaborators of an organization. An outside collaborator is a user that
/// is not a member of the organization.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/outside_collaborators/#list-outside-collaborators">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="options">Options for changing the API response</param>
/// <returns>The users</returns>
IObservable<User> GetAll(string org, ApiOptions options);

/// <summary>
/// List all users who are outside collaborators of an organization. An outside collaborator is a user that
/// is not a member of the organization.
Expand All @@ -31,6 +44,20 @@ public interface IObservableOrganizationOutsideCollaboratorsClient
/// <returns>The users</returns>
IObservable<User> GetAll(string org, OrganizationMembersFilter filter);

/// <summary>
/// List all users who are outside collaborators of an organization. An outside collaborator is a user that
/// is not a member of the organization.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/outside_collaborators/#list-outside-collaborators">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="filter">The filter to use when getting the users, <see cref="OrganizationMembersFilter"/></param>
/// <param name="options">Options for changing the API response</param>
/// <returns>The users</returns>
IObservable<User> GetAll(string org, OrganizationMembersFilter filter, ApiOptions options);

/// <summary>
/// Removes a user as an outside collaborator from the organization, this will remove them from all repositories
/// within the organization.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,26 @@ public IObservable<User> GetAll(string org)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));

return _connection.GetAndFlattenAllPages<User>(ApiUrls.OutsideCollaborators(org), null, AcceptHeaders.OrganizationMembershipPreview);
return GetAll(org, ApiOptions.None);
}

/// <summary>
/// List all users who are outside collaborators of an organization. An outside collaborator is a user that
/// is not a member of the organization.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/outside_collaborators/#list-outside-collaborators">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="options">Options for changing the API response</param>
/// <returns>The users</returns>
public IObservable<User> GetAll(string org, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(options, nameof(options));

return _connection.GetAndFlattenAllPages<User>(ApiUrls.OutsideCollaborators(org), null, AcceptHeaders.OrganizationMembershipPreview, options);
}

/// <summary>
Expand All @@ -53,7 +72,27 @@ public IObservable<User> GetAll(string org, OrganizationMembersFilter filter)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));

return _connection.GetAndFlattenAllPages<User>(ApiUrls.OutsideCollaborators(org, filter), null, AcceptHeaders.OrganizationMembershipPreview);
return GetAll(org, filter, ApiOptions.None);
}

/// <summary>
/// List all users who are outside collaborators of an organization. An outside collaborator is a user that
/// is not a member of the organization.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/outside_collaborators/#list-outside-collaborators">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="org">The login for the organization</param>
/// <param name="filter">The filter to use when getting the users, <see cref="OrganizationMembersFilter"/></param>
/// <param name="options">Options for changing the API response</param>
/// <returns>The users</returns>
public IObservable<User> GetAll(string org, OrganizationMembersFilter filter, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
Ensure.ArgumentNotNull(options, nameof(options));

return _connection.GetAndFlattenAllPages<User>(ApiUrls.OutsideCollaborators(org, filter), null, AcceptHeaders.OrganizationMembershipPreview, options);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,54 @@ public async Task ReturnsOutsideCollaborators()
}
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithoutStart()
{
var repoName = Helper.MakeNameWithTimestamp("public-repo");
using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName)))
{
await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator);

var options = new ApiOptions
{
PageSize = 1,
PageCount = 1
};

var outsideCollaborators = await _gitHub.Organization
.OutsideCollaborator
.GetAll(Helper.Organization, options);

Assert.NotNull(outsideCollaborators);
Assert.Equal(1, outsideCollaborators.Count);
}
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithStart()
{
var repoName = Helper.MakeNameWithTimestamp("public-repo");
using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName)))
{
await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator);
await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, "alfhenrik");

var options = new ApiOptions
{
PageSize = 1,
PageCount = 1,
StartPage = 1
};

var outsideCollaborators = await _gitHub.Organization
.OutsideCollaborator
.GetAll(Helper.Organization, options);

Assert.NotNull(outsideCollaborators);
Assert.Equal(1, outsideCollaborators.Count);
}
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithAllFilter()
{
Expand All @@ -66,6 +114,66 @@ public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithAllFilter()
}
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithAllFilterAndApiOptions()
{
var repoName = Helper.MakeNameWithTimestamp("public-repo");
using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName)))
{
await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator);
await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, "alfhenrik");

var options = new ApiOptions
{
PageCount = 1,
PageSize = 2
};

var outsideCollaborators = await _gitHub.Organization
.OutsideCollaborator
.GetAll(Helper.Organization, OrganizationMembersFilter.All, options);

Assert.NotNull(outsideCollaborators);
Assert.Equal(2, outsideCollaborators.Count);
}
}

[IntegrationTest(Skip = "It seems this API endpoint does not support pagination as page size/count are not adhered to")]
public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithAllFilterWithStart()
{
var repoName = Helper.MakeNameWithTimestamp("public-repo");
using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName)))
{
await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator);
await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, "alfhenrik");

var firstPageOptions = new ApiOptions
{
PageCount = 1,
PageSize = 1,
StartPage = 1
};

var firstPageOfOutsideCollaborators = await _gitHub.Organization
.OutsideCollaborator
.GetAll(Helper.Organization, OrganizationMembersFilter.All, firstPageOptions);

var secondPageOptions = new ApiOptions
{
PageCount = 1,
PageSize = 1,
StartPage = 2
};

var secondPageOfOutsideCollaborators = await _gitHub.Organization
.OutsideCollaborator
.GetAll(Helper.Organization, OrganizationMembersFilter.All, secondPageOptions);

Assert.Equal(1, firstPageOfOutsideCollaborators.Count);
Assert.Equal(1, secondPageOfOutsideCollaborators.Count);
}
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithTwoFactorFilter()
{
Expand All @@ -84,6 +192,31 @@ public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithTwoFactorFilter()
Assert.Equal(_fixtureCollaborator, outsideCollaborators[0].Login);
}
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithTwoFactorFilterAndApiOptions()
{
var repoName = Helper.MakeNameWithTimestamp("public-repo");
using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName)))
{
await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator);
await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, "alfhenrik");

var options = new ApiOptions
{
PageCount = 1,
PageSize = 2
};

var outsideCollaborators = await _gitHub.Organization
.OutsideCollaborator
.GetAll(Helper.Organization, OrganizationMembersFilter.TwoFactorAuthenticationDisabled, options);

Assert.NotNull(outsideCollaborators);
Assert.Equal(1, outsideCollaborators.Count);
Assert.Equal(_fixtureCollaborator, outsideCollaborators[0].Login);
}
}
}

public class TheDeleteMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,52 @@ public async Task ReturnsOutsideCollaborators()
}
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithoutStart()
{
var repoName = Helper.MakeNameWithTimestamp("public-repo");
using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName)))
{
await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator);

var options = new ApiOptions
{
PageSize = 1,
PageCount = 1
};

var outsideCollaborators = await _client
.GetAll(Helper.Organization, options).ToList();

Assert.NotNull(outsideCollaborators);
Assert.Equal(1, outsideCollaborators.Count);
}
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithStart()
{
var repoName = Helper.MakeNameWithTimestamp("public-repo");
using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName)))
{
await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator);
await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, "alfhenrik");

var options = new ApiOptions
{
PageSize = 1,
PageCount = 1,
StartPage = 1
};

var outsideCollaborators = await _client
.GetAll(Helper.Organization, options).ToList();

Assert.NotNull(outsideCollaborators);
Assert.Equal(1, outsideCollaborators.Count);
}
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithAllFilter()
{
Expand All @@ -63,6 +109,63 @@ public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithAllFilter()
}
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithAllFilterAndApiOptions()
{
var repoName = Helper.MakeNameWithTimestamp("public-repo");
using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName)))
{
await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator);
await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, "alfhenrik");

var options = new ApiOptions
{
PageCount = 1,
PageSize = 2
};

var outsideCollaborators = await _client
.GetAll(Helper.Organization, OrganizationMembersFilter.All, options).ToList();

Assert.NotNull(outsideCollaborators);
Assert.Equal(2, outsideCollaborators.Count);
}
}

[IntegrationTest(Skip = "It seems this API endpoint does not support pagination as page size/count are not adhered to")]
public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithAllFilterWithStart()
{
var repoName = Helper.MakeNameWithTimestamp("public-repo");
using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName)))
{
await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator);
await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, "alfhenrik");

var firstPageOptions = new ApiOptions
{
PageCount = 1,
PageSize = 1,
StartPage = 1
};

var firstPageOfOutsideCollaborators = await _client
.GetAll(Helper.Organization, OrganizationMembersFilter.All, firstPageOptions).ToList();

var secondPageOptions = new ApiOptions
{
PageCount = 1,
PageSize = 1,
StartPage = 2
};

var secondPageOfOutsideCollaborators = await _client
.GetAll(Helper.Organization, OrganizationMembersFilter.All, secondPageOptions).ToList();

Assert.Equal(1, firstPageOfOutsideCollaborators.Count);
Assert.Equal(1, secondPageOfOutsideCollaborators.Count);
}
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithTwoFactorFilter()
{
Expand All @@ -80,6 +183,30 @@ public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithTwoFactorFilter()
Assert.Equal("alfhenrik-test-2", outsideCollaborators[0].Login);
}
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfOutsideCollaboratorsWithTwoFactorFilterAndApiOptions()
{
var repoName = Helper.MakeNameWithTimestamp("public-repo");
using (var context = await _gitHub.CreateRepositoryContext(Helper.Organization, new NewRepository(repoName)))
{
await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, _fixtureCollaborator);
await _gitHub.Repository.Collaborator.Add(context.RepositoryOwner, context.RepositoryName, "alfhenrik");

var options = new ApiOptions
{
PageCount = 1,
PageSize = 2
};

var outsideCollaborators = await _client
.GetAll(Helper.Organization, OrganizationMembersFilter.TwoFactorAuthenticationDisabled, options).ToList();

Assert.NotNull(outsideCollaborators);
Assert.Equal(1, outsideCollaborators.Count);
Assert.Equal("alfhenrik-test-2", outsideCollaborators[0].Login);
}
}
}

public class TheDeleteMethod
Expand Down
Loading

0 comments on commit 595e6e2

Please sign in to comment.