以下代码应该使用不同的电子邮件属性模拟两个对象。但相反,我得到两个具有相同电子邮件属性的对象。为什么呢?
using (var autoMock = AutoMock.GetStrict())
{
var contact1 = autoMock.Mock<IContact>();
contact1.SetupGet(x => x.Email).Returns("a");
var contact2 = autoMock.Mock<IContact>();
contact2.SetupGet(x => x.Email).Returns("b");
Assert.AreNotEqual(contact1.Object.Email, contact2.Object.Email);
}
答案 0 :(得分:0)
使用Mock类而不是AutoMock:
var contact1 = new Mock<IContact>();
contact1.SetupGet(x => x.Email).Returns(DefaultEmail1);
var contact2 = new Mock<IContact>();
contact2.SetupGet(x => x.Email).Returns(DefaultEmail2);
Assert.AreNotEqual(contact1.Object.Email, contact2.Object.Email);