missing files

This commit is contained in:
Andy Cross
2014-01-26 05:22:32 +00:00
parent 0c806d7298
commit e623632c3d
6 changed files with 237 additions and 0 deletions
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Octokit.Reactive
{
public interface IObservableRepositoryForksClient
{
/// <summary>
/// Gets the list of forks defined for a repository
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/forks/#list-forks">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")]
IObservable<IReadOnlyList<Repository>> Get(string owner, string repositoryName);
/// <summary>
/// Creates a fork for a repository. Specify organization in the fork parameter to create for an organization.
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/forks/#create-a-fork">API documentation</a> for more information.</remarks>
/// <returns></returns>
IObservable<Repository> Create(string owner, string repositoryName, NewRepositoryFork fork);
}
}
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Reactive.Threading.Tasks;
using System.Threading.Tasks;
namespace Octokit.Reactive
{
public class ObservableRepositoryForksClient : IObservableRepositoryForksClient
{
readonly IRepositoryForksClient _client;
/// <summary>
/// Initializes a new GitHub Repos Fork API client.
/// </summary>
/// <param name="client"></param>
public ObservableRepositoryForksClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_client = client.Repository.Forks;
}
/// <summary>
/// Gets the list of forks defined for a repository
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/forks/#list-forks">API documentation</a> for more information.</remarks>
/// <returns></returns>
public IObservable<IReadOnlyList<Repository>> Get(string owner, string repositoryName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
return _client.Get(owner, repositoryName).ToObservable();
}
/// <summary>
/// Creates a fork for a repository. Specify organization in the fork parameter to create for an organization.
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/forks/#create-a-fork">API documentation</a> for more information.</remarks>
/// <returns></returns>
public IObservable<Repository> Create(string owner, string repositoryName, NewRepositoryFork fork)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
Ensure.ArgumentNotNull(fork, "fork");
return _client.Create(owner, repositoryName, fork).ToObservable();
}
}
}
@@ -0,0 +1,71 @@
using System;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Tests.Helpers;
using Xunit;
namespace Octokit.Tests.Clients
{
public class RepositoryForksClientTests
{
public class TheGetMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoriesClient(connection);
client.Forks.Get("fake", "repo");
connection.Received().GetAll<Repository>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/forks"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new RepositoriesClient(Substitute.For<IApiConnection>());
await AssertEx.Throws<ArgumentNullException>(async () => await client.Forks.Get(null, "name"));
await AssertEx.Throws<ArgumentNullException>(async () => await client.Forks.Get("owner", null));
}
}
public class TheCreateMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoriesClient(connection);
var newRepositoryFork = new NewRepositoryFork();
client.Forks.Create("fake", "repo", newRepositoryFork);
connection.Received().Post<Repository>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/forks"), newRepositoryFork);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new RepositoriesClient(Substitute.For<IApiConnection>());
await AssertEx.Throws<ArgumentNullException>(async () => await client.Forks.Create(null, "name", new NewRepositoryFork()));
await AssertEx.Throws<ArgumentNullException>(async () => await client.Forks.Create("owner", null, new NewRepositoryFork()));
await AssertEx.Throws<ArgumentNullException>(async () => await client.Forks.Create("owner", "name", null));
}
[Fact]
public void UsesTheSuppliedHook()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoriesClient(connection);
var newRepositoryFork = new NewRepositoryFork { Organization = "aName" };
client.Forks.Create("owner", "repo", newRepositoryFork);
connection.Received().Post<Repository>(Arg.Any<Uri>(), newRepositoryFork);
}
}
}
}
+25
View File
@@ -0,0 +1,25 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Octokit
{
public interface IRepositoryForksClient
{
/// <summary>
/// Gets the list of forks defined for a repository
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/forks/#list-forks">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<Repository>> Get(string owner, string repositoryName);
/// <summary>
/// Creates a fork for a repository. Specify organization in the fork parameter to create for an organization.
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/forks/#create-a-fork">API documentation</a> for more information.</remarks>
/// <returns></returns>
Task<Repository> Create(string owner, string repositoryName, NewRepositoryFork fork);
}
}
+44
View File
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Octokit
{
public class RepositoryForksClient : ApiClient, IRepositoryForksClient
{
/// <summary>
/// Initializes a new GitHub Repos Fork API client.
/// </summary>
/// <param name="apiConnection">An API connection.</param>
public RepositoryForksClient(IApiConnection apiConnection) : base(apiConnection)
{
}
/// <summary>
/// Gets the list of forks defined for a repository
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/forks/#list-forks">API documentation</a> for more information.</remarks>
/// <returns></returns>
public Task<IReadOnlyList<Repository>> Get(string owner, string repositoryName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
return ApiConnection.GetAll<Repository>(ApiUrls.RepositoryForks(owner, repositoryName));
}
/// <summary>
/// Creates a fork for a repository. Specify organization in the fork parameter to create for an organization.
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/forks/#create-a-fork">API documentation</a> for more information.</remarks>
/// <returns></returns>
public Task<Repository> Create(string owner, string repositoryName, NewRepositoryFork fork)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
Ensure.ArgumentNotNull(fork, "fork");
return ApiConnection.Post<Repository>(ApiUrls.RepositoryForks(owner, repositoryName), fork);
}
}
}
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
namespace Octokit
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class NewRepositoryFork
{
public string Organization { get; set; }
internal string DebuggerDisplay
{
get
{
return String.Format(CultureInfo.InvariantCulture,
"Repository Hook: Organization: {0}", Organization);
}
}
}
}