Last active
December 16, 2015 13:29
-
-
Save GuyHarwood/5442369 to your computer and use it in GitHub Desktop.
Scan all API controllers to ensure that they all inherit from the specified base controller
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
[Test] | |
public void AllApiControllersInProjectInheritFromBaseApiController() | |
{ | |
var apiBaseType = typeof(BaseApiController); | |
var controllerTypes = (from type in apiBaseType.Assembly.GetTypes() | |
where type.Name.EndsWith("Controller") && type.IsSubclassOf(typeof(ApiController)) | |
&& !type.IsSubclassOf(typeof (BaseApiController)) | |
&& type != typeof(BaseApiController) | |
select type.Name).ToArray(); | |
if (controllerTypes.Any()) | |
{ | |
Assert.Fail("The following controllers do not inherit from the base controller:{0}", string.Join(",",controllerTypes)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment