Using FakeItEasy, how to get the value set on a property on a fake?

Stécy picture Stécy · Oct 26, 2011 · Viewed 8.1k times · Source

Using FakeItEasy, I am trying to capture the setting of a property value on a fake object:

First the interface:

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

Then a fragment of unit test:

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

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

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

And having

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

I don't know what to put to replace the ?????

Answer

Patrik H&#228;gne picture Patrik Hägne · Oct 27, 2011
var myObject = A.Fake<ISomeInterface>();

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