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
heres a test that fails:
public class UsedClass
{
    public int multiply(int a)
    {
        return a * 3;
    }
    
}
public class ClassUnderTest
{
    private UsedClass _GetUsed;
    public UsedClass getUsed
    {
        get { return _GetUsed; }
    }
    public ClassUnderTest()
    {
        _GetUsed = new UsedClass();            
    }
}

[TestClass]
public class ConditionalChaining
{
    [TestMethod]
    public void ConditionalChaining_OnSameCall_throwsException()
    {

        ClassUnderTest target = new ClassUnderTest();

        Isolate.WhenCalled(() => target.getUsed.multiply(0)).WillReturn(20);
        Isolate.WhenCalled(() => target.getUsed.multiply(5)).WithExactArguments().WillReturn(3);

        Assert.AreEqual(3, target.getUsed.multiply(5));
        Assert.AreEqual(20, target.getUsed.multiply(20));
        Assert.AreEqual(20, target.getUsed.multiply(56));
    }
}


but passes if switch the whencalled statements like this:
[TestMethod]
public void ConditionalChaining_OnSameCall_throwsException()
{

    ClassUnderTest target = new ClassUnderTest();

    Isolate.WhenCalled(() => target.getUsed.multiply(5)).WithExactArguments().WillReturn(3);
        Isolate.WhenCalled(() => target.getUsed.multiply(0)).WillReturn(20);

    Assert.AreEqual(3, target.getUsed.multiply(5));
    Assert.AreEqual(20, target.getUsed.multiply(20));
    Assert.AreEqual(20, target.getUsed.multiply(56));
}

any idea why?
asked by (6.6k points)

1 Answer

0 votes
It seems we have a bug in this particular scenario.

I'll add a bug report and forward this information to our development team.

Thank you for the report and the repro.
answered by (11.9k points)
...