Created
October 9, 2013 00:44
-
-
Save plioi/6894324 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Reflection; | |
using Fixie; | |
using Fixie.Conventions; | |
public class CustomConvention : Convention | |
{ | |
public CustomConvention() | |
{ | |
Classes | |
.NameEndsWith("Tests"); | |
Methods | |
.Where(method => method.IsVoid()); | |
Parameters(method => | |
{ | |
//Attempt to find a perfect matching source for N calls. | |
var parameters = method.GetParameters(); | |
if (parameters.Length == 1) | |
return FindInputs(method.ReflectedType, parameters.Single().ParameterType); | |
//No matching source method, so call it once with with zero parameters. | |
return new[] { new object[] {} }; | |
}); | |
} | |
private static IEnumerable<object[]> FindInputs(Type testClass, Type parameterType) | |
{ | |
var enumerableOfParameterType = typeof (IEnumerable<>).MakeGenericType(parameterType); | |
var sources = testClass.GetMethods(BindingFlags.Static | BindingFlags.Public) | |
.Where(m => !m.GetParameters().Any()) | |
.Where(m => m.ReturnType == enumerableOfParameterType) | |
.ToArray(); | |
foreach (var source in sources) | |
foreach (var input in (IEnumerable) source.Invoke(null, null)) | |
yield return new[] {input}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment