Add repositoryId overloads to methods on I(Observable)RepositoryDeployKeysClient (#1351)

This commit is contained in:
Alexander Efremov
2016-06-18 05:02:28 +07:00
committed by Brendan Forster
parent d941f62904
commit 3d97346672
7 changed files with 608 additions and 64 deletions

View File

@@ -4,6 +4,12 @@ using System.Reactive;
namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Repository Deploy Keys API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/">Deploy Keys API documentation</a> for more information.
/// </remarks>
public interface IObservableRepositoryDeployKeysClient
{
/// <summary>
@@ -18,6 +24,17 @@ namespace Octokit.Reactive
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
IObservable<DeployKey> Get(string owner, string name, int number);
/// <summary>
/// Get a single deploy key by number for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#get"> API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The ID of the repository.</param>
/// <param name="number">The id of the deploy key.</param>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
IObservable<DeployKey> Get(int repositoryId, int number);
/// <summary>
/// Get all deploy keys for a repository.
/// </summary>
@@ -28,6 +45,15 @@ namespace Octokit.Reactive
/// <param name="name">The name of the repository.</param>
IObservable<DeployKey> GetAll(string owner, string name);
/// <summary>
/// Get all deploy keys for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#list"> API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The ID of the repository.</param>
IObservable<DeployKey> GetAll(int repositoryId);
/// <summary>
/// Get all deploy keys for a repository.
/// </summary>
@@ -39,6 +65,16 @@ namespace Octokit.Reactive
/// <param name="options">Options for changing the API response</param>
IObservable<DeployKey> GetAll(string owner, string name, ApiOptions options);
/// <summary>
/// Get all deploy keys for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#list"> API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The ID of the repository.</param>
/// <param name="options">Options for changing the API response</param>
IObservable<DeployKey> GetAll(int repositoryId, ApiOptions options);
/// <summary>
/// Creates a new deploy key for a repository.
/// </summary>
@@ -48,9 +84,18 @@ namespace Octokit.Reactive
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the repository.</param>
/// <param name="newDeployKey">The deploy key to create for the repository.</param>
/// <returns></returns>
IObservable<DeployKey> Create(string owner, string name, NewDeployKey newDeployKey);
/// <summary>
/// Creates a new deploy key for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#create"> API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The ID of the repository.</param>
/// <param name="newDeployKey">The deploy key to create for the repository.</param>
IObservable<DeployKey> Create(int repositoryId, NewDeployKey newDeployKey);
/// <summary>
/// Deletes a deploy key from a repository.
/// </summary>
@@ -60,7 +105,16 @@ namespace Octokit.Reactive
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the repository.</param>
/// <param name="number">The id of the deploy key to delete.</param>
/// <returns></returns>
IObservable<Unit> Delete(string owner, string name, int number);
/// <summary>
/// Deletes a deploy key from a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#delete"> API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The ID of the repository.</param>
/// <param name="number">The id of the deploy key to delete.</param>
IObservable<Unit> Delete(int repositoryId, int number);
}
}
}

View File

