1

Suppose we have two c# classes A and B with the following properties

A
-Name
-SurName

B
-Name
-SurName

Using Automapper I can map from class A to class B without any problem.

What happened if I do a refactor to Class A -Name. Using VS2010 Rename.

Then Classes would be

A
-NameRefactored
-SurName
B
-Name
-SurName

Due to the fact we are using Automapper the Refactor has no way to know that he should also change the name of B.

Worst the refactor will never complain anything until We found that the B.Name after the AutoMap is empty....

How can we avoid this kind of problems?

Tschareck
  • 4,071
  • 9
  • 47
  • 74

1 Answers1

4

Use the Mapper.AssertConfigurationIsValid() method to verify your configuration. It does exactly as advertised - checks to make sure that all members on the destination types are mapped.

Jimmy Bogard
  • 26,045
  • 5
  • 74
  • 69
  • Thanks, so what is your best suggestion for projects. Do you have a Test Class that checks all mapping configuration? And for each new added map we should be adding a new unit test.? – user1040478 Apr 26 '12 at 12:59
  • Nope, just one test works for us. It checks all mapping configurations (we make sure that the test and our production app both call the same configuration entry point, like a static class that has MapperConfig.Configure() or something). – Jimmy Bogard Apr 27 '12 at 01:31