implement members except TEST

This commit is contained in:
Andy Cross
2014-01-20 16:16:20 +00:00
parent 170b0c459e
commit 828b77601c
4 changed files with 220 additions and 14 deletions

View File

@@ -53,5 +53,137 @@ namespace Octokit.Tests.Clients
await AssertEx.Throws<ArgumentNullException>(async () => await client.Hooks.GetById("owner", null, 123));
}
}
public class TheCreateMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoriesClient(connection);
var hook = new NewRepositoryHook();
client.Hooks.Create("fake", "repo", hook);
connection.Received().Post<RepositoryHook>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/hooks"), hook);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new RepositoriesClient(Substitute.For<IApiConnection>());
await AssertEx.Throws<ArgumentNullException>(async () => await client.Hooks.Create(null, "name", new NewRepositoryHook()));
await AssertEx.Throws<ArgumentNullException>(async () => await client.Hooks.Create("owner", null, new NewRepositoryHook()));
await AssertEx.Throws<ArgumentNullException>(async () => await client.Hooks.Create("owner", "name", null));
}
[Fact]
public void UsesTheSuppliedHook()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoriesClient(connection);
var newRepositoryHook = new NewRepositoryHook { Name = "aName" };
client.Hooks.Create("owner", "repo", newRepositoryHook);
connection.Received().Post<RepositoryHook>(Arg.Any<Uri>(), newRepositoryHook);
}
}
public class TheEditMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoriesClient(connection);
var hook = new EditRepositoryHook();
client.Hooks.Edit("fake", "repo", 12345678, hook);
connection.Received().Patch<RepositoryHook>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/hooks/12345678"), hook);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new RepositoriesClient(Substitute.For<IApiConnection>());
await AssertEx.Throws<ArgumentNullException>(async () => await client.Hooks.Edit(null, "name", 12345678, new EditRepositoryHook()));
await AssertEx.Throws<ArgumentNullException>(async () => await client.Hooks.Edit("owner", null, 12345678, new EditRepositoryHook()));
await AssertEx.Throws<ArgumentNullException>(async () => await client.Hooks.Edit("owner", "name", 12345678, null));
}
[Fact]
public void UsesTheSuppliedHook()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoriesClient(connection);
var editRepositoryHook = new EditRepositoryHook() { Active = false };
client.Hooks.Edit("owner", "repo", 12345678, editRepositoryHook);
connection.Received().Patch<RepositoryHook>(Arg.Any<Uri>(), editRepositoryHook);
}
}
public class TheTestMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoriesClient(connection);
client.Hooks.Test("fake", "repo", 12345678);
connection.Received().Post<RepositoryHook>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/hooks/12345678/tests"), null);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new RepositoriesClient(Substitute.For<IApiConnection>());
await AssertEx.Throws<ArgumentNullException>(async () => await client.Hooks.Test(null, "name", 12345678));
await AssertEx.Throws<ArgumentNullException>(async () => await client.Hooks.Test("owner", null, 12345678));
}
[Fact]
public void CallsPost()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoriesClient(connection);
client.Hooks.Test("owner", "repo", 12345678);
connection.Received().Post<RepositoryHook>(Arg.Any<Uri>(), Arg.Is<object>(o => o == null));
}
}
public class TheDeleteMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoriesClient(connection);
client.Hooks.Delete("fake", "repo", 12345678);
connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/hooks/12345678"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new RepositoriesClient(Substitute.For<IApiConnection>());
await AssertEx.Throws<ArgumentNullException>(async () => await client.Hooks.Delete(null, "name", 12345678));
await AssertEx.Throws<ArgumentNullException>(async () => await client.Hooks.Delete("owner", null, 12345678));
}
}
}
}

View File

