考虑以下界面...
public interface MyInterface
{
bool MyProperty { get; }
}
我试图在fakeiteasyget
中删除对这个属性的函数的调用。
[Test]
public void Foo()
{
var fake = A.Fake<MyInterface>();
var sut = new MySUT(fake);
A.CallTo(() => fake.MyProperty).Returns(true);
var result = sut.Foo();
Assert.IsTrue(result);
}
被测系统的 Foo() 方法只返回 MyProperty get 属性调用的值。不幸的是,这个测试总是失败。调试时,该get
属性似乎总是返回 false。
如何存根get
属性调用的返回值?
编辑- 添加 MySUT 类的代码(根据评论中的要求)
public class MySUT
{
private readonly MyInterface _myInterface;
public MySUT(MyInterface myInterface)
{
_myInterface = myInterface;
}
public bool Foo()
{
return _myInterface.MyProperty;
}
}