Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Revision to an XUnit test for identifying bad mappings. Unlike the standard test (which would fail after the first bad/missing mapping), this will print out all the unmapped property names in the solution in context with the mapping they belong to.
[Fact]
public void AssertConfigurationIsValid()
{
try
{
Mapper.AssertConfigurationIsValid();
}
catch (AutoMapperConfigurationException amce)
{
foreach (var e in amce.Errors)
{
Console.WriteLine("Source Type Name: {0}", e.TypeMap.SourceType.Name);
Console.WriteLine("Destination Type Name: {0}", e.TypeMap.DestinationType.Name);
Console.WriteLine("Unmapped Properties:");
foreach (var name in e.UnmappedPropertyNames)
{
Console.WriteLine(name);
}
Console.WriteLine();
}
throw;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment