Created
September 26, 2013 23:08
-
-
Save plioi/6721871 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()); | |
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