Implemented ObservableDeploymentStatusClient and...

unit tests.
This commit is contained in:
Peter MacNaughton
2014-01-21 10:29:36 -07:00
parent a22006950a
commit c5d12dcc7e
8 changed files with 247 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
using System;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive.Clients
{
public interface IObservableDeploymentStatusClient
{
/// <summary>
/// Gets all the statuses for the given deployment. Any user with pull access to a repository can
/// view deployments.
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/repos/deployments/#list-deployment-statuses
/// </remarks>
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the repository.</param>
/// <param name="deploymentId">The id of the deployment.</param>
/// <returns>All deployment statuses for the given deployment.</returns>
IObservable<DeploymentStatus> GetAll(string owner, string name, int deploymentId);
/// <summary>
/// Creates a new status for the given deployment. Users with push access can create deployment
/// statuses for a given deployment.
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/repos/deployments/#create-a-deployment-status
/// </remarks>
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the repository.</param>
/// <param name="deploymentId">The id of the deployment.</param>
/// <param name="newDeploymentStatus">The new deployment status to create.</param>
/// <returns></returns>
IObservable<DeploymentStatus> Create(string owner, string name, int deploymentId, NewDeploymentStatus newDeploymentStatus);
}
}

View File

@@ -0,0 +1,59 @@
using Octokit.Reactive.Internal;
using System;
using System.Reactive.Threading.Tasks;
namespace Octokit.Reactive.Clients
{
public class ObservableDeploymentStatusClient : IObservableDeploymentStatusClient
{
const string acceptsHeader = "application/vnd.github.cannonball-preview+json";
private IDeploymentStatusClient _client;
private IConnection _connection;
public ObservableDeploymentStatusClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_client = client.Deployment.Status;
_connection = client.Connection;
}
/// <summary>
/// Gets all the statuses for the given deployment. Any user with pull access to a repository can
/// view deployments.
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/repos/deployments/#list-deployment-statuses
/// </remarks>
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the repository.</param>
/// <param name="deploymentId">The id of the deployment.</param>
/// <returns>All deployment statuses for the given deployment.</returns>
public IObservable<DeploymentStatus> GetAll(string owner, string name, int deploymentId)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _connection.GetAndFlattenAllPages<DeploymentStatus>(
ApiUrls.DeploymentStatuses(owner, name, deploymentId),
null, acceptsHeader);
}
/// <summary>
/// Creates a new status for the given deployment. Users with push access can create deployment
/// statuses for a given deployment.
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/repos/deployments/#create-a-deployment-status
/// </remarks>
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the repository.</param>
/// <param name="deploymentId">The id of the deployment.</param>
/// <param name="newDeploymentStatus">The new deployment status to create.</param>
/// <returns></returns>
public IObservable<DeploymentStatus> Create(string owner, string name, int deploymentId, NewDeploymentStatus newDeploymentStatus)
{
return _client.Create(owner, name, deploymentId, newDeploymentStatus).ToObservable();
}
}
}

View File

@@ -120,6 +120,8 @@
<Compile Include="Clients\ObservableSearchClient.cs" />
<Compile Include="Clients\ObservableDeploymentsClient.cs" />
<Compile Include="Clients\IObservableDeploymentsClient.cs" />
<Compile Include="Clients\IObservableDeploymentStatusClient.cs" />
<Compile Include="Clients\ObservableDeploymentStatusClient.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>

View File

@@ -129,6 +129,8 @@
<Compile Include="Clients\ObservableSearchClient.cs" />
<Compile Include="Clients\ObservableDeploymentsClient.cs" />
<Compile Include="Clients\IObservableDeploymentsClient.cs" />
<Compile Include="Clients\IObservableDeploymentStatusClient.cs" />
<Compile Include="Clients\ObservableDeploymentStatusClient.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
<ItemGroup>

View File

@@ -124,6 +124,8 @@
<Compile Include="Clients\ObservableSearchClient.cs" />
<Compile Include="Clients\ObservableDeploymentsClient.cs" />
<Compile Include="Clients\IObservableDeploymentsClient.cs" />
<Compile Include="Clients\IObservableDeploymentStatusClient.cs" />
<Compile Include="Clients\ObservableDeploymentStatusClient.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>

View File

@@ -74,7 +74,9 @@
<Link>Properties\SolutionInfo.cs</Link>
</Compile>
<Compile Include="Clients\IObservableDeploymentsClient.cs" />
<Compile Include="Clients\IObservableDeploymentStatusClient.cs" />
<Compile Include="Clients\ObservableDeploymentsClient.cs" />
<Compile Include="Clients\ObservableDeploymentStatusClient.cs" />
<Compile Include="Clients\ObservableSearchClient.cs" />
<Compile Include="Clients\IObservableBlobClient.cs" />
<Compile Include="Clients\IObservableGistCommentsClient.cs" />