@@ -5,6 +5,12 @@ using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Repository Deploy Keys API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/">Deploy Keys API documentation</a> for more information.
/// </remarks>
public class ObservableRepositoryDeployKeysClient : IObservableRepositoryDeployKeysClient
{
readonly IRepositoryDeployKeysClient _client;
@@ -35,6 +41,19 @@ namespace Octokit.Reactive
return _client.Get(owner, name, number).ToObservable();
}
/// <summary>
/// Get a single deploy key by number for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#get"> API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The ID of the repository.</param>
/// <param name="number">The id of the deploy key.</param>
public IObservable<DeployKey> Get(int repositoryId, int number)
{
return _client.Get(repositoryId, number).ToObservable();
}
/// <summary>
/// Get all deploy keys for a repository.
/// </summary>
@@ -51,6 +70,18 @@ namespace Octokit.Reactive
return GetAll(owner, name, ApiOptions.None);
}
/// <summary>
/// Get all deploy keys for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#list"> API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The ID of the repository.</param>
public IObservable<DeployKey> GetAll(int repositoryId)
{
return GetAll(repositoryId, ApiOptions.None);
}
/// <summary>
/// Get all deploy keys for a repository.
/// </summary>
@@ -69,6 +100,21 @@ namespace Octokit.Reactive
return _connection.GetAndFlattenAllPages<DeployKey>(ApiUrls.RepositoryDeployKeys(owner, name), options);
}
/// <summary>
/// Get all deploy keys for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#list"> API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The ID of the repository.</param>
/// <param name="options">Options for changing the API response</param>
public IObservable<DeployKey> GetAll(int repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages<DeployKey>(ApiUrls.RepositoryDeployKeys(repositoryId), options);
}
/// <summary>
/// Creates a new deploy key for a repository.
/// </summary>
@@ -78,7 +124,6 @@ namespace Octokit.Reactive
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the repository.</param>
/// <param name="newDeployKey">The deploy key to create for the repository.</param>
/// <returns></returns>
public IObservable<DeployKey> Create(string owner, string name, NewDeployKey newDeployKey)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
@@ -95,6 +140,28 @@ namespace Octokit.Reactive
return _client.Create(owner, name, newDeployKey).ToObservable();
}
/// <summary>
/// Creates a new deploy key for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#create"> API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The ID of the repository.</param>
/// <param name="newDeployKey">The deploy key to create for the repository.</param>
public IObservable<DeployKey> Create(int repositoryId, NewDeployKey newDeployKey)
{
Ensure.ArgumentNotNull(newDeployKey, "newDeployKey");
if (string.IsNullOrWhiteSpace(newDeployKey.Title))
throw new ArgumentException("The new deploy key's title must not be null.");
if (string.IsNullOrWhiteSpace(newDeployKey.Key))
throw new ArgumentException("The new deploy key's key must not be null.");
return _client.Create(repositoryId, newDeployKey).ToObservable();
}
/// <summary>
/// Deletes a deploy key from a repository.
/// </summary>
@@ -104,7 +171,6 @@ namespace Octokit.Reactive
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the repository.</param>
/// <param name="number">The id of the deploy key to delete.</param>
/// <returns></returns>
public IObservable<Unit> Delete(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
@@ -112,5 +178,18 @@ namespace Octokit.Reactive
return _client.Delete(owner, name, number).ToObservable();
}
/// <summary>
/// Deletes a deploy key from a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#delete"> API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The ID of the repository.</param>
/// <param name="number">The id of the deploy key to delete.</param>
public IObservable<Unit> Delete(int repositoryId, int number)
{
return _client.Delete(repositoryId, number).ToObservable();
}
}
}
}

View File

