chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
I have been using the following code until now:

I can see that this has been marked as Obsolete, and that I should use Isolate.Fake.AllUnstances, but how do I pass a parameter (as I did with Swap and the With(...) method) to a pre-assigned instance?

asked by MartinH (3.2k points)

2 Answers

0 votes

Isolate.Fake.AllInstances<>(); returns a proxy object on which you should set the desired behavior.


public class UnitTest1
    public void IsolateFakeAllInstances()
        var allFakeFoo = Isolate.Fake.AllInstances<Foo>();
        Isolate.WhenCalled(() => allFakeFoo.GetNum()).WillReturn(5);

        var foo = new Foo();
        Assert.AreEqual(5 , foo.GetNum());

public class Foo
    public int GetNum()
        return 3;

You can find more info here.
answered by alex (17k points)
0 votes
Great, thanks.
answered by MartinH (3.2k points)