Fixing argument tests for ObservableDeployments...

Client and ObservableDeploymentStatusClient. Needed to make sure that
the tasks were actually run and not just scheduled.
This commit is contained in:
Peter MacNaughton
2014-02-02 18:24:25 -07:00
parent ed462e7cd6
commit 2e9263009d
3 changed files with 77 additions and 42 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ namespace Octokit.Tests.Helpers
static readonly string[] whitespaceArguments = { " ", "\t", "\n", "\n\r", " " };
public static async void ThrowsWhenGivenWhitespaceArgument(Func<string, Task> action)
public static async Task ThrowsWhenGivenWhitespaceArgument(Func<string, Task> action)
{
foreach (var argument in whitespaceArguments)
{
@@ -7,6 +7,7 @@ using System.Reactive.Linq;
using System.Threading.Tasks;
using Xunit;
namespace Octokit.Tests.Reactive
{
public class ObservableDeploymentStatusClientTests
@@ -43,11 +44,11 @@ namespace Octokit.Tests.Reactive
}
[Fact]
public void EnsureNonWhitespaceArguments()
public async Task EnsureNonWhitespaceArguments()
{
AssertEx.ThrowsWhenGivenWhitespaceArgument(
await AssertEx.ThrowsWhenGivenWhitespaceArgument(
async whitespace => await _client.GetAll(whitespace, "repo", 1));
AssertEx.ThrowsWhenGivenWhitespaceArgument(
await AssertEx.ThrowsWhenGivenWhitespaceArgument(
async whitespace => await _client.GetAll("owner", whitespace, 1));
}
@@ -80,44 +81,58 @@ namespace Octokit.Tests.Reactive
public class TheCreateMethod
{
readonly IGitHubClient _githubClient = Substitute.For<IGitHubClient>();
readonly ObservableDeploymentStatusClient _client;
IGitHubClient _githubClient = Substitute.For<IGitHubClient>();
ObservableDeploymentStatusClient _client;
public TheCreateMethod()
public void SetupWithoutNonReactiveClient()
{
_client = new ObservableDeploymentStatusClient(_githubClient);
}
[Fact]
public void EnsuresNonNullArguments()
public void SetupWithNonReactiveClient()
{
AssertEx.Throws<ArgumentNullException>(
async () => await _client.GetAll(null, "repo", 1));
AssertEx.Throws<ArgumentNullException>(
async () => await _client.GetAll("owner", null, 1));
var deploymentStatusClient = new DeploymentStatusClient(Substitute.For<IApiConnection>());
_githubClient.Deployment.Status.Returns(deploymentStatusClient);
_client = new ObservableDeploymentStatusClient(_githubClient);
}
[Fact]
public void EnsuresNonEmptyArguments()
public async Task EnsuresNonNullArguments()
{
AssertEx.Throws<ArgumentException>(
async () => await _client.GetAll("", "repo", 1));
AssertEx.Throws<ArgumentException>(
async () => await _client.GetAll("owner", "", 1));
SetupWithNonReactiveClient();
await AssertEx.Throws<ArgumentNullException>(
async () => await _client.Create(null, "repo", 1, new NewDeploymentStatus()));
await AssertEx.Throws<ArgumentNullException>(
async () => await _client.Create("owner", null, 1, new NewDeploymentStatus()));
await AssertEx.Throws<ArgumentNullException>(
async () => await _client.Create("owner", "repo", 1, null));
}
[Fact]
public void EnsureNonWhitespaceArguments()
public async Task EnsuresNonEmptyArguments()
{
AssertEx.ThrowsWhenGivenWhitespaceArgument(
async ws => await _client.GetAll(ws, "repo", 1));
AssertEx.ThrowsWhenGivenWhitespaceArgument(
async ws => await _client.GetAll("owner", ws, 1));
SetupWithNonReactiveClient();
await AssertEx.Throws<ArgumentException>(
async () => await _client.Create("", "repo", 1, new NewDeploymentStatus()));
await AssertEx.Throws<ArgumentException>(
async () => await _client.Create("owner", "", 1, new NewDeploymentStatus()));
}
[Fact]
public async Task EnsureNonWhitespaceArguments()
{
SetupWithNonReactiveClient();
await AssertEx.ThrowsWhenGivenWhitespaceArgument(
async whitespace => await _client.Create(whitespace, "repo", 1, new NewDeploymentStatus()));
await AssertEx.ThrowsWhenGivenWhitespaceArgument(
async whitespace => await _client.Create("owner", whitespace, 1, new NewDeploymentStatus()));
}
[Fact]
public void CallsIntoDeploymentStatusClient()
{
SetupWithoutNonReactiveClient();
var newStatus = new NewDeploymentStatus();
_client.Create("owner", "repo", 1, newStatus);
_githubClient.Deployment
@@ -26,29 +26,29 @@ namespace Octokit.Tests.Reactive
}
[Fact]
public void EnsuresNonNullArguments()
public async Task EnsuresNonNullArguments()
{
AssertEx.Throws<ArgumentNullException>(
await AssertEx.Throws<ArgumentNullException>(
async () => await _client.GetAll(null, "repo"));
AssertEx.Throws<ArgumentNullException>(
await AssertEx.Throws<ArgumentNullException>(
async () => await _client.GetAll("owner", null));
}
[Fact]
public void EnsuresNonEmptyArguments()
public async Task EnsuresNonEmptyArguments()
{
AssertEx.Throws<ArgumentException>(
await AssertEx.Throws<ArgumentException>(
async () => await _client.GetAll("", "repo"));
AssertEx.Throws<ArgumentException>(
await AssertEx.Throws<ArgumentException>(
async () => await _client.GetAll("owner", ""));
}
[Fact]
public void EnsuresNonWhitespaceArguments()
public async Task EnsuresNonWhitespaceArguments()
{
AssertEx.ThrowsWhenGivenWhitespaceArgument(
await AssertEx.ThrowsWhenGivenWhitespaceArgument(
async whitespace => await _client.GetAll(whitespace, "repo"));
AssertEx.ThrowsWhenGivenWhitespaceArgument(
await AssertEx.ThrowsWhenGivenWhitespaceArgument(
async whitespace => await _client.GetAll("owner", whitespace));
}
@@ -85,41 +85,60 @@ namespace Octokit.Tests.Reactive
public TheCreateMethod()
{
_githubClient = Substitute.For<IGitHubClient>();
}
private void SetupWithoutNonReactiveClient()
{
_client = new ObservableDeploymentsClient(_githubClient);
}
private void SetupWithNonReactiveClient()
{
var deploymentsClient = new DeploymentsClient(Substitute.For<IApiConnection>());
_githubClient.Deployment.Returns(deploymentsClient);
_client = new ObservableDeploymentsClient(_githubClient);
}
[Fact]
public void EnsuresNonNullArguments()
public async Task EnsuresNonNullArguments()
{
AssertEx.Throws<ArgumentNullException>(
SetupWithNonReactiveClient();
await AssertEx.Throws<ArgumentNullException>(
async () => await _client.Create(null, "repo", new NewDeployment()));
AssertEx.Throws<ArgumentNullException>(
await AssertEx.Throws<ArgumentNullException>(
async () => await _client.Create("owner", null, new NewDeployment()));
AssertEx.Throws<ArgumentNullException>(
await AssertEx.Throws<ArgumentNullException>(
async () => await _client.Create("owner", "repo", null));
}
[Fact]
public void EnsuresNonEmptyArguments()
public async Task EnsuresNonEmptyArguments()
{
AssertEx.Throws<ArgumentNullException>(
SetupWithNonReactiveClient();
await AssertEx.Throws<ArgumentException>(
async () => await _client.Create("", "repo", new NewDeployment()));
AssertEx.Throws<ArgumentNullException>(
await AssertEx.Throws<ArgumentException>(
async () => await _client.Create("owner", "", new NewDeployment()));
}
[Fact]
public void EnsuresNonWhitespaceArguments()
public async Task EnsuresNonWhitespaceArguments()
{
AssertEx.ThrowsWhenGivenWhitespaceArgument(
SetupWithNonReactiveClient();
await AssertEx.ThrowsWhenGivenWhitespaceArgument(
async whitespace => await _client.Create(whitespace, "repo", new NewDeployment()));
AssertEx.ThrowsWhenGivenWhitespaceArgument(
await AssertEx.ThrowsWhenGivenWhitespaceArgument(
async whitespace => await _client.Create("owner", whitespace, new NewDeployment()));
}
[Fact]
public void CallsCreateOnRegularDeploymentsClient()
{
SetupWithoutNonReactiveClient();
var newDeployment = new NewDeployment();
_client.Create("owner", "repo", newDeployment);
_githubClient.Deployment.Received(1).Create(Arg.Is("owner"),
@@ -130,6 +149,7 @@ namespace Octokit.Tests.Reactive
public class TheCtor
{
[Fact]
public void EnsuresArguments()
{
Assert.Throws<ArgumentNullException>(