所以,我的应用程序中有一个层可以将一种类型的 a 映射object
到另一种类型。考虑ViewModel
对映射类型进行建模。ViewModel
可能具有命名不同或模型中不存在的属性。反之亦然。
我想测试我的映射层,比较分配,但也允许我为不同的属性提供某种边缘情况处理。ViewModel
理想情况下,如果未检查中的所有属性,则测试将失败。
有谁知道这样的野兽是否已经存在?
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.
});
这背后的驱动力是一项艰巨的任务,即必须在非常大的应用程序的代码中手动声明每个属性。