Files
octokit.net/Octokit.Tests/Helpers/AssertEx.cs
Haacked 7fdbbf0ae3 Merge branch 'master' into haacked/api-response-refactor
Conflicts:
	Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs
	Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs
	Octokit.Tests/Reactive/ObservablePullRequestsClientTests.cs
	Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs
	Octokit/Octokit-Mono.csproj
	Octokit/Octokit-MonoAndroid.csproj
	Octokit/Octokit-Monotouch.csproj
	Octokit/Octokit-Portable.csproj
	Octokit/Octokit-netcore45.csproj
2015-01-18 12:35:17 -08:00

60 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using Xunit;
namespace Octokit.Tests.Helpers
{
public static class AssertEx
{
public static void WithMessage(Action assert, string message)
{
// TODO: we should just :fire: this to the ground
assert();
}
public static TAttribute HasAttribute<TAttribute>(MemberInfo memberInfo, bool inherit = false) where TAttribute : Attribute
{
var attribute = memberInfo.GetCustomAttribute<TAttribute>(inherit);
Assert.NotNull(attribute);
return attribute;
}
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));
}
}
public static void IsReadOnlyCollection<T>(object instance)
{
var collection = instance as ICollection<T>;
// The collection == null case is for .NET 4.0
Assert.True(instance is IReadOnlyList<T> && (collection == null || collection.IsReadOnly));
}
}
}