add method to create a repository

This commit is contained in:
half-ogre
2013-10-01 17:16:30 -07:00
parent 5993c50bd2
commit e1dbeb4551
3 changed files with 57 additions and 0 deletions
@@ -24,6 +24,41 @@ namespace Octokit.Tests.Clients
}
}
public class TheCreateMethod
{
[Fact]
public async Task EnsuresNonNullArguments()
{
var repositoriesClient = new RepositoriesClient(Substitute.For<IApiConnection<Repository>>());
await AssertEx.Throws<ArgumentNullException>(async () => await repositoriesClient.Create(null));
await AssertEx.Throws<ArgumentException>(async () => await repositoriesClient.Create(new NewRepository { Name = null }));
}
[Fact]
public void UsesTheUserReposUrl()
{
var client = Substitute.For<IApiConnection<Repository>>();
var repositoriesClient = new RepositoriesClient(client);
repositoriesClient.Create(new NewRepository { Name = "aName" });
client.Received().Create(Arg.Is<Uri>(u => u.ToString() == "user/repos"), Arg.Any<NewRepository>());
}
[Fact]
public void TheNewRepositoryDescription()
{
var client = Substitute.For<IApiConnection<Repository>>();
var repositoriesClient = new RepositoriesClient(client);
var newRepository = new NewRepository { Name = "aName" };
repositoriesClient.Create(newRepository);
client.Received().Create(Arg.Any<Uri>(), newRepository);
}
}
public class TheGetMethod
{
[Fact]
+15
View File
@@ -11,6 +11,21 @@ namespace Octokit.Clients
{
}
/// <summary>
/// Creates a new repository for the current user.
/// </summary>
/// <param name="newRepository">A <see cref="NewRepository"/> instance describing the new repository to create</param>
/// <returns>A <see cref="Repository"/> instance for the created repository</returns>
public async Task<Repository> Create(NewRepository newRepository)
{
Ensure.ArgumentNotNull(newRepository, "newRepository");
if (string.IsNullOrEmpty(newRepository.Name))
throw new ArgumentException("The new repository's name must not be null.");
var endpoint = new Uri("user/repos", UriKind.Relative);
return await Client.Create(endpoint, newRepository);
}
public async Task<Repository> Get(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
+7
View File
@@ -6,6 +6,13 @@ namespace Octokit
{
public interface IRepositoriesClient
{
/// <summary>
/// Creates a new repository for the current user.
/// </summary>
/// <param name="newRepository">A <see cref="NewRepository"/> instance describing the new repository to create</param>
/// <returns>A <see cref="Repository"/> instance for the created repository</returns>
Task<Repository> Create(NewRepository newRepository);
/// <summary>
/// Retrieves the <see cref="Repository"/> for the specified owner and name.
/// </summary>