【发布时间】:2011-09-10 17:04:07
【问题描述】:
我遇到了以下问题: 目前我正在使用 TDD 重构我的项目。有一个我无法更改的现有域。
代码示例:
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 之类的东西,但不是为了映射,而是为了比较。请给点建议。
提前致谢。
【问题讨论】:
标签: .net unit-testing