Add implementation and unit tests

This commit is contained in:
Mordechai Zuber
2016-01-17 22:33:02 +02:00
parent 1a5e3d15dc
commit 15c8ff9362
10 changed files with 218 additions and 10 deletions
@@ -0,0 +1,85 @@
using NSubstitute;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
namespace Octokit.Tests.Clients
{
public class RepositoryPagesClientTests
{
public class TheGetMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryPagesClient(connection);
client.Get("fake", "repo");
connection.Received().Get<Page>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pages"), null);
}
[Fact]
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));
}
}
public class TheGetBuildsMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryPagesClient(connection);
client.GetBuilds("fake", "repo");
connection.Received().GetAll<PagesBuild>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pages/builds"));
}
[Fact]
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));
}
}
public class TheGetLatestBuildMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryPagesClient(connection);
client.GetLatestBuild("fake", "repo");
connection.Received().Get<PagesBuild>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pages/builds/latest"), null);
}
[Fact]
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));
}
}
}
}
+1
View File
@@ -93,6 +93,7 @@
<Compile Include="Clients\FeedsClientTests.cs" />
<Compile Include="Clients\RepositoryDeployKeysClientTests.cs" />
<Compile Include="Clients\RepositoryContentsClientTests.cs" />
<Compile Include="Clients\RepositoryPagesClientTests.cs" />
<Compile Include="Clients\SearchClientTests.cs" />
<Compile Include="Clients\GistCommentsClientTests.cs" />
<Compile Include="Clients\GistsClientTests.cs" />
+9 -1
View File
@@ -269,7 +269,7 @@ namespace Octokit
/// See the <a href="http://developer.github.com/v3/repos/commits/">Commits API documentation</a> for more details
///</remarks>
IRepositoryCommitsClient Commit { get; }
/// <summary>
/// Access GitHub's Releases API.
/// </summary>
@@ -384,5 +384,13 @@ namespace Octokit
/// <param name="update">New values to update the branch with</param>
/// <returns>The updated <see cref="T:Octokit.Branch"/></returns>
Task<Branch> EditBranch(string owner, string name, string branch, BranchUpdate update);
/// <summary>
/// A client for GitHub's Repository Pages API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/">Repository Pages API documentation</a> for more information.
/// </remarks>
IRepositoryPagesClient Page { get; }
}
}
+16 -6
View File
@@ -1,32 +1,39 @@
using Octokit.Models.Response;
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Octokit.Clients
namespace Octokit
{
/// <summary>
/// A client for GitHub's Repository Pages API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages//">Repository Pages API documentation</a> for more information.
/// See the <a href="https://developer.github.com/v3/repos/pages/">Repository Pages API documentation</a> for more information.
/// </remarks>
interface IRepositoryPagesClient
public interface IRepositoryPagesClient
{
/// <summary>
/// Gets the page metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#get-information-about-a-pages-site">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
Task<IReadOnlyList<Page>> Get(string owner, string repositoryName);
[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="name">The name of the repository</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>> GetBuilds(string owner, string repositoryName);
/// <summary>
@@ -34,6 +41,9 @@ namespace Octokit.Clients
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-latest-pages-build">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
Task<PagesBuild> GetLatestBuild(string owner, string repositoryName);
}
+9
View File
@@ -44,6 +44,7 @@ namespace Octokit
DeployKeys = new RepositoryDeployKeysClient(apiConnection);
Merging = new MergingClient(apiConnection);
Content = new RepositoryContentsClient(apiConnection);
Page = new RepositoryPagesClient(apiConnection);
}
/// <summary>
@@ -577,5 +578,13 @@ namespace Octokit
return ApiConnection.Get<Branch>(ApiUrls.RepoBranch(owner, repositoryName, branchName), null, AcceptHeaders.ProtectedBranchesApiPreview);
}
/// <summary>
/// A client for GitHub's Repository Pages API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/">Repository Pages API documentation</a> for more information.
/// </remarks>
public IRepositoryPagesClient Page { get; private set; }
}
}
+77
View File
@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Octokit
{
/// <summary>
/// A client for GitHub's Repository Pages API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/">Repository Pages API documentation</a> for more information.
/// </remarks>
public class RepositoryPagesClient : ApiClient, IRepositoryPagesClient
{
/// <summary>
/// Initializes a new GitHub Repository Pages API client.
/// </summary>
/// <param name="apiConnection">An API connection.</param>
public RepositoryPagesClient(IApiConnection apiConnection) : base(apiConnection)
{
}
/// <summary>
/// Gets the page metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#get-information-about-a-pages-site">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
public Task<Page> Get(string owner, string repositoryName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
return ApiConnection.Get<Page>(ApiUrls.RepositoryPage(owner, repositoryName));
}
/// <summary>
/// Gets all build metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</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>> GetBuilds(string owner, string repositoryName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
return ApiConnection.GetAll<PagesBuild>(ApiUrls.RepositoryBuilds(owner, repositoryName));
}
/// <summary>
/// Gets the build metadata for the last build for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-latest-pages-build">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
public Task<PagesBuild> GetLatestBuild(string owner, string repositoryName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
return ApiConnection.Get<PagesBuild>(ApiUrls.RepositoryBuildsLatest(owner, repositoryName));
}
}
}
+15
View File
@@ -1554,5 +1554,20 @@ namespace Octokit
{
return "repos/{0}/{1}/contents/{2}?ref={3}".FormatUri(owner, name, path, reference);
}
public static Uri RepositoryPage(string owner, string name)
{
return "repos/{0}/{1}/pages".FormatUri(owner, name);
}
public static Uri RepositoryBuilds(string owner, string name)
{
return "repos/{0}/{1}/pages/builds".FormatUri(owner, name);
}
public static Uri RepositoryBuildsLatest(string owner, string name)
{
return "repos/{0}/{1}/pages/builds/latest".FormatUri(owner, name);
}
}
}
+1 -1
View File
@@ -7,7 +7,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Octokit.Models.Response
namespace Octokit
{
public enum PagesBuildStatus
{
+4 -2
View File
@@ -6,7 +6,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Octokit.Models.Response
namespace Octokit
{
/// <summary>
/// Metadata of a Github Pages build.
@@ -16,10 +16,11 @@ namespace Octokit.Models.Response
{
public PagesBuild() { }
public PagesBuild(string url, PagesBuildStatus status, User pusher, Commit commit, TimeSpan duration, DateTime createdAt, DateTime updatedAt)
public PagesBuild(string url, PagesBuildStatus status, ApiError error, User pusher, Commit commit, TimeSpan duration, DateTime createdAt, DateTime updatedAt)
{
Url = url;
Status = status;
Error = error;
Pusher = pusher;
Commit = commit;
Duration = duration;
@@ -35,6 +36,7 @@ namespace Octokit.Models.Response
/// The status of the build.
/// </summary>
public PagesBuildStatus Status { get; protected set; }
public ApiError Error { get; set; }
/// <summary>
/// The user whose commit intiated the build.
/// </summary>
+1
View File
@@ -73,6 +73,7 @@
<Compile Include="Clients\IFeedsClient.cs" />
<Compile Include="Clients\RepositoryCommitsClient.cs" />
<Compile Include="Clients\RepositoryDeployKeysClient.cs" />
<Compile Include="Clients\RepositoryPagesClient.cs" />
<Compile Include="Clients\UserKeysClient.cs" />
<Compile Include="Clients\RepositoryContentsClient.cs" />
<Compile Include="Exceptions\InvalidGitIgnoreTemplateException.cs" />