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

本文关键字:属性 设置 FakeItEasy 使用 | 更新日期: 2023-09-27 18:12:41

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

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

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

var myObject = A.Fake<ISomeInterface>();
SomeMethod (myObject);
Assert.That (saved.MyProperty, Is.EqualTo(100));