Skip to content

Instantly share code, notes, and snippets.

@plioi
Created October 15, 2013 16:34
Show Gist options
  • Save plioi/6994516 to your computer and use it in GitHub Desktop.
Save plioi/6994516 to your computer and use it in GitHub Desktop.
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