Search code examples
.netc#-4.0microsoft-fakes

How to use MS Fakes setter?


I'm using a Fakes constructor:

ShimClassA.Constructor = (@this) =>
{
 var shim = new ShimClass(@this);
};

but I also need to set a property in the constructor:

ShimClassA.Constructor = (@this) =>
{
 var shim = new ShimClass(@this);
 shim.PropertyB = new FakesDelegate.Action<ClassB>...
};

When I type in the keyword new, intellisense fills in the FakesDelegate.Action<ClassB> part. I'm not sure what comes next. Anyone have some idea on the syntax and what else should go there? I know it is a delegate but I don't know what it is looking for.


Solution

  • shim.PropertyBSet = s=>{};
    

    another way of doing is in the constructor

    ShimClassA.Constructor =(@this)=>
    {
       var shim = new Shimclass(@this){PropertyBSet=s=>{};};
    }
    

    I am not sure, if you would get any benefit out of this. I would still advise to shim the getter of the PropertyB to return whatever you like.

    ShimClass.AllInstances.PropertyBGet =()=>{return something;};