Skip to content

Instantly share code, notes, and snippets.

@GuyHarwood
Last active December 16, 2015 13:29
Show Gist options
  • Save GuyHarwood/5442369 to your computer and use it in GitHub Desktop.
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
[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