4
我遇到了以下問題: 目前我正在使用TDD重構我的項目。有一個我不能改變的存在的域名。如何將複雜對象作爲C#中的結構進行單元測試比較
代碼示例:
public class Product: IEquatable<Product>
{
public int Id { get; set; }
public string Name { get; set; }
public bool Equals(Product other)
{
if (other == null)
return false;
if (Id == other.Id && Name == other.Name)
return true;
return false;
}
}
[TestClass]
public class ProductTest
{
[TestMethod]
public void Test1()
{
var product1 = new Product {Id = 100, Name = "iPhone"};
var product2 = new Product {Id = 100, Name = "iPhone"};
Assert.IsTrue(product1.Equals(product2));
}
}
我的目標是要找到一個快速的解決方案比較複雜的對象作爲結構和沒有實現IEquatable,因爲我無法擴展經營業務層。我的意思是像Automapper,但不映射,但只是爲了比較。請給出一些建議。
提前致謝。
這樣的事情? http://stackoverflow.com/questions/986572/hows-to-quick-check-if-data-transfer-two-objects-have-equal-properties-in-c/986617#986617或者:http:// stackoverflow .com/questions/3060382 /比較2-objects-and-retrive-a-list-of-fields-with-different-values/3060929 – 2011-06-08 09:10:38