@@ -37,6 +37,21 @@ public class RepositoryDeployKeysClientTests : IDisposable
Assert.Equal(_keyTitle, deployKeyResult.Title);
}
[IntegrationTest(Skip = "see https://github.com/octokit/octokit.net/issues/533 for investigating this failing test")]
public async Task CanCreateADeployKeyWithRepositoryId()
{
var deployKey = new NewDeployKey
{
Key = _key,
Title = _keyTitle
};
var deployKeyResult = await _fixture.Create(_context.Repository.Id, deployKey);
Assert.NotNull(deployKeyResult);
Assert.Equal(_key, deployKeyResult.Key);
Assert.Equal(_keyTitle, deployKeyResult.Title);
}
[IntegrationTest(Skip = "See https://github.com/octokit/octokit.net/issues/1003 for investigating this failing test")]
public async Task CanRetrieveAllDeployKeys()
{
@@ -57,6 +72,26 @@ public class RepositoryDeployKeysClientTests : IDisposable
Assert.Equal(_keyTitle, deployKeys[0].Title);
}
[IntegrationTest(Skip = "See https://github.com/octokit/octokit.net/issues/1003 for investigating this failing test")]
public async Task CanRetrieveAllDeployKeysWithRepositoryId()
{
var deployKeys = await _fixture.GetAll(_context.RepositoryOwner, _context.RepositoryName);
Assert.Equal(0, deployKeys.Count);
var deployKey = new NewDeployKey
{
Key = _key,
Title = _keyTitle
};
await _fixture.Create(_context.Repository.Id, deployKey);
deployKeys = await _fixture.GetAll(_context.Repository.Id);
Assert.Equal(1, deployKeys.Count);
Assert.Equal(_key, deployKeys[0].Key);
Assert.Equal(_keyTitle, deployKeys[0].Title);
}
[IntegrationTest(Skip = "See https://github.com/octokit/octokit.net/issues/1003 for investigating this failing test")]
public async Task ReturnsCorrectCountOfDeployKeysWithoutStart()
{
@@ -166,6 +201,46 @@ public class RepositoryDeployKeysClientTests : IDisposable
Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
}
[IntegrationTest(Skip = "See https://github.com/octokit/octokit.net/issues/1003 for investigating this failing test")]
public async Task ReturnsDistinctResultsBasedOnStartPageWithRepositoryId()
{
var list = new List<NewDeployKey>();
var deployKeysCount = 5;
for (int i = 0; i < deployKeysCount; i++)
{
var item = new NewDeployKey
{
Key = "ssh-rsa A" + i, // here we should genereate ssh-key some how
Title = "KeyTitle" + i
};
list.Add(item);
}
foreach (var key in list)
{
await _fixture.Create(_context.Repository.Id, key);
}
var startOptions = new ApiOptions
{
PageSize = 2,
PageCount = 1
};
var firstPage = await _fixture.GetAll(_context.Repository.Id, startOptions);
var skipStartOptions = new ApiOptions
{
PageSize = 2,
PageCount = 1,
StartPage = 2
};
var secondPage = await _fixture.GetAll(_context.Repository.Id, skipStartOptions);
Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
}
[IntegrationTest(Skip = "see https://github.com/octokit/octokit.net/issues/533 for the resolution to this failing test")]
public async Task CanRetrieveADeployKey()
{
@@ -183,6 +258,23 @@ public class RepositoryDeployKeysClientTests : IDisposable
Assert.Equal(_keyTitle, deployKey.Title);
}
[IntegrationTest(Skip = "see https://github.com/octokit/octokit.net/issues/533 for the resolution to this failing test")]
public async Task CanRetrieveADeployKeyWithRepositoryId()
{
var newDeployKey = new NewDeployKey
{
Key = _key,
Title = _keyTitle
};
var deployKeyResult = await _fixture.Create(_context.Repository.Id, newDeployKey);
var deployKey = await _fixture.Get(_context.Repository.Id, deployKeyResult.Id);
Assert.NotNull(deployKey);
Assert.Equal(deployKeyResult.Id, deployKey.Id);
Assert.Equal(_key, deployKey.Key);
Assert.Equal(_keyTitle, deployKey.Title);
}
[IntegrationTest(Skip = "see https://github.com/octokit/octokit.net/issues/533 for the resolution to this failing test")]
public async Task CanRemoveADeployKey()
{
@@ -204,6 +296,27 @@ public class RepositoryDeployKeysClientTests : IDisposable
Assert.Equal(0, deployKeys.Count);
}
[IntegrationTest(Skip = "see https://github.com/octokit/octokit.net/issues/533 for the resolution to this failing test")]
public async Task CanRemoveADeployKeyWithRepositoryId()
{
var newDeployKey = new NewDeployKey
{
Key = _key,
Title = _keyTitle
};
await _fixture.Create(_context.Repository.Id, newDeployKey);
var deployKeys = await _fixture.GetAll(_context.Repository.Id);
Assert.Equal(1, deployKeys.Count);
Assert.Equal(_key, deployKeys[0].Key);
Assert.Equal(_keyTitle, deployKeys[0].Title);
await _fixture.Delete(_context.Repository.Id, deployKeys[0].Id);
deployKeys = await _fixture.GetAll(_context.Repository.Id);
Assert.Equal(0, deployKeys.Count);
}
public void Dispose()
{
_context.Dispose();

View File

@@ -23,24 +23,36 @@ namespace Octokit.Tests.Clients
public class TheGetMethod
{
[Fact]
public void GetsADeployKey()
public async Task RequestsCorrectUrl()
{
var apiConnection = Substitute.For<IApiConnection>();
var deployKeysClient = new RepositoryDeployKeysClient(apiConnection);
deployKeysClient.Get("user", "repo", 42);
await deployKeysClient.Get("user", "repo", 42);
apiConnection.Received().Get<DeployKey>(Arg.Is<Uri>(u => u.ToString() == "repos/user/repo/keys/42"));
}
[Fact]
public async Task RequestsCorrectUrlWithRepositoryId()
{
var apiConnection = Substitute.For<IApiConnection>();
var deployKeysClient = new RepositoryDeployKeysClient(apiConnection);
await deployKeysClient.Get(1, 42);
apiConnection.Received().Get<DeployKey>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/keys/42"));
}
[Fact]
public async Task EnsureNonNullArguments()
{
var deployKeysClient = new RepositoryDeployKeysClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => deployKeysClient.Get(null, "repo", 1));
await Assert.ThrowsAsync<ArgumentException>(() => deployKeysClient.Get("", "repo", 1));
await Assert.ThrowsAsync<ArgumentNullException>(() => deployKeysClient.Get("user", null, 1));
await Assert.ThrowsAsync<ArgumentException>(() => deployKeysClient.Get("", "repo", 1));
await Assert.ThrowsAsync<ArgumentException>(() => deployKeysClient.Get("user", "", 1));
}
}
@@ -48,18 +60,29 @@ namespace Octokit.Tests.Clients
public class TheGetAllMethod
{
[Fact]
public void GetsAListOfDeployKeys()
public async Task RequestsCorrectUrl()
{
var apiConnection = Substitute.For<IApiConnection>();
var deployKeysClient = new RepositoryDeployKeysClient(apiConnection);
deployKeysClient.GetAll("user", "repo");
await deployKeysClient.GetAll("user", "repo");
apiConnection.Received().GetAll<DeployKey>(Arg.Is<Uri>(u => u.ToString() == "repos/user/repo/keys"), Args.ApiOptions);
}
[Fact]
public void GetsAListOfDeployKeysWithApiOptions()
public async Task RequestsCorrectUrlWithRepositoryId()
{
var apiConnection = Substitute.For<IApiConnection>();
var deployKeysClient = new RepositoryDeployKeysClient(apiConnection);
await deployKeysClient.GetAll(1);
apiConnection.Received().GetAll<DeployKey>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/keys"), Args.ApiOptions);
}
[Fact]
public async Task RequestsCorrectUrlWithApiOptions()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryDeployKeysClient(connection);
@@ -71,49 +94,81 @@ namespace Octokit.Tests.Clients
StartPage = 1
};
client.GetAll("user", "repo", options);
await client.GetAll("user", "repo", options);
connection.Received(1)
.GetAll<DeployKey>(Arg.Is<Uri>(u => u.ToString() == "repos/user/repo/keys"),
options);
}
[Fact]
public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryDeployKeysClient(connection);
var options = new ApiOptions
{
PageCount = 1,
PageSize = 1,
StartPage = 1
};
await client.GetAll(1, options);
connection.Received(1)
.GetAll<DeployKey>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/keys"),
options);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var deployKeysClient = new RepositoryDeployKeysClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => deployKeysClient.GetAll(null, null));
await Assert.ThrowsAsync<ArgumentNullException>(() => deployKeysClient.GetAll(null, "repo"));
await Assert.ThrowsAsync<ArgumentNullException>(() => deployKeysClient.GetAll("user", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => deployKeysClient.GetAll(null, null, null));
await Assert.ThrowsAsync<ArgumentNullException>(() => deployKeysClient.GetAll(null, null, ApiOptions.None));
await Assert.ThrowsAsync<ArgumentNullException>(() => deployKeysClient.GetAll(null, "repo", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => deployKeysClient.GetAll("user", null, null));
await Assert.ThrowsAsync<ArgumentNullException>(() => deployKeysClient.GetAll(null, "repo", ApiOptions.None));
await Assert.ThrowsAsync<ArgumentNullException>(() => deployKeysClient.GetAll("user", null, ApiOptions.None));
await Assert.ThrowsAsync<ArgumentNullException>(() => deployKeysClient.GetAll("user", "repo", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => deployKeysClient.GetAll(1, null));
await Assert.ThrowsAsync<ArgumentException>(() => deployKeysClient.GetAll("user", ""));
await Assert.ThrowsAsync<ArgumentException>(() => deployKeysClient.GetAll("", "repo"));
await Assert.ThrowsAsync<ArgumentException>(() => deployKeysClient.GetAll("", "repo", ApiOptions.None));
await Assert.ThrowsAsync<ArgumentException>(() => deployKeysClient.GetAll("user", "", ApiOptions.None));
}
}
public class TheCreateMethod
{
[Fact]
public void SendsCreateToCorrectUrl()
public void CreatesCorrectUrl()
{
var apiConnection = Substitute.For<IApiConnection>();
var deployKeysClient = new RepositoryDeployKeysClient(apiConnection);
deployKeysClient.Create("user", "repo", new NewDeployKey { Key = "ABC123", Title = "user@repo" });
var newDeployKey = new NewDeployKey { Key = "ABC123", Title = "user@repo" };
deployKeysClient.Create("user", "repo", newDeployKey);
apiConnection.Received().Post<DeployKey>(Arg.Is<Uri>(u => u.ToString() == "repos/user/repo/keys"),
Args.NewDeployKey);
newDeployKey);
}
[Fact]
public void CreatesCorrectUrlWithRepositoryId()
{
var apiConnection = Substitute.For<IApiConnection>();
var deployKeysClient = new RepositoryDeployKeysClient(apiConnection);
var newDeployKey = new NewDeployKey { Key = "ABC123", Title = "user@repo" };
deployKeysClient.Create(1, newDeployKey);
apiConnection.Received().Post<DeployKey>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/keys"),
newDeployKey);
}
[Fact]
@@ -122,10 +177,14 @@ namespace Octokit.Tests.Clients
var deployKeysClient = new RepositoryDeployKeysClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => deployKeysClient.Create(null, "repo", new NewDeployKey()));
await Assert.ThrowsAsync<ArgumentException>(() => deployKeysClient.Create("", "repo", new NewDeployKey()));
await Assert.ThrowsAsync<ArgumentNullException>(() => deployKeysClient.Create("user", null, new NewDeployKey()));
await Assert.ThrowsAsync<ArgumentException>(() => deployKeysClient.Create("user", "", new NewDeployKey()));
await Assert.ThrowsAsync<ArgumentNullException>(() => deployKeysClient.Create("user", "repo", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => deployKeysClient.Create(1, null));
await Assert.ThrowsAsync<ArgumentException>(() => deployKeysClient.Create("", "repo", new NewDeployKey()));
await Assert.ThrowsAsync<ArgumentException>(() => deployKeysClient.Create("user", "", new NewDeployKey()));
await Assert.ThrowsAsync<ArgumentException>(() => deployKeysClient.Create("user", "repo", new NewDeployKey()));
await Assert.ThrowsAsync<ArgumentException>(() => deployKeysClient.Create("user", "repo", new NewDeployKey { Key = "ABC123" }));
await Assert.ThrowsAsync<ArgumentException>(() => deployKeysClient.Create("user", "repo", new NewDeployKey { Title = "user@repo" }));
@@ -135,24 +194,36 @@ namespace Octokit.Tests.Clients
public class TheDeleteMethod
{
[Fact]
public void DeletesCorrectUrl()
public async Task DeletesCorrectUrl()
{
var apiConnection = Substitute.For<IApiConnection>();
var deployKeysClient = new RepositoryDeployKeysClient(apiConnection);
deployKeysClient.Delete("user", "repo", 42);
await deployKeysClient.Delete("user", "repo", 42);
apiConnection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "repos/user/repo/keys/42"));
}
[Fact]
public async Task DeletesCorrectUrlWithRepositoryId()
{
var apiConnection = Substitute.For<IApiConnection>();
var deployKeysClient = new RepositoryDeployKeysClient(apiConnection);
await deployKeysClient.Delete(1, 42);
apiConnection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "repositories/1/keys/42"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var deployKeysClient = new RepositoryDeployKeysClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => deployKeysClient.Delete(null, "repo", 1));
await Assert.ThrowsAsync<ArgumentException>(() => deployKeysClient.Delete("", "repo", 1));
await Assert.ThrowsAsync<ArgumentNullException>(() => deployKeysClient.Delete("user", null, 1));
await Assert.ThrowsAsync<ArgumentException>(() => deployKeysClient.Delete("", "repo", 1));
await Assert.ThrowsAsync<ArgumentException>(() => deployKeysClient.Delete("user", "", 1));
}
}

View File

@@ -20,14 +20,25 @@ namespace Octokit.Tests.Reactive
public class TheGetMethod
{
[Fact]
public void CallsIntoClient()
public void RequestsCorrectUrl()
{
var githubClient = Substitute.For<IGitHubClient>();
var deployKeysClient = new ObservableRepositoryDeployKeysClient(githubClient);
var gitHubClient = Substitute.For<IGitHubClient>();
var deployKeysClient = new ObservableRepositoryDeployKeysClient(gitHubClient);
deployKeysClient.Get("user", "repo", 42);
githubClient.Repository.DeployKeys.Received(1).Get("user", "repo", 42);
gitHubClient.Repository.DeployKeys.Received(1).Get("user", "repo", 42);
}
[Fact]
public void RequestsCorrectUrlWithRepositoryId()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var deployKeysClient = new ObservableRepositoryDeployKeysClient(gitHubClient);
deployKeysClient.Get(1, 42);
gitHubClient.Repository.DeployKeys.Received(1).Get(1, 42);
}
[Fact]
@@ -35,29 +46,30 @@ namespace Octokit.Tests.Reactive
{
var deployKeysClient = new ObservableRepositoryDeployKeysClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => deployKeysClient.Get(null, "repo", 42));
Assert.Throws<ArgumentException>(() => deployKeysClient.Get("", "repo", 42));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.Get("user", null, 42));
Assert.Throws<ArgumentException>(() => deployKeysClient.Get("user", "", 42));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.Get(null, "repo", 1));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.Get("user", null, 1));
Assert.Throws<ArgumentException>(() => deployKeysClient.Get("", "repo", 1));
Assert.Throws<ArgumentException>(() => deployKeysClient.Get("user", "", 1));
}
}
public class TheGetAllMethod
{
[Fact]
public void CallsIntoClient()
public void RequestsCorrectUrl()
{
var githubClient = Substitute.For<IGitHubClient>();
var deployKeysClient = new ObservableRepositoryDeployKeysClient(githubClient);
var gitHubClient = Substitute.For<IGitHubClient>();
var deployKeysClient = new ObservableRepositoryDeployKeysClient(gitHubClient);
deployKeysClient.GetAll("user", "repo");
githubClient.Connection.Received(1).Get<List<DeployKey>>(
gitHubClient.Connection.Received(1).Get<List<DeployKey>>(
new Uri("repos/user/repo/keys", UriKind.Relative), Arg.Is<Dictionary<string, string>>(dictionary => dictionary.Count == 0), null);
}
[Fact]
public void GetsCorrectUrlWithApiOptions()
public void RequestsCorrectUrlWithApiOptions()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var deployKeysClient = new ObservableRepositoryDeployKeysClient(gitHubClient);
@@ -102,42 +114,96 @@ namespace Octokit.Tests.Reactive
null);
}
[Fact]
public void RequestsCorrectUrlWithRepositoryIdWithApiOptions()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var deployKeysClient = new ObservableRepositoryDeployKeysClient(gitHubClient);
var expectedUrl = "repositories/1/keys";
// all properties are setted => only 2 options (StartPage, PageSize) in dictionary
var options = new ApiOptions
{
StartPage = 1,
PageCount = 1,
PageSize = 1
};
deployKeysClient.GetAll(1, options);
gitHubClient.Connection.Received(1)
.Get<List<DeployKey>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 2),
null);
// StartPage is setted => only 1 option (StartPage) in dictionary
options = new ApiOptions
{
StartPage = 1
};
deployKeysClient.GetAll(1, options);
gitHubClient.Connection.Received(1)
.Get<List<DeployKey>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 1),
null);
// PageCount is setted => none of options in dictionary
options = new ApiOptions
{
PageCount = 1
};
deployKeysClient.GetAll(1, options);
gitHubClient.Connection.Received(1)
.Get<List<DeployKey>>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
Arg.Is<IDictionary<string, string>>(dictionary => dictionary.Count == 0),
null);
}
[Fact]
public void EnsuresNonNullArguments()
{
var deployKeysClient = new ObservableRepositoryDeployKeysClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll(null, null));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll(null, "repo"));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll("user", null));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll(null, null, null));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll(null, null, ApiOptions.None));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll(null, "repo", null));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll("user", null, null));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll(null, "repo", ApiOptions.None));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll("user", null, ApiOptions.None));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll("user", "repo", null));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll(1, null));
Assert.Throws<ArgumentException>(() => deployKeysClient.GetAll("user", ""));
Assert.Throws<ArgumentException>(() => deployKeysClient.GetAll("", "repo"));
Assert.Throws<ArgumentException>(() => deployKeysClient.GetAll("", "repo", ApiOptions.None));
Assert.Throws<ArgumentException>(() => deployKeysClient.GetAll("user", "", ApiOptions.None));
}
}
public class TheCreateMethod
{
[Fact]
public void CallsIntoClient()
public void CreatesCorrectUrl()
{
var githubClient = Substitute.For<IGitHubClient>();
var deployKeysClient = new ObservableRepositoryDeployKeysClient(githubClient);
var gitHubClient = Substitute.For<IGitHubClient>();
var deployKeysClient = new ObservableRepositoryDeployKeysClient(gitHubClient);
var data = new NewDeployKey { Key = "ABC123", Title = "user@repo" };
deployKeysClient.Create("user", "repo", data);
githubClient.Repository.DeployKeys.Received(1).Create("user", "repo", data);
gitHubClient.Repository.DeployKeys.Received(1).Create("user", "repo", data);
}
[Fact]
public void CreatesCorrectUrlWithRepositoryId()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var deployKeysClient = new ObservableRepositoryDeployKeysClient(gitHubClient);
var data = new NewDeployKey { Key = "ABC123", Title = "user@repo" };
deployKeysClient.Create(1, data);
gitHubClient.Repository.DeployKeys.Received(1).Create(1, data);
}
[Fact]
@@ -146,12 +212,54 @@ namespace Octokit.Tests.Reactive
var deployKeysClient = new ObservableRepositoryDeployKeysClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => deployKeysClient.Create(null, "repo", new NewDeployKey()));
Assert.Throws<ArgumentException>(() => deployKeysClient.Create("", "repo", new NewDeployKey()));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.Create("user", null, new NewDeployKey()));
Assert.Throws<ArgumentException>(() => deployKeysClient.Create("user", "", new NewDeployKey()));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.Create("user", "repo", null));
Assert.Throws<ArgumentException>(() => deployKeysClient.Create("user", "repo", new NewDeployKey { Title = "user@repo" }));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.Create(1, null));
Assert.Throws<ArgumentException>(() => deployKeysClient.Create("", "repo", new NewDeployKey()));
Assert.Throws<ArgumentException>(() => deployKeysClient.Create("user", "", new NewDeployKey()));
Assert.Throws<ArgumentException>(() => deployKeysClient.Create("user", "repo", new NewDeployKey()));
Assert.Throws<ArgumentException>(() => deployKeysClient.Create("user", "repo", new NewDeployKey { Key = "ABC123" }));
Assert.Throws<ArgumentException>(() => deployKeysClient.Create("user", "repo", new NewDeployKey { Title = "user@repo" }));
}
}
public class TheDeleteMethod
{
[Fact]
public void CreatesCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var deployKeysClient = new ObservableRepositoryDeployKeysClient(gitHubClient);
deployKeysClient.Delete("user", "repo", 42);
gitHubClient.Repository.DeployKeys.Received(1).Delete("user", "repo", 42);
}
[Fact]
public void CreatesCorrectUrlWithRepositoryId()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var deployKeysClient = new ObservableRepositoryDeployKeysClient(gitHubClient);
deployKeysClient.Delete(1, 42);
gitHubClient.Repository.DeployKeys.Received(1).Delete(1, 42);
}
[Fact]
public void EnsuresNonNullArguments()
{
var deployKeysClient = new ObservableRepositoryDeployKeysClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => deployKeysClient.Delete(null, "repo", 1));
Assert.Throws<ArgumentNullException>(() => deployKeysClient.Delete("user", null, 1));
Assert.Throws<ArgumentException>(() => deployKeysClient.Delete("", "repo", 1));
Assert.Throws<ArgumentException>(() => deployKeysClient.Delete("user", "", 1));
}
}
}

View File

@@ -24,6 +24,17 @@ namespace Octokit
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
Task<DeployKey> Get(string owner, string name, int number);
/// <summary>
/// Get a single deploy key by number for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#get"> API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The ID of the repository.</param>
/// <param name="number">The id of the deploy key.</param>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
Task<DeployKey> Get(int repositoryId, int number);
/// <summary>
/// Get all deploy keys for a repository.
/// </summary>
@@ -34,6 +45,15 @@ namespace Octokit
/// <param name="name">The name of the repository.</param>
Task<IReadOnlyList<DeployKey>> GetAll(string owner, string name);
/// <summary>
/// Get all deploy keys for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#list"> API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The ID of the repository.</param>
Task<IReadOnlyList<DeployKey>> GetAll(int repositoryId);
/// <summary>
/// Get all deploy keys for a repository.
/// </summary>
@@ -45,6 +65,16 @@ namespace Octokit
/// <param name="options">Options for changing the API response</param>
Task<IReadOnlyList<DeployKey>> GetAll(string owner, string name, ApiOptions options);
/// <summary>
/// Get all deploy keys for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#list"> API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The ID of the repository.</param>
/// <param name="options">Options for changing the API response</param>
Task<IReadOnlyList<DeployKey>> GetAll(int repositoryId, ApiOptions options);
/// <summary>
/// Creates a new deploy key for a repository.
/// </summary>
@@ -54,9 +84,18 @@ namespace Octokit
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the repository.</param>
/// <param name="newDeployKey">The deploy key to create for the repository.</param>
/// <returns></returns>
Task<DeployKey> Create(string owner, string name, NewDeployKey newDeployKey);
/// <summary>
/// Creates a new deploy key for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#create"> API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The ID of the repository.</param>
/// <param name="newDeployKey">The deploy key to create for the repository.</param>
Task<DeployKey> Create(int repositoryId, NewDeployKey newDeployKey);
/// <summary>
/// Deletes a deploy key from a repository.
/// </summary>
@@ -66,7 +105,16 @@ namespace Octokit
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the repository.</param>
/// <param name="number">The id of the deploy key to delete.</param>
/// <returns></returns>
Task Delete(string owner, string name, int number);
/// <summary>
/// Deletes a deploy key from a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#delete"> API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The ID of the repository.</param>
/// <param name="number">The id of the deploy key to delete.</param>
Task Delete(int repositoryId, int number);
}
}
}

