mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-04 19:26:51 +00:00
Merge pull request #1368 from dampir/add-repo-id-deployment-status
Add repositoryId overloads to methods on I(Observable)DeploymentStatusClient
This commit is contained in:
@@ -2,6 +2,13 @@ using System;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
/// <summary>
|
||||
/// A client for GitHub's Repository Deployment Statuses API.
|
||||
/// Gets and creates Deployment Statuses.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/repos/deployments/">Repository Deployment Statuses API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
public interface IObservableDeploymentStatusClient
|
||||
{
|
||||
/// <summary>
|
||||
@@ -14,9 +21,19 @@ namespace Octokit.Reactive
|
||||
/// <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>
|
||||
/// 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="repositoryId">The ID of the repository.</param>
|
||||
/// <param name="deploymentId">The id of the deployment.</param>
|
||||
IObservable<DeploymentStatus> GetAll(int repositoryId, int deploymentId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the statuses for the given deployment. Any user with pull access to a repository can
|
||||
/// view deployments.
|
||||
@@ -28,9 +45,20 @@ namespace Octokit.Reactive
|
||||
/// <param name="name">The name of the repository.</param>
|
||||
/// <param name="deploymentId">The id of the deployment.</param>
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
/// <returns>All deployment statuses for the given deployment.</returns>
|
||||
IObservable<DeploymentStatus> GetAll(string owner, string name, int deploymentId, ApiOptions options);
|
||||
|
||||
/// <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="repositoryId">The ID of the repository.</param>
|
||||
/// <param name="deploymentId">The id of the deployment.</param>
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
IObservable<DeploymentStatus> GetAll(int repositoryId, int deploymentId, ApiOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new status for the given deployment. Users with push access can create deployment
|
||||
/// statuses for a given deployment.
|
||||
@@ -42,7 +70,18 @@ namespace Octokit.Reactive
|
||||
/// <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);
|
||||
|
||||
/// <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="repositoryId">The ID of the repository.</param>
|
||||
/// <param name="deploymentId">The id of the deployment.</param>
|
||||
/// <param name="newDeploymentStatus">The new deployment status to create.</param>
|
||||
IObservable<DeploymentStatus> Create(int repositoryId, int deploymentId, NewDeploymentStatus newDeploymentStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,13 @@ using Octokit.Reactive.Internal;
|
||||
|
||||
namespace Octokit.Reactive.Clients
|
||||
{
|
||||
/// <summary>
|
||||
/// A client for GitHub's Repository Deployment Statuses API.
|
||||
/// Gets and creates Deployment Statuses.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/repos/deployments/">Repository Deployment Statuses API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
public class ObservableDeploymentStatusClient : IObservableDeploymentStatusClient
|
||||
{
|
||||
private readonly IDeploymentStatusClient _client;
|
||||
@@ -27,7 +34,6 @@ namespace Octokit.Reactive.Clients
|
||||
/// <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");
|
||||
@@ -36,6 +42,20 @@ namespace Octokit.Reactive.Clients
|
||||
return GetAll(owner, name, deploymentId, ApiOptions.None);
|
||||
}
|
||||
|
||||
/// <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="repositoryId">The ID of the repository.</param>
|
||||
/// <param name="deploymentId">The id of the deployment.</param>
|
||||
public IObservable<DeploymentStatus> GetAll(int repositoryId, int deploymentId)
|
||||
{
|
||||
return GetAll(repositoryId, deploymentId, ApiOptions.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the statuses for the given deployment. Any user with pull access to a repository can
|
||||
/// view deployments.
|
||||
@@ -47,7 +67,6 @@ namespace Octokit.Reactive.Clients
|
||||
/// <param name="name">The name of the repository.</param>
|
||||
/// <param name="deploymentId">The id of the deployment.</param>
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
/// <returns>All deployment statuses for the given deployment.</returns>
|
||||
public IObservable<DeploymentStatus> GetAll(string owner, string name, int deploymentId, ApiOptions options)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
@@ -58,6 +77,24 @@ namespace Octokit.Reactive.Clients
|
||||
ApiUrls.DeploymentStatuses(owner, name, deploymentId), options);
|
||||
}
|
||||
|
||||
/// <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="repositoryId">The ID of the repository.</param>
|
||||
/// <param name="deploymentId">The id of the deployment.</param>
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
public IObservable<DeploymentStatus> GetAll(int repositoryId, int deploymentId, ApiOptions options)
|
||||
{
|
||||
Ensure.ArgumentNotNull(options, "options");
|
||||
|
||||
return _connection.GetAndFlattenAllPages<DeploymentStatus>(
|
||||
ApiUrls.DeploymentStatuses(repositoryId, deploymentId), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new status for the given deployment. Users with push access can create deployment
|
||||
/// statuses for a given deployment.
|
||||
@@ -69,10 +106,30 @@ namespace Octokit.Reactive.Clients
|
||||
/// <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)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNull(newDeploymentStatus, "newDeploymentStatus");
|
||||
|
||||
return _client.Create(owner, name, deploymentId, newDeploymentStatus).ToObservable();
|
||||
}
|
||||
|
||||
/// <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="repositoryId">The ID of the repository.</param>
|
||||
/// <param name="deploymentId">The id of the deployment.</param>
|
||||
/// <param name="newDeploymentStatus">The new deployment status to create.</param>
|
||||
public IObservable<DeploymentStatus> Create(int repositoryId, int deploymentId, NewDeploymentStatus newDeploymentStatus)
|
||||
{
|
||||
Ensure.ArgumentNotNull(newDeploymentStatus, "newDeploymentStatus");
|
||||
|
||||
return _client.Create(repositoryId, deploymentId, newDeploymentStatus).ToObservable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,17 @@ public class DeploymentStatusClientTests : IDisposable
|
||||
Assert.Equal(DeploymentState.Success, status.State);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task CanCreateDeploymentStatusWithRepositoryId()
|
||||
{
|
||||
var newStatus = new NewDeploymentStatus(DeploymentState.Success);
|
||||
|
||||
var status = await _deploymentsClient.Status.Create(_context.Repository.Id, _deployment.Id, newStatus);
|
||||
|
||||
Assert.NotNull(status);
|
||||
Assert.Equal(DeploymentState.Success, status.State);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task CanReadDeploymentStatuses()
|
||||
{
|
||||
@@ -69,6 +80,18 @@ public class DeploymentStatusClientTests : IDisposable
|
||||
Assert.Equal(newStatus.EnvironmentUrl, statuses[0].EnvironmentUrl);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task CanReadDeploymentStatusesWithRepositoryId()
|
||||
{
|
||||
var newStatus = new NewDeploymentStatus(DeploymentState.Success);
|
||||
await _deploymentsClient.Status.Create(_context.Repository.Id, _deployment.Id, newStatus);
|
||||
|
||||
var statuses = await _deploymentsClient.Status.GetAll(_context.Repository.Id, _deployment.Id);
|
||||
|
||||
Assert.NotEmpty(statuses);
|
||||
Assert.Equal(DeploymentState.Success, statuses[0].State);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsCorrectCountOfDeploymentStatusesWithoutStart()
|
||||
{
|
||||
@@ -90,6 +113,27 @@ public class DeploymentStatusClientTests : IDisposable
|
||||
Assert.Equal(3, deploymentStatuses.Count);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsCorrectCountOfDeploymentStatusesWithoutStartWithRepositoryId()
|
||||
{
|
||||
var newStatus1 = new NewDeploymentStatus(DeploymentState.Success);
|
||||
var newStatus2 = new NewDeploymentStatus(DeploymentState.Success);
|
||||
var newStatus3 = new NewDeploymentStatus(DeploymentState.Success);
|
||||
await _deploymentsClient.Status.Create(_context.Repository.Id, _deployment.Id, newStatus1);
|
||||
await _deploymentsClient.Status.Create(_context.Repository.Id, _deployment.Id, newStatus2);
|
||||
await _deploymentsClient.Status.Create(_context.Repository.Id, _deployment.Id, newStatus3);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageSize = 3,
|
||||
PageCount = 1
|
||||
};
|
||||
|
||||
var deploymentStatuses = await _deploymentsClient.Status.GetAll(_context.Repository.Id, _deployment.Id, options);
|
||||
|
||||
Assert.Equal(3, deploymentStatuses.Count);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsCorrectCountOfDeploymentStatusesWithStart()
|
||||
{
|
||||
@@ -112,6 +156,28 @@ public class DeploymentStatusClientTests : IDisposable
|
||||
Assert.Equal(1, deploymentStatuses.Count);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsCorrectCountOfDeploymentStatusesWithStartWithRepositoryId()
|
||||
{
|
||||
var newStatus1 = new NewDeploymentStatus(DeploymentState.Success);
|
||||
var newStatus2 = new NewDeploymentStatus(DeploymentState.Success);
|
||||
var newStatus3 = new NewDeploymentStatus(DeploymentState.Success);
|
||||
await _deploymentsClient.Status.Create(_context.Repository.Id,_deployment.Id, newStatus1);
|
||||
await _deploymentsClient.Status.Create(_context.Repository.Id, _deployment.Id, newStatus2);
|
||||
await _deploymentsClient.Status.Create(_context.Repository.Id, _deployment.Id, newStatus3);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
PageSize = 2,
|
||||
PageCount = 1,
|
||||
StartPage = 2
|
||||
};
|
||||
|
||||
var deploymentStatuses = await _deploymentsClient.Status.GetAll(_context.Repository.Id, _deployment.Id, options);
|
||||
|
||||
Assert.Equal(1, deploymentStatuses.Count);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsDistinctDeploymentStatusesBasedOnStartPage()
|
||||
{
|
||||
@@ -142,6 +208,36 @@ public class DeploymentStatusClientTests : IDisposable
|
||||
Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
|
||||
}
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task ReturnsDistinctDeploymentStatusesBasedOnStartPageWithRepositoryId()
|
||||
{
|
||||
var newStatus1 = new NewDeploymentStatus(DeploymentState.Success);
|
||||
var newStatus2 = new NewDeploymentStatus(DeploymentState.Success);
|
||||
var newStatus3 = new NewDeploymentStatus(DeploymentState.Success);
|
||||
await _deploymentsClient.Status.Create(_context.Repository.Id, _deployment.Id, newStatus1);
|
||||
await _deploymentsClient.Status.Create(_context.Repository.Id, _deployment.Id, newStatus2);
|
||||
await _deploymentsClient.Status.Create(_context.Repository.Id, _deployment.Id, newStatus3);
|
||||
|
||||
var startOptions = new ApiOptions
|
||||
{
|
||||
PageSize = 1,
|
||||
PageCount = 1
|
||||
};
|
||||
|
||||
var firstPage = await _deploymentsClient.Status.GetAll(_context.Repository.Id, _deployment.Id, startOptions);
|
||||
|
||||
var skipStartOptions = new ApiOptions
|
||||
{
|
||||
PageSize = 1,
|
||||
PageCount = 1,
|
||||
StartPage = 2
|
||||
};
|
||||
|
||||
var secondPage = await _deploymentsClient.Status.GetAll(_context.Repository.Id, _deployment.Id, skipStartOptions);
|
||||
|
||||
Assert.NotEqual(firstPage[0].Id, secondPage[0].Id);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_context.Dispose();
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using Octokit;
|
||||
@@ -10,6 +9,76 @@ public class DeploymentStatusClientTests
|
||||
{
|
||||
public class TheGetAllMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new DeploymentStatusClient(connection);
|
||||
var expectedUrl = "repos/owner/name/deployments/1/statuses";
|
||||
|
||||
await client.GetAll("owner", "name", 1);
|
||||
|
||||
connection.Received().GetAll<
|
||||
DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
null,
|
||||
"application/vnd.github.ant-man-preview+json",
|
||||
Args.ApiOptions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new DeploymentStatusClient(connection);
|
||||
var expectedUrl = "repositories/1/deployments/1/statuses";
|
||||
|
||||
await client.GetAll(1, 1);
|
||||
|
||||
connection.Received().GetAll<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl), Args.ApiOptions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithApiOptions()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new DeploymentStatusClient(connection);
|
||||
var expectedUrl = "repos/owner/name/deployments/1/statuses";
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
StartPage = 1,
|
||||
PageCount = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
await client.GetAll("owner", "name", 1, options);
|
||||
|
||||
connection.Received().GetAll<DeploymentStatus>(
|
||||
Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
null,
|
||||
"application/vnd.github.ant-man-preview+json",
|
||||
options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new DeploymentStatusClient(connection);
|
||||
var expectedUrl = "repositories/1/deployments/1/statuses";
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
StartPage = 1,
|
||||
PageCount = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
await client.GetAll(1, 1, options);
|
||||
|
||||
connection.Received().GetAll<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl), options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
@@ -21,16 +90,11 @@ public class DeploymentStatusClientTests
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, "name", 1, ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", null, 1, ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", "name", 1, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonEmptyArguments()
|
||||
{
|
||||
var client = new DeploymentStatusClient(Substitute.For<IApiConnection>());
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(1, 1, null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name", 1));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "", 1));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name", 1, ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "", 1, ApiOptions.None));
|
||||
}
|
||||
@@ -51,61 +115,39 @@ public class DeploymentStatusClientTests
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll(whitespace, "name", 1, ApiOptions.None));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", whitespace, 1, ApiOptions.None));
|
||||
}
|
||||
|
||||
[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>(),
|
||||
Args.ApiOptions);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithApiOptions()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new DeploymentStatusClient(connection);
|
||||
var expectedUrl = "repos/owner/name/deployments/1/statuses";
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
StartPage = 1,
|
||||
PageCount = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
client.GetAll("owner", "name", 1, options);
|
||||
connection.Received().GetAll<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Any<IDictionary<string, string>>(),
|
||||
Arg.Any<string>(),
|
||||
options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithPreviewAcceptHeaders()
|
||||
{
|
||||
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.Is<string>(a => a == AcceptHeaders.DeploymentApiPreview),
|
||||
Args.ApiOptions);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateMethod
|
||||
{
|
||||
readonly NewDeploymentStatus newDeploymentStatus = new NewDeploymentStatus(DeploymentState.Success);
|
||||
|
||||
[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),
|
||||
newDeploymentStatus,
|
||||
"application/vnd.github.ant-man-preview+json");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PostsToCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new DeploymentStatusClient(connection);
|
||||
var expectedUrl = "repositories/1/deployments/1/statuses";
|
||||
|
||||
client.Create(1, 1, newDeploymentStatus);
|
||||
|
||||
connection.Received().Post<DeploymentStatus>(Arg.Is<Uri>(u => u.ToString() == expectedUrl),
|
||||
Arg.Any<NewDeploymentStatus>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
@@ -113,15 +155,12 @@ public class DeploymentStatusClientTests
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(null, "name", 1, newDeploymentStatus));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", null, 1, newDeploymentStatus));
|
||||
}
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", "name", 1, null));
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonEmptyArguments()
|
||||
{
|
||||
var client = new DeploymentStatusClient(Substitute.For<IApiConnection>());
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(1, 1, null));
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name", 1));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "", 1));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("", "name", 1, newDeploymentStatus));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("owner", "", 1, newDeploymentStatus));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -138,20 +177,6 @@ public class DeploymentStatusClientTests
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => 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 PassesNewDeploymentRequest()
|
||||
{
|
||||
@@ -189,4 +214,4 @@ public class DeploymentStatusClientTests
|
||||
Assert.Throws<ArgumentNullException>(() => new DeploymentStatusClient(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,23 +22,85 @@ namespace Octokit.Tests.Reactive
|
||||
_client = new ObservableDeploymentStatusClient(_githubClient);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var expectedUri = string.Format("repos/{0}/{1}/deployments/{2}/statuses", "owner", "repo", 1);
|
||||
|
||||
_client.GetAll("owner", "repo", 1);
|
||||
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<DeploymentStatus>>(Arg.Is<Uri>(uri => uri.ToString() == expectedUri),
|
||||
Args.EmptyDictionary,
|
||||
null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRepositoryId()
|
||||
{
|
||||
var expectedUri = string.Format("repositories/{0}/deployments/{1}/statuses", 1, 1);
|
||||
|
||||
_client.GetAll(1, 1);
|
||||
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<DeploymentStatus>>(Arg.Is<Uri>(uri => uri.ToString() == expectedUri),
|
||||
Args.EmptyDictionary,
|
||||
null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithApiOptions()
|
||||
{
|
||||
var expectedUri = string.Format("repos/{0}/{1}/deployments/{2}/statuses", "owner", "repo", 1);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
StartPage = 1,
|
||||
PageCount = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
_client.GetAll("owner", "repo", 1, options);
|
||||
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<DeploymentStatus>>(Arg.Is<Uri>(uri => uri.ToString() == expectedUri),
|
||||
Arg.Is<Dictionary<string, string>>(dictionary => dictionary.Count == 2),
|
||||
null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWithRepositoryIdWithApiOptions()
|
||||
{
|
||||
var expectedUri = string.Format("repositories/{0}/deployments/{1}/statuses", 1, 1);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
StartPage = 1,
|
||||
PageCount = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
_client.GetAll(1, 1, options);
|
||||
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<DeploymentStatus>>(Arg.Is<Uri>(uri => uri.ToString() == expectedUri),
|
||||
Arg.Is<Dictionary<string, string>>(dictionary => dictionary.Count == 2),
|
||||
null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => _client.GetAll(null, "repo", 1));
|
||||
Assert.Throws<ArgumentNullException>(() => _client.GetAll("owner", null, 1));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => _client.GetAll(null, "repo", 1, ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => _client.GetAll("owner", null, 1, ApiOptions.None));
|
||||
Assert.Throws<ArgumentNullException>(() => _client.GetAll("owner", "repo", 1, null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonEmptyArguments()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => _client.GetAll(1, 1, null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => _client.GetAll("", "repo", 1));
|
||||
Assert.Throws<ArgumentException>(() => _client.GetAll("owner", "", 1));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => _client.GetAll("", "repo", 1, ApiOptions.None));
|
||||
Assert.Throws<ArgumentException>(() => _client.GetAll("owner", "", 1, ApiOptions.None));
|
||||
}
|
||||
@@ -56,39 +118,6 @@ namespace Octokit.Tests.Reactive
|
||||
await AssertEx.ThrowsWhenGivenWhitespaceArgument(
|
||||
async whitespace => await _client.GetAll("owner", whitespace, 1, ApiOptions.None));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var expectedUri = ApiUrls.DeploymentStatuses("owner", "repo", 1);
|
||||
|
||||
_client.GetAll("owner", "repo", 1);
|
||||
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<DeploymentStatus>>(Arg.Is(expectedUri),
|
||||
Args.EmptyDictionary,
|
||||
null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectUrlWitApiOptions()
|
||||
{
|
||||
var expectedUri = ApiUrls.DeploymentStatuses("owner", "repo", 1);
|
||||
|
||||
var options = new ApiOptions
|
||||
{
|
||||
StartPage = 1,
|
||||
PageCount = 1,
|
||||
PageSize = 1
|
||||
};
|
||||
|
||||
_client.GetAll("owner", "repo", 1, options);
|
||||
|
||||
_githubClient.Connection.Received(1)
|
||||
.Get<List<DeploymentStatus>>(Arg.Is(expectedUri),
|
||||
Arg.Is<Dictionary<string, string>>(dictionary => dictionary.Count == 2),
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateMethod
|
||||
@@ -109,18 +138,42 @@ namespace Octokit.Tests.Reactive
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
public void CallsIntoDeploymentStatusClient()
|
||||
{
|
||||
SetupWithNonReactiveClient();
|
||||
Assert.Throws<ArgumentNullException>(() => _client.Create(null, "repo", 1, new NewDeploymentStatus(DeploymentState.Success)));
|
||||
Assert.Throws<ArgumentNullException>(() => _client.Create("owner", null, 1, new NewDeploymentStatus(DeploymentState.Success)));
|
||||
Assert.Throws<ArgumentNullException>(() => _client.Create("owner", "repo", 1, null));
|
||||
SetupWithoutNonReactiveClient();
|
||||
|
||||
var newStatus = new NewDeploymentStatus(DeploymentState.Success);
|
||||
|
||||
_client.Create("owner", "repo", 1, newStatus);
|
||||
|
||||
_githubClient.Repository.Deployment.Status.Received(1)
|
||||
.Create("owner", "repo", 1, newStatus);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonEmptyArguments()
|
||||
public void CallsIntoDeploymentStatusClientWithRepositoryId()
|
||||
{
|
||||
SetupWithoutNonReactiveClient();
|
||||
|
||||
var newStatus = new NewDeploymentStatus(DeploymentState.Success);
|
||||
|
||||
_client.Create(1, 1, newStatus);
|
||||
|
||||
_githubClient.Repository.Deployment.Status.Received(1)
|
||||
.Create(1, 1, newStatus);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
SetupWithNonReactiveClient();
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => _client.Create(null, "repo", 1, new NewDeploymentStatus(DeploymentState.Success)));
|
||||
Assert.Throws<ArgumentNullException>(() => _client.Create("owner", null, 1, new NewDeploymentStatus(DeploymentState.Success)));
|
||||
Assert.Throws<ArgumentNullException>(() => _client.Create("owner", "repo", 1, null));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => _client.Create(1, 1, null));
|
||||
|
||||
Assert.Throws<ArgumentException>(() => _client.Create("", "repo", 1, new NewDeploymentStatus(DeploymentState.Success)));
|
||||
Assert.Throws<ArgumentException>(() => _client.Create("owner", "", 1, new NewDeploymentStatus(DeploymentState.Success)));
|
||||
}
|
||||
@@ -129,25 +182,12 @@ namespace Octokit.Tests.Reactive
|
||||
public async Task EnsureNonWhitespaceArguments()
|
||||
{
|
||||
SetupWithNonReactiveClient();
|
||||
|
||||
await AssertEx.ThrowsWhenGivenWhitespaceArgument(
|
||||
async whitespace => await _client.Create(whitespace, "repo", 1, new NewDeploymentStatus(DeploymentState.Success)));
|
||||
await AssertEx.ThrowsWhenGivenWhitespaceArgument(
|
||||
async whitespace => await _client.Create("owner", whitespace, 1, new NewDeploymentStatus(DeploymentState.Success)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CallsIntoDeploymentStatusClient()
|
||||
{
|
||||
SetupWithoutNonReactiveClient();
|
||||
|
||||
var newStatus = new NewDeploymentStatus(DeploymentState.Success);
|
||||
_client.Create("owner", "repo", 1, newStatus);
|
||||
_githubClient.Repository.Deployment.Status.Received(1)
|
||||
.Create(Arg.Is("owner"),
|
||||
Arg.Is("repo"),
|
||||
Arg.Is(1),
|
||||
Arg.Is(newStatus));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCtor
|
||||
|
||||
@@ -27,7 +27,6 @@ namespace Octokit
|
||||
/// <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 Task<IReadOnlyList<DeploymentStatus>> GetAll(string owner, string name, int deploymentId)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
@@ -36,6 +35,20 @@ namespace Octokit
|
||||
return GetAll(owner, name, deploymentId, ApiOptions.None);
|
||||
}
|
||||
|
||||
/// <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="repositoryId">The ID of the repository.</param>
|
||||
/// <param name="deploymentId">The id of the deployment.</param>
|
||||
public Task<IReadOnlyList<DeploymentStatus>> GetAll(int repositoryId, int deploymentId)
|
||||
{
|
||||
return GetAll(repositoryId, deploymentId, ApiOptions.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the statuses for the given deployment. Any user with pull access to a repository can
|
||||
/// view deployments.
|
||||
@@ -47,7 +60,6 @@ namespace Octokit
|
||||
/// <param name="name">The name of the repository.</param>
|
||||
/// <param name="deploymentId">The id of the deployment.</param>
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
/// <returns>All deployment statuses for the given deployment.</returns>
|
||||
public Task<IReadOnlyList<DeploymentStatus>> GetAll(string owner, string name, int deploymentId, ApiOptions options)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
@@ -60,6 +72,23 @@ namespace Octokit
|
||||
options);
|
||||
}
|
||||
|
||||
/// <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="repositoryId">The ID of the repository.</param>
|
||||
/// <param name="deploymentId">The id of the deployment.</param>
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
public Task<IReadOnlyList<DeploymentStatus>> GetAll(int repositoryId, int deploymentId, ApiOptions options)
|
||||
{
|
||||
Ensure.ArgumentNotNull(options, "options");
|
||||
|
||||
return ApiConnection.GetAll<DeploymentStatus>(ApiUrls.DeploymentStatuses(repositoryId, deploymentId), options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new status for the given deployment. Users with push access can create deployment
|
||||
/// statuses for a given deployment.
|
||||
@@ -70,8 +99,7 @@ namespace Octokit
|
||||
/// <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"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="newDeploymentStatus">The new deployment status to create.</param>
|
||||
public Task<DeploymentStatus> Create(string owner, string name, int deploymentId, NewDeploymentStatus newDeploymentStatus)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
@@ -82,5 +110,23 @@ namespace Octokit
|
||||
newDeploymentStatus,
|
||||
AcceptHeaders.DeploymentApiPreview);
|
||||
}
|
||||
|
||||
/// <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="repositoryId">The ID of the repository.</param>
|
||||
/// <param name="deploymentId">The id of the deployment.</param>
|
||||
/// <param name="newDeploymentStatus">The new deployment status to create.</param>
|
||||
public Task<DeploymentStatus> Create(int repositoryId, int deploymentId, NewDeploymentStatus newDeploymentStatus)
|
||||
{
|
||||
Ensure.ArgumentNotNull(newDeploymentStatus, "newDeploymentStatus");
|
||||
|
||||
return ApiConnection.Post<DeploymentStatus>(ApiUrls.DeploymentStatuses(repositoryId, deploymentId),
|
||||
newDeploymentStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,19 @@ namespace Octokit
|
||||
/// <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>
|
||||
Task<IReadOnlyList<DeploymentStatus>> GetAll(string owner, string name, int deploymentId);
|
||||
|
||||
/// <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="repositoryId">The ID of the repository.</param>
|
||||
/// <param name="deploymentId">The id of the deployment.</param>
|
||||
Task<IReadOnlyList<DeploymentStatus>> GetAll(int repositoryId, int deploymentId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the statuses for the given deployment. Any user with pull access to a repository can
|
||||
/// view deployments.
|
||||
@@ -36,9 +46,20 @@ namespace Octokit
|
||||
/// <param name="name">The name of the repository.</param>
|
||||
/// <param name="deploymentId">The id of the deployment.</param>
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
/// <returns>All deployment statuses for the given deployment.</returns>
|
||||
Task<IReadOnlyList<DeploymentStatus>> GetAll(string owner, string name, int deploymentId, ApiOptions options);
|
||||
|
||||
/// <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="repositoryId">The ID of the repository.</param>
|
||||
/// <param name="deploymentId">The id of the deployment.</param>
|
||||
/// <param name="options">Options for changing the API response</param>
|
||||
Task<IReadOnlyList<DeploymentStatus>> GetAll(int repositoryId, int deploymentId, ApiOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new status for the given deployment. Users with push access can create deployment
|
||||
/// statuses for a given deployment.
|
||||
@@ -49,8 +70,19 @@ namespace Octokit
|
||||
/// <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"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="newDeploymentStatus">The new deployment status to create.</param>
|
||||
Task<DeploymentStatus> Create(string owner, string name, int deploymentId, NewDeploymentStatus newDeploymentStatus);
|
||||
|
||||
/// <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="repositoryId">The ID of the repository.</param>
|
||||
/// <param name="deploymentId">The id of the deployment.</param>
|
||||
/// <param name="newDeploymentStatus">The new deployment status to create.</param>
|
||||
Task<DeploymentStatus> Create(int repositoryId, int deploymentId, NewDeploymentStatus newDeploymentStatus);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user