Created
November 28, 2013 09:36
-
-
Save GuyHarwood/7689421 to your computer and use it in GitHub Desktop.
Validate all AutoMapper configurations in one test
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
[Test] | |
[Description("Seeks out all implementations of IMappingConfiguration and tests the configuration for missing member mappings")] | |
public void ValidateAllMappingConfigurations() | |
{ | |
var webAssembly = typeof (HomeController).Assembly; | |
var allMappingConfigurations = from typ in webAssembly.GetTypes() | |
let interfaces = typ.GetInterfaces() | |
where interfaces.Contains(typeof (IMappingConfiguration)) | |
select typ; | |
allMappingConfigurations.ForEach((configuration) => | |
{ | |
var instance = Activator.CreateInstance(configuration); | |
var mappingConfiguration = (instance as IMappingConfiguration); | |
if (mappingConfiguration == null) | |
{ | |
Assert.Fail("{0} could not be instantiated", configuration.FullName); | |
} | |
mappingConfiguration.Configure(); | |
mappingConfiguration.AssertConfigurationIsValid(); | |
}); | |
} | |
public interface IMappingConfiguration | |
{ | |
void Configure(); | |
void AssertConfigurationIsValid(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment