Skip to content

Instantly share code, notes, and snippets.

@plioi
Created October 9, 2013 00:44
Show Gist options
  • Save plioi/6894324 to your computer and use it in GitHub Desktop.
Save plioi/6894324 to your computer and use it in GitHub Desktop.
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