Add ApiOptions overloads to methods on I(Observable)RepositoryDeployKeysClient (#1307)

This commit is contained in:
Alexander Efremov
2016-05-20 18:45:34 +07:00
committed by Brendan Forster
parent 289cae568b
commit c4520123bf
7 changed files with 264 additions and 6 deletions

View File

@@ -53,7 +53,53 @@ namespace Octokit.Tests.Reactive
deployKeysClient.GetAll("user", "repo");
githubClient.Connection.Received(1).Get<List<DeployKey>>(
new Uri("repos/user/repo/keys", UriKind.Relative), null, null);
new Uri("repos/user/repo/keys", UriKind.Relative), Arg.Is<Dictionary<string, string>>(dictionary => dictionary.Count == 0), null);
}
[Fact]
public void GetsCorrectUrlWithApiOptions()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var deployKeysClient = new ObservableRepositoryDeployKeysClient(gitHubClient);
var expectedUrl = string.Format("repos/{0}/{1}/keys", "user", "repo");
// all properties are setted => only 2 options (StartPage, PageSize) in dictionary
var options = new ApiOptions
{
StartPage = 1,
PageCount = 1,
PageSize = 1
};
deployKeysClient.GetAll("user", "repo", options);
gitHubClient.Connection.Received(1)
.Get<List<DeployKey>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 2),
null);
// StartPage is setted => only 1 option (StartPage) in dictionary
options = new ApiOptions
{
StartPage = 1
};
deployKeysClient.GetAll("user", "repo", options);
gitHubClient.Connection.Received(1)
.Get<List<DeployKey>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 1),
null);
// PageCount is setted => none of options in dictionary
options = new ApiOptions
{
PageCount = 1
};
deployKeysClient.GetAll("user", "repo", options);
gitHubClient.Connection.Received(1)
.Get<List<DeployKey>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 0),
null);
}
[Fact]
@@ -61,10 +107,22 @@ namespace Octokit.Tests.Reactive
{
var deployKeysClient = new ObservableRepositoryDeployKeysClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll(null, null));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll(null, "repo"));
Assert.Throws<ArgumentException>(() => deployKeysClient.GetAll("", "repo"));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll("user", null));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll(null, null, null));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll(null, null, ApiOptions.None));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll(null, "repo", null));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll("user", null, null));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll(null, "repo", ApiOptions.None));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll("user", null, ApiOptions.None));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll("user", "repo", null));
Assert.Throws<ArgumentException>(() => deployKeysClient.GetAll("user", ""));
Assert.Throws<ArgumentException>(() => deployKeysClient.GetAll("", "repo"));
}
}