Skip to content

Instantly share code, notes, and snippets.

@scottlaw1
Created January 17, 2013 23:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottlaw1/4560725 to your computer and use it in GitHub Desktop.
Save scottlaw1/4560725 to your computer and use it in GitHub Desktop.
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