Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?????

like image 755
Stécy Avatar asked Oct 26 '11 18:10

Stécy


1 Answers

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

SomeMethod (myObject);
Assert.That (saved.MyProperty, Is.EqualTo(100));
like image 139
Patrik Hägne Avatar answered Sep 20 '22 08:09

Patrik Hägne