@@ -8,7 +8,7 @@ namespace Octokit
/// <summary>
/// Gets the list of hooks defined for a repository
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#json-http">API documentation</a> for more information.</remarks>
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#list">API documentation</a> for more information.</remarks>
/// <returns></returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "This is ok; we're matching HTTP verbs not keyworks")]
Task<IReadOnlyList<RepositoryHook>> Get(string owner, string repositoryName);
@@ -23,12 +23,37 @@ namespace Octokit
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#get-single-hook">API documentation</a> for more information.</remarks>
Task<RepositoryHook> GetById(string owner, string repositoryName, int hookId);
/// <summary>
/// Creates a hook for a repository
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#create-a-hook">API documentation</a> for more information.</remarks>
/// <returns></returns>
Task<RepositoryHook> Create(string owner, string repositoryName, NewRepositoryHook hook);
Task<RepositoryHook> Edit(string owner, string repositoryName, string hookId, EditRepositoryHook hook);
/// <summary>
/// Edits a hook for a repository
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#edit-a-hook">API documentation</a> for more information.</remarks>
/// <returns></returns>
Task<RepositoryHook> Edit(string owner, string repositoryName, int hookId, EditRepositoryHook hook);
Task Test(string owner, string repositoryName, string hookId);
/// <summary>
/// Tests a hook for a repository
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#test-a-hook">API documentation</a> for more information.
/// This will trigger the hook with the latest push to the current repository if the hook is subscribed to push events. If the hook
/// is not subscribed to push events, the server will respond with 204 but no test POST will be generated.</remarks>
/// <returns></returns>
Task Test(string owner, string repositoryName, int hookId);
Task Delete(string owner, string repositoryName, string hookId);
/// <summary>
/// Deletes a hook for a repository
/// </summary>
/// <param name="owner"></param>
/// <param name="repositoryName"></param>
/// <param name="hookId"></param>
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#delete-a-hook">API documentation</a> for more information.</remarks>
/// <returns></returns>
Task Delete(string owner, string repositoryName, int hookId);
}
}

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Octokit
@@ -39,7 +40,7 @@ namespace Octokit
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
return ApiConnection.Get<RepositoryHook>(ApiUrls.RepositoryHooksById(owner, repositoryName, hookId));
return ApiConnection.Get<RepositoryHook>(ApiUrls.RepositoryHookById(owner, repositoryName, hookId));
}
/// <summary>
@@ -49,22 +50,58 @@ namespace Octokit
/// <returns></returns>
public Task<RepositoryHook> Create(string owner, string repositoryName, NewRepositoryHook hook)
{
throw new System.NotImplementedException();
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
Ensure.ArgumentNotNull(hook, "hook");
return ApiConnection.Post<RepositoryHook>(ApiUrls.RepositoryHooks(owner, repositoryName), hook);
}
public Task<RepositoryHook> Edit(string owner, string repositoryName, string hookId, EditRepositoryHook hook)
/// <summary>
/// Edits a hook for a repository
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#edit-a-hook">API documentation</a> for more information.</remarks>
/// <returns></returns>
public Task<RepositoryHook> Edit(string owner, string repositoryName, int hookId, EditRepositoryHook hook)
{
throw new System.NotImplementedException();
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
Ensure.ArgumentNotNull(hook, "hook");
return ApiConnection.Patch<RepositoryHook>(ApiUrls.RepositoryHookById(owner, repositoryName, hookId), hook);
}
public Task Test(string owner, string repositoryName, string hookId)
/// <summary>
/// Tests a hook for a repository
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#test-a-hook">API documentation</a> for more information.
/// This will trigger the hook with the latest push to the current repository if the hook is subscribed to push events. If the hook
/// is not subscribed to push events, the server will respond with 204 but no test POST will be generated.</remarks>
/// <returns></returns>
public Task Test(string owner, string repositoryName, int hookId)
{
throw new System.NotImplementedException();
throw new NotImplementedException();
//Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
//Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
//return ApiConnection.Post<object>(ApiUrls.RepositoryHookTest(owner, repositoryName, hookId), null);
}
public Task Delete(string owner, string repositoryName, string hookId)
/// <summary>
/// Deletes a hook for a repository
/// </summary>
/// <param name="owner"></param>
/// <param name="repositoryName"></param>
/// <param name="hookId"></param>
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#delete-a-hook">API documentation</a> for more information.</remarks>
/// <returns></returns>
public Task Delete(string owner, string repositoryName, int hookId)
{
throw new System.NotImplementedException();
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
return ApiConnection.Delete(ApiUrls.RepositoryHookById(owner, repositoryName, hookId));
}
}
}

View File

@@ -265,9 +265,21 @@ namespace Octokit
/// <param name="repositoryName">The name of the repository</param>
/// <param name="hookId">The identifier of the repository hook</param>
/// <returns></returns>
public static Uri RepositoryHooksById(string owner, string repositoryName, int hookId)
public static Uri RepositoryHookById(string owner, string repositoryName, int hookId)
{
return "repos/{0}/{1}/hooks/{2}".FormatUri(owner, repositoryName, hookId);
}
/// <summary>
/// Returns the <see cref="Uri"/> that can tests a specified repository hook
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repositoryName">The name of the repository</param>
/// <param name="hookId">The identifier of the repository hook</param>
/// <returns></returns>
public static Uri RepositoryHookTest(string owner, string repositoryName, int hookId)
{
return "repos/{0}/{1}/hooks/{2}/tests".FormatUri(owner, repositoryName, hookId);
}
}
}