I am trying to follow TDD principles in all my code base. The frontend (MVC) and backend part are split, and frontend use their own Model objects, while backed use database objects which are then saved to a document database (RavenDb).
This requires a lot of conversion from say CustomerModel
to CustomerData
. These are created independently from each other, so the strucutre might not match. For example, the CustomerModel
might be flat while CustomerData
has a nested object ContactDetails
.
Currently, we are implementing two methods, one say ConvertCustomerModelToCustomerData
and ConvertCustomerDataToCustomerModel
. These are very similar, but inverse of each other. Apart from this, these methods are also unit-tested. Hence, similar code is created in four instances - twice for each conversion, and twice for each unit test.
This is a big headache to maintain, and does not seem right to me. I've tried to use AutoMapper
, however I found it quite rigid. Also, I could not find any way how I can unit-test this.
Any ideas would be greatly appreciated.