So, I have a layer in my application that maps one type of an object
into another. Think ViewModel
to model type of mapping. The ViewModel
may have properties that are named differently or do not exist in the model. And vice-versa will be true as well.
I want to test my mapping layer, comparing the assignments, but also allowing me to provide some sort edge case handling for the properties that are different. Ideally, the test would fail if all of the properties in the ViewModel
are not checked.
Does anyone know if such a beast exists already?
public class CustomerViewModel
{
// This is the same as CustomerModel.CustomerName, but the names differ
public string Name { get; set; }
public int ID { get; set; }
}
public class CustomerModel
{
public string CustomerName { get; set; }
public int ID { get; set; }
}
// Would auto test the properties that match automatically. Additionaltest test for non matching. Fails if all properties aren't tested
Assert.CompareObjects(customerViewModelInstance, customerModelInstance)
.AdditionalTest("Name", "CustomerName")
.AdditionalComplexText((viewModel, model) =>
{
// do some sort of a compare of complex objects. Maybe the viewmodel has address fields, address1, address2 while the Model has an Address object with those fields.
});
The driving force behind this is the daunting task of having to assert every single property manually in code for a very large application.