Created
October 15, 2013 16:34
-
-
Save plioi/6994516 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
public class CustomConvention : Convention | |
{ | |
public CustomConvention() | |
{ | |
Classes | |
.NameEndsWith("Tests"); | |
Methods | |
.Where(method => method.IsVoid()); | |
Parameters(FindInputs); | |
} | |
private static IEnumerable<object[]> FindInputs(MethodInfo method) | |
{ | |
var parameters = method.GetParameters(); | |
if (parameters.Length == 1) | |
{ | |
var testClass = method.ReflectedType; | |
var parameterType = parameters.Single().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