1

以下代码应模拟具有不同电子邮件属性的两个对象。但相反,我得到了两个具有相同电子邮件属性的对象。为什么?

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);
}
4

1 回答 1

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);
于 2013-06-05T15:57:52.493 回答