Skip to content

Instantly share code, notes, and snippets.

@GuyHarwood
Created November 28, 2013 09:36
Show Gist options
  • Save GuyHarwood/7689421 to your computer and use it in GitHub Desktop.
Save GuyHarwood/7689421 to your computer and use it in GitHub Desktop.
Validate all AutoMapper configurations in one test
[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