Files
octokit.net/Octokit.Tests/Helpers/AssertEx.cs
Peter MacNaughton 2e9263009d Fixing argument tests for ObservableDeployments...
Client and ObservableDeploymentStatusClient. Needed to make sure that
the tasks were actually run and not just scheduled.
2014-02-02 18:25:49 -07:00

36 lines
1.0 KiB
C#

using System;
using System.Threading.Tasks;
using Xunit;
namespace Octokit.Tests.Helpers
{
public static class AssertEx
{
public async static Task<T> Throws<T>(Func<Task> testCode) where T : Exception
{
try
{
await testCode();
Assert.Throws<T>(() => { }); // Use xUnit's default behavior.
}
catch (T exception)
{
return exception;
}
// We should never reach this line. It's here because the compiler doesn't know that
// Assert.Throws above will always throw.
return null;
}
static readonly string[] whitespaceArguments = { " ", "\t", "\n", "\n\r", " " };
public static async Task ThrowsWhenGivenWhitespaceArgument(Func<string, Task> action)
{
foreach (var argument in whitespaceArguments)
{
await Throws<ArgumentException>(async () => await action(argument));
}
}
}
}