Skip to content

Commit

Permalink
Merge pull request #1304 from shiftkey/shiftkey-repository-pages-api-…
Browse files Browse the repository at this point in the history
…options

Added ApiOption overloads to methods on I(Observable)RepositoryPagesClient
  • Loading branch information
shiftkey committed May 20, 2016
2 parents 3f39302 + cf4b09b commit 289cae5
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 9 deletions.
14 changes: 14 additions & 0 deletions Octokit.Reactive/Clients/IObservableRepositoryPagesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface IObservableRepositoryPagesClient
/// <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>
Expand All @@ -26,6 +27,19 @@ public interface IObservableRepositoryPagesClient
/// </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>
Expand Down
21 changes: 20 additions & 1 deletion Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,26 @@ public IObservable<PagesBuild> GetAll(string owner, string repositoryName)
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>
Expand Down
27 changes: 27 additions & 0 deletions Octokit.Tests.Integration/Clients/RepositoryPagesClientTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
2 changes: 2 additions & 0 deletions Octokit.Tests.Integration/Octokit.Tests.Integration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ public void Dispose()
{
Helper.DeleteRepo(_repository);
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
19 changes: 15 additions & 4 deletions Octokit.Tests/Clients/RepositoryPagesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task EnsuresNonNullArguments()
}
}

public class TheGetBuildsMethod
public class TheGetAllMethod
{
[Fact]
public void RequestsCorrectUrl()
Expand All @@ -51,7 +51,7 @@ public void RequestsCorrectUrl()

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]
Expand All @@ -60,8 +60,19 @@ public async Task EnsuresNonNullArguments()
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()));
}
}

Expand Down
1 change: 1 addition & 0 deletions Octokit.Tests/Octokit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
54 changes: 54 additions & 0 deletions Octokit.Tests/Reactive/ObservableRepositoryPagesClientTests.cs
Original file line number Diff line number Diff line change
@@ -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()));
}
}
}
}
16 changes: 15 additions & 1 deletion Octokit/Clients/IRepositoryPagesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,30 @@ public interface IRepositoryPagesClient
/// <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>
Expand Down
24 changes: 22 additions & 2 deletions Octokit/Clients/RepositoryPagesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Task<Page> Get(string owner, string repositoryName)
/// </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>
Expand All @@ -50,7 +50,27 @@ public Task<IReadOnlyList<PagesBuild>> GetAll(string owner, string repositoryNam
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>
Expand Down

0 comments on commit 289cae5

Please sign in to comment.