Skip to content

Instantly share code, notes, and snippets.

@alieniasty
Last active January 31, 2018 13:50
Show Gist options
  • Save alieniasty/dfd73788ea16e630fa4abab348fd3047 to your computer and use it in GitHub Desktop.
Save alieniasty/dfd73788ea16e630fa4abab348fd3047 to your computer and use it in GitHub Desktop.
[Fact]
public void AllControllers_ShouldDerivedFromBaseController()
{
var itemsToVerify = new Types(Types.InAssemblyOf<BaseController>().Where(c => c.IsSubclassOf(typeof(Controller)) && !c.IsAbstract).ToList(), "ControllersTests");
TestStack.ConventionTests.Convention.Is(new MvcControllerNameAndCustomBaseClassConvention(), itemsToVerify);
}
public class MvcControllerNameAndCustomBaseClassConvention : IConvention<Types>
{
public void Execute(Types data, IConventionResultContext result)
{
var controllers = data.TypesToVerify.Where(t => t.IsAbstract || !t.Name.EndsWith("Controller") || !t.IsSubclassOf(typeof(BaseController)));
result.Is("Types must be derived from BaseController class and it's name should ends with Controller", controllers);
}
public string ConventionReason => "Check if all controllers have propper base class and name";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment