Skip to content

Instantly share code, notes, and snippets.

@plioi
Created September 26, 2013 23:08
Show Gist options
  • Save plioi/6721871 to your computer and use it in GitHub Desktop.
Save plioi/6721871 to your computer and use it in GitHub Desktop.
public class CustomConvention : Convention
{
public CustomConvention()
{
Classes
.NameEndsWith("Tests");
Methods
.Where(method => method.IsVoid());
ClassExecution
.CreateInstancePerTestClass();
//This new hook lets you explain where
//parameters should come from:
Parameters(FromInputAttributes);
}
IEnumerable<object[]> FromInputAttributes(MethodInfo method)
{
var inputAttributes = method.GetCustomAttributes<InputAttribute>(true).ToArray();
if (!inputAttributes.Any())
{
//No [Input] attributes? Just call the
//test method once with no arguments.
yield return new object[] { };
}
else
{
//Call the test once for each [Input] attribute.
foreach (var input in inputAttributes)
yield return input.Parameters;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment