mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-06 03:55:55 +00:00
add method to create a repository
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user