Last active
January 31, 2018 13:50
-
-
Save alieniasty/dfd73788ea16e630fa4abab348fd3047 to your computer and use it in GitHub Desktop.
Cool convention tests. They use https://github.com/TestStack/TestStack.ConventionTests
This file contains 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
[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