View File

@@ -40,6 +40,19 @@ namespace Octokit
return ApiConnection.Get<DeployKey>(ApiUrls.RepositoryDeployKey(owner, name, number));
}
/// <summary>
/// Get a single deploy key by number for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#get"> API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The ID of the repository.</param>
/// <param name="number">The id of the deploy key.</param>
public Task<DeployKey> Get(int repositoryId, int number)
{
return ApiConnection.Get<DeployKey>(ApiUrls.RepositoryDeployKey(repositoryId, number));
}
/// <summary>
/// Get all deploy keys for a repository.
/// </summary>
@@ -56,6 +69,18 @@ namespace Octokit
return GetAll(owner, name, ApiOptions.None);
}
/// <summary>
/// Get all deploy keys for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#list"> API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The ID of the repository.</param>
public Task<IReadOnlyList<DeployKey>> GetAll(int repositoryId)
{
return GetAll(repositoryId, ApiOptions.None);
}
/// <summary>
/// Get all deploy keys for a repository.
/// </summary>
@@ -74,6 +99,21 @@ namespace Octokit
return ApiConnection.GetAll<DeployKey>(ApiUrls.RepositoryDeployKeys(owner, name), options);
}
/// <summary>
/// Get all deploy keys for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#list"> API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The ID of the repository.</param>
/// <param name="options">Options for changing the API response</param>
public Task<IReadOnlyList<DeployKey>> GetAll(int repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return ApiConnection.GetAll<DeployKey>(ApiUrls.RepositoryDeployKeys(repositoryId), options);
}
/// <summary>
/// Creates a new deploy key for a repository.
/// </summary>
@@ -83,7 +123,6 @@ namespace Octokit
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the repository.</param>
/// <param name="newDeployKey">The deploy key to create for the repository.</param>
/// <returns></returns>
public Task<DeployKey> Create(string owner, string name, NewDeployKey newDeployKey)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
@@ -99,6 +138,27 @@ namespace Octokit
return ApiConnection.Post<DeployKey>(ApiUrls.RepositoryDeployKeys(owner, name), newDeployKey);
}
/// <summary>
/// Creates a new deploy key for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#create"> API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The ID of the repository.</param>
/// <param name="newDeployKey">The deploy key to create for the repository.</param>
public Task<DeployKey> Create(int repositoryId, NewDeployKey newDeployKey)
{
Ensure.ArgumentNotNull(newDeployKey, "newDeployKey");
if (string.IsNullOrWhiteSpace(newDeployKey.Title))
throw new ArgumentException("The new deploy key's title must not be null.");
if (string.IsNullOrWhiteSpace(newDeployKey.Key))
throw new ArgumentException("The new deploy key's key must not be null.");
return ApiConnection.Post<DeployKey>(ApiUrls.RepositoryDeployKeys(repositoryId), newDeployKey);
}
/// <summary>
/// Deletes a deploy key from a repository.
/// </summary>
@@ -108,14 +168,25 @@ namespace Octokit
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the repository.</param>
/// <param name="number">The id of the deploy key to delete.</param>
/// <returns></returns>
public Task Delete(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(number, "number");
return ApiConnection.Delete(ApiUrls.RepositoryDeployKey(owner, name, number));
}
/// <summary>
/// Deletes a deploy key from a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#delete"> API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The ID of the repository.</param>
/// <param name="number">The id of the deploy key to delete.</param>
public Task Delete(int repositoryId, int number)
{
return ApiConnection.Delete(ApiUrls.RepositoryDeployKey(repositoryId, number));
}
}
}
}