Merge pull request #1304 from shiftkey/shiftkey-repository-pages-api-options

Added ApiOption overloads to methods on I(Observable)RepositoryPagesClient
This commit is contained in:
Brendan Forster
2016-05-20 14:02:13 +03:00
11 changed files with 217 additions and 9 deletions
@@ -16,6 +16,7 @@ namespace Octokit.Reactive
/// <returns></returns>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
IObservable<Page> Get(string owner, string repositoryName);
/// <summary>
/// Gets all build metadata for a given repository
/// </summary>
@@ -26,6 +27,19 @@ namespace Octokit.Reactive
/// </remarks>
/// <returns></returns>
IObservable<PagesBuild> GetAll(string owner, string repositoryName);
/// <summary>
/// Gets all build metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repositoryName">The name of the repository</param>
/// <param name="options">Options to change the API response</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-pages-builds">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
IObservable<PagesBuild> GetAll(string owner, string repositoryName, ApiOptions options);
/// <summary>
/// Gets the build metadata for the last build for a given repository
/// </summary>
@@ -50,7 +50,26 @@ namespace Octokit.Reactive
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
return _connection.GetAndFlattenAllPages<PagesBuild>(ApiUrls.RepositoryPageBuilds(owner, repositoryName));
return GetAll(owner, repositoryName, ApiOptions.None);
}
/// <summary>
/// Gets all build metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repositoryName">The name of the repository</param>
/// <param name="options">Options to change the API response</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-pages-builds">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
public IObservable<PagesBuild> GetAll(string owner, string repositoryName, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages<PagesBuild>(ApiUrls.RepositoryPageBuilds(owner, repositoryName), options);
}
/// <summary>
@@ -0,0 +1,27 @@
using System.Threading.Tasks;
using Octokit;
using Octokit.Tests.Integration;
using Xunit;
public class RepositoryPagesClientTests
{
public class TheGetMethod
{
readonly IRepositoryPagesClient _repositoryPagesClient;
const string owner = "octokit";
const string name = "octokit.net";
public TheGetMethod()
{
var github = Helper.GetAuthenticatedClient();
_repositoryPagesClient = github.Repository.Page;
}
[IntegrationTest(Skip= "These tests require repository admin rights - see https://github.com/octokit/octokit.net/issues/1263 for discussion")]
public async Task ReturnsMetadata()
{
var data = await _repositoryPagesClient.Get(owner, name);
Assert.Equal("https://api.github.com/repos/octokit/octokit.net/pages", data.Url);
}
}
}
@@ -101,6 +101,7 @@
<Compile Include="Clients\RepositoryDeployKeysClientTests.cs" />
<Compile Include="Clients\RepositoryForksClientTests.cs" />
<Compile Include="Clients\RepositoryHooksClientTests.cs" />
<Compile Include="Clients\RepositoryPagesClientTests.cs" />
<Compile Include="Clients\SearchClientTests.cs" />
<Compile Include="Clients\StarredClientTests.cs" />
<Compile Include="Clients\StatisticsClientTests.cs" />
@@ -155,6 +156,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Helper.cs" />
<Compile Include="Clients\UsersClientTests.cs" />
<Compile Include="Reactive\ObservableRepositoryPagesClientTests.cs" />
<Compile Include="Reactive\ObservableRepositoryCommitsClientTests.cs" />
<Compile Include="Reactive\ObservableRepositoryHooksClientTests.cs" />
<Compile Include="Reactive\ObservableUserAdministrationClientTests.cs" />
@@ -103,4 +103,4 @@ public class ObservableRespositoryDeployKeysClientTests : IDisposable
{
Helper.DeleteRepo(_repository);
}
}
}
@@ -0,0 +1,46 @@
using System.Reactive.Linq;
using System.Threading.Tasks;
using Octokit.Reactive;
using Xunit;
namespace Octokit.Tests.Integration.Reactive
{
public class ObservableRepositoryPagesClientTests
{
public class TheGetAllMethod
{
readonly ObservableRepositoryPagesClient _repositoryPagesClient;
const string owner = "octokit";
const string name = "octokit.net";
public TheGetAllMethod()
{
var github = Helper.GetAuthenticatedClient();
_repositoryPagesClient = new ObservableRepositoryPagesClient(github);
}
[IntegrationTest(Skip = "These tests require repository admin rights - see https://github.com/octokit/octokit.net/issues/1263 for discussion")]
public async Task ReturnsAllRepositoryPagesBuilds()
{
var pages = await _repositoryPagesClient.GetAll(owner, name).ToList();
Assert.NotEmpty(pages);
}
[IntegrationTest(Skip = "These tests require repository admin rights - see https://github.com/octokit/octokit.net/issues/1263 for discussion")]
public async Task ReturnsPageOfRepositoryBuilds()
{
var options = new ApiOptions
{
PageSize= 5,
PageCount = 1
};
var pages = await _repositoryPagesClient.GetAll(owner, name, options).ToList();
Assert.Equal(5, pages.Count);
}
}
}
}
@@ -41,7 +41,7 @@ namespace Octokit.Tests.Clients
}
}
public class TheGetBuildsMethod
public class TheGetAllMethod
{
[Fact]
public void RequestsCorrectUrl()
@@ -51,7 +51,7 @@ namespace Octokit.Tests.Clients
client.GetAll("fake", "repo");
connection.Received().GetAll<PagesBuild>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pages/builds"));
connection.Received().GetAll<PagesBuild>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pages/builds"), Args.ApiOptions);
}
[Fact]
@@ -60,8 +60,19 @@ namespace Octokit.Tests.Clients
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryPagesClient(connection);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "name"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, "name", new ApiOptions()));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", null, new ApiOptions()));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", "name", null));
}
[Fact]
public async Task EnsuresNonEmptyArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryPagesClient(connection);
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name", new ApiOptions()));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "", new ApiOptions()));
}
}
+1
View File
@@ -220,6 +220,7 @@
<Compile Include="Reactive\ObservablePullRequestReviewCommentsClientTests.cs" />
<Compile Include="Reactive\ObservableRepositoriesClientTests.cs" />
<Compile Include="Reactive\ObservableRepositoryCommitsClientTests.cs" />
<Compile Include="Reactive\ObservableRepositoryPagesClientTests.cs"/>
<Compile Include="Reactive\ObservableRepositoryDeployKeysClientTests.cs" />
<Compile Include="Reactive\ObservableGistsTests.cs" />
<Compile Include="Reactive\ObservableRepositoryHooksClientTests.cs" />
@@ -0,0 +1,54 @@
using System;
using NSubstitute;
using Octokit.Reactive;
using Xunit;
namespace Octokit.Tests.Reactive
{
public class ObservableRepositoryPagesClientTests
{
public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ObservableRepositoryPagesClient(null));
}
}
public class TheGetAllMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var githubClient = Substitute.For<IGitHubClient>();
var client = new ObservableRepositoryPagesClient(githubClient);
var options = new ApiOptions();
client.GetAll("fake", "repo", options);
githubClient.Received().Repository.Page.GetAll("fake", "repo", options);
}
[Fact]
public void EnsuresNonNullArguments()
{
var githubClient = Substitute.For<IGitHubClient>();
var client = new ObservableRepositoryPagesClient(githubClient);
Assert.Throws<ArgumentNullException>(() => client.GetAll(null, "repo", new ApiOptions()));
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", null, new ApiOptions()));
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", "repo", null));
}
[Fact]
public void EnsuresNonEmptyArguments()
{
var githubClient = Substitute.For<IGitHubClient>();
var client = new ObservableRepositoryPagesClient(githubClient);
Assert.Throws<ArgumentException>(() => client.GetAll("", "repo", new ApiOptions()));
Assert.Throws<ArgumentException>(() => client.GetAll("owner", "", new ApiOptions()));
}
}
}
}
+15 -1
View File
@@ -23,16 +23,30 @@ namespace Octokit
/// <returns></returns>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
Task<Page> Get(string owner, string repositoryName);
/// <summary>
/// Gets all build metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repositoryName">The name of the repository</param>
/// <remarks>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-pages-builds">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
Task<IReadOnlyList<PagesBuild>> GetAll(string owner, string repositoryName);
/// <summary>
/// Gets all build metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repositoryName">The name of the repository</param>
/// <param name="options">Options to change the API response</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-pages-builds">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
Task<IReadOnlyList<PagesBuild>> GetAll(string owner, string repositoryName, ApiOptions options);
/// <summary>
/// Gets the build metadata for the last build for a given repository
/// </summary>
+22 -2
View File
@@ -41,7 +41,7 @@ namespace Octokit
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repositoryName">The name of the repository</param>
/// <remarks>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-pages-builds">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
@@ -50,7 +50,27 @@ namespace Octokit
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
return ApiConnection.GetAll<PagesBuild>(ApiUrls.RepositoryPageBuilds(owner, repositoryName));
return GetAll(owner, repositoryName, ApiOptions.None);
}
/// <summary>
/// Gets all build metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repositoryName">The name of the repository</param>
/// <param name="options">Options to change the API response</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-pages-builds">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
public Task<IReadOnlyList<PagesBuild>> GetAll(string owner, string repositoryName, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
Ensure.ArgumentNotNull(options, "options");
var endpoint = ApiUrls.RepositoryPageBuilds(owner, repositoryName);
return ApiConnection.GetAll<PagesBuild>(endpoint, options);
}
/// <summary>