13

使用 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;
}

不知道用什么来代替??????

4

1 回答 1

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

SomeMethod (myObject);
Assert.That (saved.MyProperty, Is.EqualTo(100));
于 2011-10-27T20:08:45.277 回答