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
Welcome to Typemock Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!

Isolate.Swap.AllInstances - obsolete

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 Mar 27, 2013 by MartinH (3,200 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 Mar 28, 2013 by alex (17,950 points)
0 votes
Great, thanks.
answered Apr 2, 2013 by MartinH (3,200 points)