Using FakeItEasy, is there a way to fake the installer of record properties?

Using FakeItEasy, is there a way to fake the installer of record properties only?

The interface I have to work with looks something like this:

Interface IMyInterface
{
   String Foo { set; }
}

I tried the following, but the syntax does not work.

IMyInterface _myObject = A.Fake<IMyInterface>();
A.CallTo(() => _myObject.Foo).Invokes((String foo) => {
   //save off foo
});

I also tried this, but with a syntax error.

IMyInterface _myObject = A.Fake<IMyInterface>();
A.CallTo(() => _myObject.set_Foo).Invokes((String foo) => {
   //save off foo
});
+4
source share
1 answer

You can do this, but it’s not very simple, due to the restriction of expression trees (you cannot write a destination in an expression). The workaround is to use the “extended” call configuration syntax (described in the docs ):

A.CallTo(_myObject)
 .Where(call => call.Method.Name == "set_Foo")
 .Invokes((String foo) => {
   //save off foo
 });

, , , ; , . , , , .

+4

All Articles