diff --git a/Octokit.Tests/Clients/RepositoriesClientTests.cs b/Octokit.Tests/Clients/RepositoriesClientTests.cs index 08a0ec5b..2c9a698d 100644 --- a/Octokit.Tests/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoriesClientTests.cs @@ -24,6 +24,41 @@ namespace Octokit.Tests.Clients } } + public class TheCreateMethod + { + [Fact] + public async Task EnsuresNonNullArguments() + { + var repositoriesClient = new RepositoriesClient(Substitute.For>()); + + await AssertEx.Throws(async () => await repositoriesClient.Create(null)); + await AssertEx.Throws(async () => await repositoriesClient.Create(new NewRepository { Name = null })); + } + + [Fact] + public void UsesTheUserReposUrl() + { + var client = Substitute.For>(); + var repositoriesClient = new RepositoriesClient(client); + + repositoriesClient.Create(new NewRepository { Name = "aName" }); + + client.Received().Create(Arg.Is(u => u.ToString() == "user/repos"), Arg.Any()); + } + + [Fact] + public void TheNewRepositoryDescription() + { + var client = Substitute.For>(); + var repositoriesClient = new RepositoriesClient(client); + var newRepository = new NewRepository { Name = "aName" }; + + repositoriesClient.Create(newRepository); + + client.Received().Create(Arg.Any(), newRepository); + } + } + public class TheGetMethod { [Fact] diff --git a/Octokit/Clients/RepositoriesClient.cs b/Octokit/Clients/RepositoriesClient.cs index e09e0dbb..37bca958 100644 --- a/Octokit/Clients/RepositoriesClient.cs +++ b/Octokit/Clients/RepositoriesClient.cs @@ -11,6 +11,21 @@ namespace Octokit.Clients { } + /// + /// Creates a new repository for the current user. + /// + /// A instance describing the new repository to create + /// A instance for the created repository + public async Task 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 Get(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); diff --git a/Octokit/IRepositoriesClient.cs b/Octokit/IRepositoriesClient.cs index b417028b..9d806439 100644 --- a/Octokit/IRepositoriesClient.cs +++ b/Octokit/IRepositoriesClient.cs @@ -6,6 +6,13 @@ namespace Octokit { public interface IRepositoriesClient { + /// + /// Creates a new repository for the current user. + /// + /// A instance describing the new repository to create + /// A instance for the created repository + Task Create(NewRepository newRepository); + /// /// Retrieves the for the specified owner and name. ///