使用FakeItEasy,如何在假冒的属性上设置值?

时间:2011-10-26 18:57:17

标签: c# mocking fakeiteasy

使用FakeItEasy,我试图在假对象上捕获属性值的设置:

首先是界面:

interface ISomeInterface
{
    int MyProperty {get;set;}
}

然后是单元测试的片段:

var myObject = A.Fake<ISomeInterface>();

int saved = 0;
A.CallTo (() => myObject.MyProperty).Invokes (x => saved = ?????);

SomeMethod (myObject);
Assert.That (saved, Is.EqualTo (100));

void SomeMethod (ISomeInterface intf)
{
    intf.MyProperty = 100;
}

我不知道该怎么替换?????

1 个答案:

答案 0 :(得分:13)

var myObject = A.Fake<ISomeInterface>();

SomeMethod (myObject);
Assert.That (saved.MyProperty, Is.EqualTo(100));