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:
Isolate.Swap.AllInstances<CalculadorDocConfigProviderController>().With(calculadorDocConfigProvider);

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?
Isolate.Fake.AllInstances<CalculadorDocConfigProviderController>(???);

Thanks,
Martin.
asked by MartinH (3.2k points)

2 Answers

0 votes
Hi,

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

Example:

[TestClass]
public class UnitTest1
{
    [TestMethod]
    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 (18k points)
0 votes
Great, thanks.
answered by MartinH (3.2k points)
...