mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-01 10:25:36 +00:00
Implemented DeploymentStatusesClient and unit tests
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
using NSubstitute;
|
||||
using Octokit;
|
||||
using Octokit.Tests.Helpers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
using Xunit.Extensions;
|
||||
|
||||
public class DeploymentStatusClientTests
|
||||
{
|
||||
const string expectedAcceptsHeader = "application/vnd.github.cannonball-preview+json";
|
||||
|
||||
public class TheGetAllMethod
|
||||
{
|
||||
[Fact]
|
||||
public async void EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new DeploymentStatusClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetAll(null, "name", 1));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetAll("owner", null, 1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void EnsuresNonEmptyArguments()
|
||||
{
|
||||
var client = new DeploymentStatusClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetAll("", "name", 1));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetAll("owner", "", 1));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(" ")]
|
||||
[InlineData("\n")]
|
||||
[InlineData("\t")]
|
||||
[InlineData(" ")]
|
||||
[InlineData("\n\r")]
|
||||
public async void EnsureNonWhitespaceArguments(string whitespace)
|
||||
{
|
||||
var client = new DeploymentStatusClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetAll(whitespace, "name", 1));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetAll("owner", whitespace, 1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new DeploymentStatusClient(connection);
|
||||
var expectedUrl = "repos/owner/name/deployments/1/statuses";
|
||||
|
||||
client.GetAll("owner", "name", 1);
|
||||
connection.Received().GetAll<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Any<IDictionary<string, string>>(),
|
||||
Arg.Any<string>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsesPreviewAcceptHeader()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new DeploymentStatusClient(connection);
|
||||
|
||||
client.GetAll("owner", "name", 1);
|
||||
connection.Received().GetAll<DeploymentStatus>(Arg.Any<Uri>(),
|
||||
Arg.Any<IDictionary<string, string>>(),
|
||||
expectedAcceptsHeader);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateMethod
|
||||
{
|
||||
readonly NewDeploymentStatus newDeploymentStatus = new NewDeploymentStatus();
|
||||
|
||||
[Fact]
|
||||
public async void EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new DeploymentStatusClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () =>
|
||||
await client.Create(null, "name", 1, newDeploymentStatus));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () =>
|
||||
await client.Create("owner", null, 1, newDeploymentStatus));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void EnsuresNonEmptyArguments()
|
||||
{
|
||||
var client = new DeploymentStatusClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetAll("", "name", 1));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetAll("owner", "", 1));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(" ")]
|
||||
[InlineData("\n")]
|
||||
[InlineData("\t")]
|
||||
[InlineData(" ")]
|
||||
[InlineData("\n\r")]
|
||||
public async void EnsureNonWhitespaceArguments(string whitespace)
|
||||
{
|
||||
var client = new DeploymentStatusClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await AssertEx.Throws<ArgumentException>(async () =>
|
||||
await client.Create(whitespace, "repo", 1, newDeploymentStatus));
|
||||
await AssertEx.Throws<ArgumentException>(async () =>
|
||||
await client.Create("owner", whitespace, 1, newDeploymentStatus));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PostsToCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new DeploymentStatusClient(connection);
|
||||
var expectedUrl = "repos/owner/repo/deployments/1/statuses";
|
||||
|
||||
client.Create("owner", "repo", 1, newDeploymentStatus);
|
||||
|
||||
connection.Received().Post<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Any<NewDeploymentStatus>(),
|
||||
Arg.Any<string>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsesPreviewAcceptHeader()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new DeploymentStatusClient(connection);
|
||||
|
||||
client.Create("owner", "repo", 1, newDeploymentStatus);
|
||||
|
||||
connection.Received().Post<DeploymentStatus>(Arg.Any<Uri>(),
|
||||
Arg.Any<NewDeploymentStatus>(),
|
||||
expectedAcceptsHeader);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCtor
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresArgument()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new DeploymentStatusClient(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Authentication\CredentialsTests.cs" />
|
||||
<Compile Include="Clients\DeploymentsClientTests.cs" />
|
||||
<Compile Include="Clients\DeploymentStatusClientTests.cs" />
|
||||
<Compile Include="Clients\SearchClientTests.cs" />
|
||||
<Compile Include="Clients\GistCommentsClientTests.cs" />
|
||||
<Compile Include="Clients\GistsClientTests.cs" />
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
public class DeploymentStatusClient : ApiClient, IDeploymentStatusClient
|
||||
{
|
||||
const string acceptsHeader = "application/vnd.github.cannonball-preview+json";
|
||||
|
||||
public DeploymentStatusClient(IApiConnection apiConnection)
|
||||
: base(apiConnection)
|
||||
{
|
||||
}
|
||||
|
||||
public Task<IReadOnlyList<DeploymentStatus>> GetAll(string owner, string name, int deploymentId)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
return ApiConnection.GetAll<DeploymentStatus>(ApiUrls.DeploymentStatuses(owner, name, deploymentId),
|
||||
null, acceptsHeader);
|
||||
}
|
||||
|
||||
public Task<DeploymentStatus> Create(string owner, string name, int deploymentId, NewDeploymentStatus newDeploymentStatus)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNull(newDeploymentStatus, "newDeploymentStatus");
|
||||
|
||||
return ApiConnection.Post<DeploymentStatus>(ApiUrls.DeploymentStatuses(owner, name, deploymentId),
|
||||
newDeploymentStatus, acceptsHeader);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ namespace Octokit
|
||||
public DeploymentsClient(IApiConnection apiConnection)
|
||||
: base(apiConnection)
|
||||
{
|
||||
Status = new DeploymentStatusClient(apiConnection);
|
||||
}
|
||||
|
||||
public Task<IReadOnlyList<GitDeployment>> GetAll(string owner, string name)
|
||||
@@ -30,5 +31,7 @@ namespace Octokit
|
||||
return ApiConnection.Post<GitDeployment>(ApiUrls.Deployments(owner, name),
|
||||
newDeployment, acceptsHeader);
|
||||
}
|
||||
|
||||
public IDeploymentStatusClient Status { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
public interface IDeploymentStatusClient
|
||||
{
|
||||
Task<IReadOnlyList<DeploymentStatus>> GetAll(string owner, string name, int deploymentId);
|
||||
|
||||
Task<DeploymentStatus> Create(string owner, string name, int deploymentId, NewDeploymentStatus newDeploymentStatus);
|
||||
}
|
||||
}
|
||||
@@ -7,5 +7,6 @@ namespace Octokit
|
||||
{
|
||||
Task<IReadOnlyList<GitDeployment>> GetAll(string owner, string name);
|
||||
Task<GitDeployment> Create(string owner, string name, NewDeployment newDeployment);
|
||||
IDeploymentStatusClient Status { get; }
|
||||
}
|
||||
}
|
||||
@@ -786,5 +786,10 @@ namespace Octokit
|
||||
{
|
||||
return "repos/{0}/{1}/deployments".FormatUri(owner, name);
|
||||
}
|
||||
|
||||
public static Uri DeploymentStatuses(string owner, string name, int deploymentId)
|
||||
{
|
||||
return "repos/{0}/{1}/deployments/{2}/statuses".FormatUri(owner, name, deploymentId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Octokit
|
||||
{
|
||||
public class NewDeploymentStatus
|
||||
{
|
||||
public DeploymentState State { get; set; }
|
||||
|
||||
public string TargetUrl { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
public class DeploymentStatus
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Url { get; set; }
|
||||
|
||||
public DeploymentState State { get; set; }
|
||||
|
||||
public User Creator { get; set; }
|
||||
|
||||
public string Payload { get; set; }
|
||||
|
||||
public string TargetUrl { get; set; }
|
||||
|
||||
public DateTime CreatedAt { get; set; }
|
||||
|
||||
public DateTime UpdatedAt { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
}
|
||||
|
||||
public enum DeploymentState
|
||||
{
|
||||
Pending,
|
||||
Success,
|
||||
Error,
|
||||
Failure
|
||||
}
|
||||
}
|
||||
@@ -246,10 +246,14 @@
|
||||
<Compile Include="Clients\IGistCommentsClient.cs" />
|
||||
<Compile Include="Models\Response\GistComment.cs" />
|
||||
<Compile Include="Models\Request\BodyWrapper.cs" />
|
||||
<Compile Include="Clients\DeploymentStatusClient.cs" />
|
||||
<Compile Include="Clients\DeploymentsClient.cs" />
|
||||
<Compile Include="Clients\IDeploymentsClient.cs" />
|
||||
<Compile Include="Models\Request\NewDeployment.cs" />
|
||||
<Compile Include="Models\Response\GitDeployment.cs" />
|
||||
<Compile Include="Clients\IDeploymentStatusClient.cs" />
|
||||
<Compile Include="Models\Request\NewDeploymentStatus.cs" />
|
||||
<Compile Include="Models\Response\DeploymentStatus.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -256,10 +256,14 @@
|
||||
<Compile Include="Models\Request\LabelUpdate.cs" />
|
||||
<Compile Include="Models\Request\NewLabel.cs" />
|
||||
<Compile Include="Models\Response\Branch.cs" />
|
||||
<Compile Include="Clients\DeploymentStatusClient.cs" />
|
||||
<Compile Include="Clients\DeploymentsClient.cs" />
|
||||
<Compile Include="Clients\IDeploymentsClient.cs" />
|
||||
<Compile Include="Models\Request\NewDeployment.cs" />
|
||||
<Compile Include="Models\Response\GitDeployment.cs" />
|
||||
<Compile Include="Clients\IDeploymentStatusClient.cs" />
|
||||
<Compile Include="Models\Request\NewDeploymentStatus.cs" />
|
||||
<Compile Include="Models\Response\DeploymentStatus.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -251,10 +251,14 @@
|
||||
<Compile Include="Models\Request\LabelUpdate.cs" />
|
||||
<Compile Include="Models\Request\NewLabel.cs" />
|
||||
<Compile Include="Models\Response\Branch.cs" />
|
||||
<Compile Include="Clients\DeploymentStatusClient.cs" />
|
||||
<Compile Include="Clients\DeploymentsClient.cs" />
|
||||
<Compile Include="Clients\IDeploymentsClient.cs" />
|
||||
<Compile Include="Models\Request\NewDeployment.cs" />
|
||||
<Compile Include="Models\Response\GitDeployment.cs" />
|
||||
<Compile Include="Clients\IDeploymentStatusClient.cs" />
|
||||
<Compile Include="Models\Request\NewDeploymentStatus.cs" />
|
||||
<Compile Include="Models\Response\DeploymentStatus.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -244,10 +244,14 @@
|
||||
<Compile Include="Clients\IGistCommentsClient.cs" />
|
||||
<Compile Include="Models\Response\GistComment.cs" />
|
||||
<Compile Include="Models\Request\BodyWrapper.cs" />
|
||||
<Compile Include="Clients\DeploymentStatusClient.cs" />
|
||||
<Compile Include="Clients\DeploymentsClient.cs" />
|
||||
<Compile Include="Clients\IDeploymentsClient.cs" />
|
||||
<Compile Include="Models\Request\NewDeployment.cs" />
|
||||
<Compile Include="Models\Response\GitDeployment.cs" />
|
||||
<Compile Include="Clients\IDeploymentStatusClient.cs" />
|
||||
<Compile Include="Models\Request\NewDeploymentStatus.cs" />
|
||||
<Compile Include="Models\Response\DeploymentStatus.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
|
||||
|
||||
@@ -54,6 +54,10 @@
|
||||
<Link>Properties\SolutionInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Clients\ActivitiesClient.cs" />
|
||||
<Compile Include="Models\Response\DeploymentStatus.cs" />
|
||||
<Compile Include="Clients\DeploymentStatusClient.cs" />
|
||||
<Compile Include="Clients\IDeploymentStatusClient.cs" />
|
||||
<Compile Include="Models\Request\NewDeploymentStatus.cs" />
|
||||
<Compile Include="Models\Request\NewDeployment.cs" />
|
||||
<Compile Include="Models\Response\GitDeployment.cs" />
|
||||
<Compile Include="Clients\DeploymentsClient.cs" />
|
||||
|
||||
Reference in New Issue
Block a user