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
Hi, a slightly updated sample from http://code.google.com/p/mocking-frameworks-compare/

SUT - a method from Brain class:
public void TouchIron(Iron iron)
{
    try {
        _hand.TouchIron(iron);
    }
    catch (BurnException) {
        _mouth.Yell();
    }
}

//test
[Test, Isolated]
public void TouchHotIron_Yell()
{
    var hand = Isolate.Fake.Instance<Hand>();
    var mouth = Isolate.Fake.Instance<Mouth>();
    Isolate.WhenCalled(() => hand.TouchIron(new Iron {IsHot = true})).WillThrow(new BurnException());

    var brain = new Brain(hand, mouth);
    brain.TouchIron(new Iron());

    Isolate.Verify.WasNotCalled(() => mouth.Yell());
}


Notice I'm expecting to throw for the iron with "IsHot=true" but during the test an "IsHot=false" iron is passed (a completely different instance!), so I'd expect that mouth.Yell isn't called.

However, the test fails.

Can anyone explain?

Thanks,
Andrew
asked by andreister (3.4k points)

1 Answer

0 votes
Andrew,
Isolator doesn't explicitly consider the arguments passed into the WhenCalled statements. When the method is called (with any arguments) the BurnException will be throw.
This is done to keep the tests robust and not fail if an argument is changed.

Indexers, will work as you expect, allowing different indexes to return different values.
In a coming version we will enable different behavior depending on the arguments passed
answered by eli (5.7k points)
...