Add ApiOptions overloads to methods on I(Observable)OrganizationMembersClient (#1332)

This commit is contained in:
Alexander Efremov
2016-06-01 21:16:55 +07:00
committed by Brendan Forster
parent a29752d363
commit 437bf91117
7 changed files with 802 additions and 43 deletions
@@ -31,7 +31,26 @@ namespace Octokit.Tests.Reactive
client.GetAll("org");
gitHubClient.Connection.Received(1).Get<List<User>>(
new Uri("orgs/org/members", UriKind.Relative), null, null);
new Uri("orgs/org/members", UriKind.Relative), Args.EmptyDictionary, null);
}
[Fact]
public void RequestsCorrectUrlWithApiOptions()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableOrganizationMembersClient(gitHubClient);
var options = new ApiOptions
{
PageCount = 1,
StartPage = 1,
PageSize = 1
};
client.GetAll("org", options);
gitHubClient.Connection.Received(1).Get<List<User>>(
new Uri("orgs/org/members", UriKind.Relative), Arg.Is<IDictionary<string, string>>(d => d.Count == 2), null);
}
[Fact]
@@ -39,8 +58,80 @@ namespace Octokit.Tests.Reactive
{
var client = new ObservableOrganizationMembersClient(Substitute.For<IGitHubClient>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("").ToTask());
Assert.Throws<ArgumentNullException>(() => client.GetAll(null));
Assert.Throws<ArgumentNullException>(() => client.GetAll(null, ApiOptions.None));
Assert.Throws<ArgumentNullException>(() => client.GetAll("org", null));
Assert.Throws<ArgumentNullException>(() => client.GetAll(null, OrganizationMembersFilter.All));
Assert.Throws<ArgumentNullException>(() => client.GetAll(null, OrganizationMembersFilter.All, ApiOptions.None));
Assert.Throws<ArgumentNullException>(() => client.GetAll("org", OrganizationMembersFilter.All, null));
Assert.Throws<ArgumentNullException>(() => client.GetAll(null, OrganizationMembersFilter.All, OrganizationMembersRole.Admin));
Assert.Throws<ArgumentNullException>(() => client.GetAll(null, OrganizationMembersFilter.All, OrganizationMembersRole.Admin, ApiOptions.None));
Assert.Throws<ArgumentNullException>(() => client.GetAll("org", OrganizationMembersFilter.All, OrganizationMembersRole.Admin, null));
Assert.Throws<ArgumentException>(() => client.GetAll(""));
Assert.Throws<ArgumentException>(() => client.GetAll("", ApiOptions.None));
Assert.Throws<ArgumentException>(() => client.GetAll("", OrganizationMembersFilter.All));
Assert.Throws<ArgumentException>(() => client.GetAll("", OrganizationMembersFilter.All, OrganizationMembersRole.Admin));
Assert.Throws<ArgumentException>(() => client.GetAll("", OrganizationMembersFilter.All, OrganizationMembersRole.Admin, ApiOptions.None));
}
[Fact]
public void TwoFactorFilterRequestTheCorrectUrlWithApiOptions()
{
var client = Substitute.For<IGitHubClient>();
var orgMembersClient = new ObservableOrganizationMembersClient(client);
var options = new ApiOptions
{
PageCount = 1,
StartPage = 1,
PageSize = 1
};
orgMembersClient.GetAll("org", OrganizationMembersFilter.TwoFactorAuthenticationDisabled, options);
client.Connection.Received(1).Get<List<User>>(
new Uri("orgs/org/members?filter=2fa_disabled", UriKind.Relative), Arg.Is<IDictionary<string, string>>(d => d.Count == 2), null);
}
[Fact]
public void MemberRoleFilterRequestTheCorrectUrlWithApiOptions()
{
var client = Substitute.For<IGitHubClient>();
var orgMembersClient = new ObservableOrganizationMembersClient(client);
var options = new ApiOptions
{
PageCount = 1,
StartPage = 1,
PageSize = 1
};
orgMembersClient.GetAll("org", OrganizationMembersRole.Member, options);
client.Connection.Received().Get<List<User>>(Arg.Is<Uri>(u => u.ToString() == "orgs/org/members?role=member"), Arg.Is<IDictionary<string, string>>(d => d.Count == 2), null);
}
[Fact]
public void TwoFactorFilterPlusMemberRoleRequestTheCorrectUrlWithApiOptions()
{
var client = Substitute.For<IGitHubClient>();
var orgMembersClient = new ObservableOrganizationMembersClient(client);
var options = new ApiOptions
{
PageCount = 1,
StartPage = 1,
PageSize = 1
};
orgMembersClient.GetAll("org", OrganizationMembersFilter.TwoFactorAuthenticationDisabled, OrganizationMembersRole.Member, options);
client.Connection.Received().Get<List<User>>(Arg.Is<Uri>(u => u.ToString() == "orgs/org/members?filter=2fa_disabled&role=member"), Arg.Is<IDictionary<string, string>>(d => d.Count == 2), null);
}
}
@@ -55,7 +146,26 @@ namespace Octokit.Tests.Reactive
client.GetAllPublic("org");
gitHubClient.Connection.Received(1).Get<List<User>>(
new Uri("orgs/org/public_members", UriKind.Relative), null, null);
new Uri("orgs/org/public_members", UriKind.Relative), Args.EmptyDictionary, null);
}
[Fact]
public void RequestsTheCorrectUrlWithApiOptions()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableOrganizationMembersClient(gitHubClient);
var options = new ApiOptions
{
PageCount = 1,
StartPage = 1,
PageSize = 1
};
client.GetAllPublic("org", options);
gitHubClient.Connection.Received(1).Get<List<User>>(
new Uri("orgs/org/public_members", UriKind.Relative), Arg.Is<IDictionary<string, string>>(d => d.Count == 2), null);
}
[Fact]
@@ -63,8 +173,12 @@ namespace Octokit.Tests.Reactive
{
var client = new ObservableOrganizationMembersClient(Substitute.For<IGitHubClient>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllPublic(null).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllPublic("").ToTask());
Assert.Throws<ArgumentNullException>(() => client.GetAllPublic(null));
Assert.Throws<ArgumentNullException>(() => client.GetAllPublic(null, ApiOptions.None));
Assert.Throws<ArgumentNullException>(() => client.GetAllPublic("org", null));
Assert.Throws<ArgumentException>(() => client.GetAllPublic(""));
Assert.Throws<ArgumentException>(() => client.GetAllPublic("", ApiOptions.None));
}
}