mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-03 03:01:31 +00:00
Implemented ObservableDeploymentsClient and...
unit tests.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
|
||||
namespace Octokit.Reactive.Clients
|
||||
{
|
||||
public interface IObservableDeploymentsClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets all the deployments for the specified repository. Any user with pull access
|
||||
/// to a repository can view deployments.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/repos/deployments/#list-deployments
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <returns>All the <see cref="Deployment"/>s for the specified repository.</returns>
|
||||
IObservable<Deployment> GetAll(string owner, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new deployment for the specified repository.
|
||||
/// Users with push access can create a deployment for a given ref.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/repos/deployments/#create-a-deployment
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="newDeployment">A <see cref="NewDeployment"/> instance describing the new deployment to create</param>
|
||||
/// <returns>The created <see cref="Deployment"></returns>
|
||||
IObservable<Deployment> Create(string owner, string name, NewDeployment newDeployment);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using Octokit.Reactive.Internal;
|
||||
using System;
|
||||
using System.Reactive.Threading.Tasks;
|
||||
|
||||
namespace Octokit.Reactive.Clients
|
||||
{
|
||||
public class ObservableDeploymentsClient : IObservableDeploymentsClient
|
||||
{
|
||||
readonly IDeploymentsClient _client;
|
||||
readonly IConnection _connection;
|
||||
|
||||
public ObservableDeploymentsClient(IGitHubClient client)
|
||||
{
|
||||
Ensure.ArgumentNotNull(client, "client");
|
||||
|
||||
_client = client.Deployment;
|
||||
_connection = client.Connection;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the deployments for the specified repository. Any user with pull access
|
||||
/// to a repository can view deployments.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/repos/deployments/#list-deployments
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <returns>All the <see cref="Deployment"/>s for the specified repository.</returns>
|
||||
public IObservable<Deployment> GetAll(string owner, string name)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
return _connection.GetAndFlattenAllPages<Deployment>(ApiUrls.Deployments(owner, name), null,
|
||||
"application/vnd.github.cannonball-preview+json");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new deployment for the specified repository.
|
||||
/// Users with push access can create a deployment for a given ref.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/repos/deployments/#create-a-deployment
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="newDeployment">A <see cref="NewDeployment"/> instance describing the new deployment to create</param>
|
||||
/// <returns>The created <see cref="Deployment"></returns>
|
||||
public IObservable<Deployment> Create(string owner, string name, NewDeployment newDeployment)
|
||||
{
|
||||
return _client.Create(owner, name, newDeployment).ToObservable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,6 +118,8 @@
|
||||
<Compile Include="Clients\ObservableGistsClient.cs" />
|
||||
<Compile Include="Clients\IObservableSearchClient.cs" />
|
||||
<Compile Include="Clients\ObservableSearchClient.cs" />
|
||||
<Compile Include="Clients\ObservableDeploymentsClient.cs" />
|
||||
<Compile Include="Clients\IObservableDeploymentsClient.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
||||
@@ -127,6 +127,8 @@
|
||||
<Compile Include="Clients\ObservableGistsClient.cs" />
|
||||
<Compile Include="Clients\IObservableSearchClient.cs" />
|
||||
<Compile Include="Clients\ObservableSearchClient.cs" />
|
||||
<Compile Include="Clients\ObservableDeploymentsClient.cs" />
|
||||
<Compile Include="Clients\IObservableDeploymentsClient.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
||||
@@ -122,6 +122,8 @@
|
||||
<Compile Include="Clients\ObservableGistsClient.cs" />
|
||||
<Compile Include="Clients\IObservableSearchClient.cs" />
|
||||
<Compile Include="Clients\ObservableSearchClient.cs" />
|
||||
<Compile Include="Clients\ObservableDeploymentsClient.cs" />
|
||||
<Compile Include="Clients\IObservableDeploymentsClient.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
||||
@@ -73,6 +73,8 @@
|
||||
<Compile Include="..\SolutionInfo.cs">
|
||||
<Link>Properties\SolutionInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Clients\IObservableDeploymentsClient.cs" />
|
||||
<Compile Include="Clients\ObservableDeploymentsClient.cs" />
|
||||
<Compile Include="Clients\ObservableSearchClient.cs" />
|
||||
<Compile Include="Clients\IObservableBlobClient.cs" />
|
||||
<Compile Include="Clients\IObservableGistCommentsClient.cs" />
|
||||
|
||||
@@ -21,5 +21,15 @@ namespace Octokit.Tests.Helpers
|
||||
// Assert.Throws above will always throw.
|
||||
return null;
|
||||
}
|
||||
|
||||
static readonly string[] whitespaceArguments = { " ", "\t", "\n", "\n\r", " " };
|
||||
|
||||
public static async void ThrowsWhenGivenWhitespaceArgument(Func<string, Task> action)
|
||||
{
|
||||
foreach (var argument in whitespaceArguments)
|
||||
{
|
||||
await Throws<ArgumentException>(async () => await action(argument));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,6 +131,7 @@
|
||||
<Compile Include="Reactive\AuthorizationExtensionsTests.cs" />
|
||||
<Compile Include="Reactive\ObservableBlobClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableCommitsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableDeploymentsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableEventsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableIssueCommentsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableIssuesClientTests.cs" />
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
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;
|
||||
using System.Linq;
|
||||
|
||||
namespace Octokit.Tests.Reactive
|
||||
{
|
||||
public class ObservableDeploymentsClientTests
|
||||
{
|
||||
const string ExpectedAcceptHeader = "application/vnd.github.cannonball-preview+json";
|
||||
|
||||
public class TheGetAllMethod
|
||||
{
|
||||
readonly IGitHubClient _githubClient;
|
||||
readonly ObservableDeploymentsClient _client;
|
||||
|
||||
public TheGetAllMethod()
|
||||
{
|
||||
_githubClient = Substitute.For<IGitHubClient>();
|
||||
_client = new ObservableDeploymentsClient(_githubClient);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
AssertEx.Throws<ArgumentNullException>(
|
||||
async () => await _client.GetAll(null, "repo"));
|
||||
AssertEx.Throws<ArgumentNullException>(
|
||||
async () => await _client.GetAll("owner", null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonEmptyArguments()
|
||||
{
|
||||
AssertEx.Throws<ArgumentException>(
|
||||
async () => await _client.GetAll("", "repo"));
|
||||
AssertEx.Throws<ArgumentException>(
|
||||
async () => await _client.GetAll("owner", ""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonWhitespaceArguments()
|
||||
{
|
||||
AssertEx.ThrowsWhenGivenWhitespaceArgument(
|
||||
async whitespace => await _client.GetAll(whitespace, "repo"));
|
||||
AssertEx.ThrowsWhenGivenWhitespaceArgument(
|
||||
async whitespace => await _client.GetAll("owner", whitespace));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CallsDeploymentsUrl()
|
||||
{
|
||||
var expectedUri = ApiUrls.Deployments("owner", "repo");
|
||||
|
||||
_client.GetAll("owner", "repo");
|
||||
_githubClient.Connection
|
||||
.Received(1)
|
||||
.GetAsync<List<Deployment>>(Arg.Is(expectedUri),
|
||||
Arg.Any<IDictionary<string, string>>(),
|
||||
Arg.Any<string>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsesPreviewAcceptHeader()
|
||||
{
|
||||
_client.GetAll("owner", "repo");
|
||||
_githubClient.Connection
|
||||
.Received(1)
|
||||
.GetAsync<List<Deployment>>(Arg.Any<Uri>(),
|
||||
Arg.Any<IDictionary<string, string>>(),
|
||||
ExpectedAcceptHeader);
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateMethod
|
||||
{
|
||||
IGitHubClient _githubClient;
|
||||
ObservableDeploymentsClient _client;
|
||||
|
||||
public TheCreateMethod()
|
||||
{
|
||||
_githubClient = Substitute.For<IGitHubClient>();
|
||||
_client = new ObservableDeploymentsClient(_githubClient);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonNullArguments()
|
||||
{
|
||||
AssertEx.Throws<ArgumentNullException>(
|
||||
async () => await _client.Create(null, "repo", new NewDeployment()));
|
||||
AssertEx.Throws<ArgumentNullException>(
|
||||
async () => await _client.Create("owner", null, new NewDeployment()));
|
||||
AssertEx.Throws<ArgumentNullException>(
|
||||
async () => await _client.Create("owner", "repo", null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonEmptyArguments()
|
||||
{
|
||||
AssertEx.Throws<ArgumentNullException>(
|
||||
async () => await _client.Create("", "repo", new NewDeployment()));
|
||||
AssertEx.Throws<ArgumentNullException>(
|
||||
async () => await _client.Create("owner", "", new NewDeployment()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresNonWhitespaceArguments()
|
||||
{
|
||||
AssertEx.ThrowsWhenGivenWhitespaceArgument(
|
||||
async whitespace => await _client.Create(whitespace, "repo", new NewDeployment()));
|
||||
AssertEx.ThrowsWhenGivenWhitespaceArgument(
|
||||
async whitespace => await _client.Create("owner", whitespace, new NewDeployment()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CallsCreateOnRegularDeploymentsClient()
|
||||
{
|
||||
var newDeployment = new NewDeployment();
|
||||
_client.Create("owner", "repo", newDeployment);
|
||||
_githubClient.Deployment.Received(1).Create(Arg.Is("owner"),
|
||||
Arg.Is("repo"),
|
||||
Arg.Is(newDeployment));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCtor
|
||||
{
|
||||
public void EnsuresArguments()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(
|
||||
() => new ObservableDeploymentsClient(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user