mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-19 21:55:12 +00:00
Unit tests for observable repo deploy keys client
This commit is contained in:
@@ -26,6 +26,7 @@ namespace Octokit.Reactive
|
|||||||
PullRequest = new ObservablePullRequestsClient(client);
|
PullRequest = new ObservablePullRequestsClient(client);
|
||||||
RepositoryComments = new ObservableRepositoryCommentsClient(client);
|
RepositoryComments = new ObservableRepositoryCommentsClient(client);
|
||||||
Commits = new ObservableRepositoryCommitsClient(client);
|
Commits = new ObservableRepositoryCommitsClient(client);
|
||||||
|
DeployKeys = new ObservableRepositoryDeployKeysClient(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -365,5 +366,13 @@ namespace Octokit.Reactive
|
|||||||
/// See the <a href="http://developer.github.com/v3/pulls/">Pull Requests API documentation</a> for more details
|
/// See the <a href="http://developer.github.com/v3/pulls/">Pull Requests API documentation</a> for more details
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public IObservablePullRequestsClient PullRequest { get; private set; }
|
public IObservablePullRequestsClient PullRequest { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Client for managing deploy keys
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// See the <a href="https://developer.github.com/v3/repos/keys/">Repository Deploy Keys API documentation</a> for more information.
|
||||||
|
/// </remarks>
|
||||||
|
public IObservableRepositoryDeployKeysClient DeployKeys { get; private set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,6 +159,7 @@
|
|||||||
<Compile Include="Reactive\ObservablePullRequestsClientTests.cs" />
|
<Compile Include="Reactive\ObservablePullRequestsClientTests.cs" />
|
||||||
<Compile Include="Reactive\ObservableReleasesClientTests.cs" />
|
<Compile Include="Reactive\ObservableReleasesClientTests.cs" />
|
||||||
<Compile Include="Reactive\ObservableRepositoriesClientTests.cs" />
|
<Compile Include="Reactive\ObservableRepositoriesClientTests.cs" />
|
||||||
|
<Compile Include="Reactive\ObservableRepositoryDeployKeysClientTests.cs" />
|
||||||
<Compile Include="Reactive\ObservableStarredClientTests.cs" />
|
<Compile Include="Reactive\ObservableStarredClientTests.cs" />
|
||||||
<Compile Include="Reactive\ObservableStatisticsClientTests.cs" />
|
<Compile Include="Reactive\ObservableStatisticsClientTests.cs" />
|
||||||
<Compile Include="Reactive\ObservableTreesClientTests.cs" />
|
<Compile Include="Reactive\ObservableTreesClientTests.cs" />
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using NSubstitute;
|
||||||
|
using NSubstitute.Core;
|
||||||
|
using Octokit.Reactive;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Octokit.Tests.Reactive
|
||||||
|
{
|
||||||
|
public class ObservableRepositoryDeployKeysClientTests
|
||||||
|
{
|
||||||
|
public class TheConstructor
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void ThrowsForBadArgs()
|
||||||
|
{
|
||||||
|
Assert.Throws<ArgumentNullException>(() => new ObservableRepositoryDeployKeysClient(null));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TheGetMethod
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void CallsIntoClient()
|
||||||
|
{
|
||||||
|
var githubClient = Substitute.For<IGitHubClient>();
|
||||||
|
var deployKeysClient = new ObservableRepositoryDeployKeysClient(githubClient);
|
||||||
|
|
||||||
|
deployKeysClient.Get("user", "repo", 42);
|
||||||
|
|
||||||
|
githubClient.Repository.DeployKeys.Received(1).Get("user", "repo", 42);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void EnsuresNonNullArguments()
|
||||||
|
{
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TheGetAllMethod
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void CallsIntoClient()
|
||||||
|
{
|
||||||
|
var githubClient = Substitute.For<IGitHubClient>();
|
||||||
|
var deployKeysClient = new ObservableRepositoryDeployKeysClient(githubClient);
|
||||||
|
|
||||||
|
deployKeysClient.GetAll("user", "repo");
|
||||||
|
|
||||||
|
githubClient.Connection.Received(1).Get<List<DeployKey>>(
|
||||||
|
new Uri("repos/user/repo/keys", UriKind.Relative), null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void EnsuresNonNullArguments()
|
||||||
|
{
|
||||||
|
var deployKeysClient = new ObservableRepositoryDeployKeysClient(Substitute.For<IGitHubClient>());
|
||||||
|
|
||||||
|
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll(null, "repo"));
|
||||||
|
Assert.Throws<ArgumentException>(() => deployKeysClient.GetAll("", "repo"));
|
||||||
|
Assert.Throws<ArgumentNullException>(() => deployKeysClient.GetAll("user", null));
|
||||||
|
Assert.Throws<ArgumentException>(() => deployKeysClient.GetAll("user", ""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TheCreateMethod
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void CallsIntoClient()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void EnsuresNonNullArguments()
|
||||||
|
{
|
||||||
|
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<ArgumentException>(() => deployKeysClient.Create("user", "repo", new NewDeployKey { Key = "ABC123" }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user