Created
July 11, 2013 03:30
-
-
Save plioi/5972318 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
using System.Linq; | |
using System.Reflection; | |
using Fixie; | |
using Fixie.Conventions; | |
namespace CategoriesDemo.Tests | |
{ | |
public class CustomConvention : Convention | |
{ | |
public CustomConvention(RunContext runContext) | |
{ | |
var desiredCategories = runContext.Options["include"].ToArray(); | |
var shouldRunAll = !desiredCategories.Any(); | |
Classes | |
.NameEndsWith("Tests"); | |
Cases | |
.Where(method => method.Void()) | |
.ZeroParameters() | |
.Where(method => shouldRunAll || MethodHasAnyDesiredCategory(method, desiredCategories)); | |
} | |
static bool MethodHasAnyDesiredCategory(MethodInfo method, string[] desiredCategories) | |
{ | |
return Categories(method).Any(testCategory => desiredCategories.Contains(testCategory.Name)); | |
} | |
static CategoryAttribute[] Categories(MethodInfo method) | |
{ | |
return method.GetCustomAttributes<CategoryAttribute>(true).ToArray(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment