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.
This file contains 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
[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