View File

@@ -132,6 +132,7 @@
<Compile Include="Reactive\ObservableBlobClientTests.cs" />
<Compile Include="Reactive\ObservableCommitsClientTests.cs" />
<Compile Include="Reactive\ObservableDeploymentsClientTests.cs" />
<Compile Include="Reactive\ObservableDeploymentStatusClientTests.cs" />
<Compile Include="Reactive\ObservableEventsClientTests.cs" />
<Compile Include="Reactive\ObservableIssueCommentsClientTests.cs" />
<Compile Include="Reactive\ObservableIssuesClientTests.cs" />

View File

@@ -0,0 +1,143 @@
using NSubstitute;
using Octokit.Reactive.Clients;
using Octokit.Tests.Helpers;
using System;
using System.Collections.Generic;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Xunit;
namespace Octokit.Tests.Reactive
{
public class ObservableDeploymentStatusClientTests
{
const string ExpectedAcceptHeader = "application/vnd.github.cannonball-preview+json";
public class TheGetAllMethod
{
readonly IGitHubClient _githubClient;
readonly ObservableDeploymentStatusClient _client;
public TheGetAllMethod()
{
_githubClient = new GitHubClient(Substitute.For<IConnection>());
_client = new ObservableDeploymentStatusClient(_githubClient);
}
[Fact]
public void EnsuresNonNullArguments()
{
AssertEx.Throws<ArgumentNullException>(
async () => await _client.GetAll(null, "repo", 1));
AssertEx.Throws<ArgumentNullException>(
async () => await _client.GetAll("owner", null, 1));
}
[Fact]
public void EnsuresNonEmptyArguments()
{
AssertEx.Throws<ArgumentException>(
async () => await _client.GetAll("", "repo", 1));
AssertEx.Throws<ArgumentException>(
async () => await _client.GetAll("owner", "", 1));
}
[Fact]
public void EnsureNonWhitespaceArguments()
{
AssertEx.ThrowsWhenGivenWhitespaceArgument(
async whitespace => await _client.GetAll(whitespace, "repo", 1));
AssertEx.ThrowsWhenGivenWhitespaceArgument(
async whitespace => await _client.GetAll("owner", whitespace, 1));
}
[Fact]
public void GetsFromCorrectUrl()
{
var expectedUri = ApiUrls.DeploymentStatuses("owner", "repo", 1);
_client.GetAll("owner", "repo", 1);
_githubClient.Connection
.Received(1)
.GetAsync<List<DeploymentStatus>>(Arg.Is(expectedUri),
Arg.Any<IDictionary<string, string>>(),
Arg.Any<string>());
}
[Fact]
public void UsesPreviewAcceptHeader()
{
_client.GetAll("owner", "repo", 1);
_githubClient.Connection
.Received(1)
.GetAsync<List<DeploymentStatus>>(Arg.Any<Uri>(),
Arg.Any<IDictionary<string, string>>(),
Arg.Is(ExpectedAcceptHeader));
}
}
public class TheCreateMethod
{
readonly IGitHubClient _githubClient = Substitute.For<IGitHubClient>();
readonly ObservableDeploymentStatusClient _client;
public TheCreateMethod()
{
_client = new ObservableDeploymentStatusClient(_githubClient);
}
[Fact]
public void EnsuresNonNullArguments()
{
AssertEx.Throws<ArgumentNullException>(
async () => await _client.GetAll(null, "repo", 1));
AssertEx.Throws<ArgumentNullException>(
async () => await _client.GetAll("owner", null, 1));
}
[Fact]
public void EnsuresNonEmptyArguments()
{
AssertEx.Throws<ArgumentException>(
async () => await _client.GetAll("", "repo", 1));
AssertEx.Throws<ArgumentException>(
async () => await _client.GetAll("owner", "", 1));
}
[Fact]
public void EnsureNonWhitespaceArguments()
{
AssertEx.ThrowsWhenGivenWhitespaceArgument(
async ws => await _client.GetAll(ws, "repo", 1));
AssertEx.ThrowsWhenGivenWhitespaceArgument(
async ws => await _client.GetAll("owner", ws, 1));
}
[Fact]
public void CallsIntoDeploymentStatusClient()
{
var newStatus = new NewDeploymentStatus();
_client.Create("owner", "repo", 1, newStatus);
_githubClient.Deployment
.Status
.Received(1)
.Create(Arg.Is("owner"),
Arg.Is("repo"),
Arg.Is(1),
Arg.Is(newStatus));
}
}
public class TheCtor
{
[Fact]
public void EnsuresArgument()
{
Assert.Throws<ArgumentNullException>(
() => new ObservableDeploymentStatusClient(null));
}
}
}
}