Consider the following interface...
public interface MyInterface
{
bool MyProperty { get; }
}
I am attempting to stub out a call to the get
function of this property in fakeiteasy.
[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);
}
The system-under-test's Foo() method simply returns the value of the MyProperty get property call. Unfortunately, this test always fails. When debugging, it seems the get
property is always returning false.
How can I stub out the return value of a get
property call?
EDIT - Adding MySUT class's code (as requested in comments)
public class MySUT
{
private readonly MyInterface _myInterface;
public MySUT(MyInterface myInterface)
{
_myInterface = myInterface;
}
public bool Foo()
{
return _myInterface.MyProperty;
}
}