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
The easiest to illustrate it with failed unit tests.

Here is a tiny class:

public class MyClass
{
    public int CallCounter { get; set; }

    public MyClass() { this.CallCounter = 0; }

    public void DoSomething() { ++this.CallCounter; }
}


And here are the tests:

[TestFixture, Isolated]
public class Tests
{
    private MyClass m_Class;

    [SetUp]
    public void SetUp()
    {
        m_Class = new MyClass();
    }

    [Test]
    public void DoSomething_CallOriginal()
    {
        Isolate.WhenCalled(() => m_Class.DoSomething()).CallOriginal();

        DoSomething(1);

        Assert.AreEqual(1, m_Class.CallCounter);
    }

    [Test]
    public void DoSomething_ThrowException()
    {
        Isolate.WhenCalled(() => m_Class.DoSomething()).WillThrow(new Exception("Test"));

        DoSomething(1);

        Assert.AreEqual(0, m_Class.CallCounter);
    }

    [Test]
    public void DoSomething_CallOriginalAndThrowException()
    {
        Isolate.WhenCalled(() => m_Class.DoSomething()).CallOriginal();
        Isolate.WhenCalled(() => m_Class.DoSomething()).WillThrow(new Exception("Test"));

        DoSomething(2);

        Assert.AreEqual(1, m_Class.CallCounter);
    }

    [Test]
    public void DoSomething_ThrowExceptionAndCallOriginal()
    {
        Isolate.WhenCalled(() => m_Class.DoSomething()).WillThrow(new Exception("Test"));
        Isolate.WhenCalled(() => m_Class.DoSomething()).CallOriginal();

        DoSomething(2);

        Assert.AreEqual(1, m_Class.CallCounter);
    }

    [Test]
    public void DoSomething_CallOriginalAndIgnore()
    {
        Isolate.WhenCalled(() => m_Class.DoSomething()).CallOriginal();
        Isolate.WhenCalled(() => m_Class.DoSomething()).IgnoreCall();

        DoSomething(2);

        Assert.AreEqual(1, m_Class.CallCounter);
    }

    [Test]
    public void DoSomething_IgnoreAndCallOriginal()
    {
        Isolate.WhenCalled(() => m_Class.DoSomething()).IgnoreCall();
        Isolate.WhenCalled(() => m_Class.DoSomething()).CallOriginal();

        DoSomething(2);

        Assert.AreEqual(1, m_Class.CallCounter);
    }

    public void DoSomething(int count)
    {
        for (int index = 0; index < count; index++)
        {
            try
            {
                m_Class.DoSomething();
            }
            catch
            {
            }
        }
    }
}


Now if I run two tests will fail:

TestCase 'TestMultipleMethodFakes.Tests.DoSomething_CallOriginalAndIgnore' failed:
Expected: 1
But was: 0
C:\Projects\NET\TypeMockTest\TestMultipleMethodFakes\Tests.cs(72,0): at TestMultipleMethodFakes.Tests.DoSomething_CallOriginalAndIgnore()
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
C:\Projects\NET\TypeMockTest\TestMultipleMethodFakes\Tests.cs(66,0): at TestMultipleMethodFakes.Tests.DoSomething_CallOriginalAndIgnore()

TestCase 'TestMultipleMethodFakes.Tests.DoSomething_CallOriginalAndThrowException'
failed:
Expected: 1
But was: 0
C:\Projects\NET\TypeMockTest\TestMultipleMethodFakes\Tests.cs(50,0): at TestMultipleMethodFakes.Tests.DoSomething_CallOriginalAndThrowException()
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
C:\Projects\NET\TypeMockTest\TestMultipleMethodFakes\Tests.cs(44,0): at TestMultipleMethodFakes.Tests.DoSomething_CallOriginalAndThrowException()

As you can see, in case I have CallOriginal followed by either IgnoreCall or WillThrow, then CallOriginal seems to be replaced by IgnoreCall. If I swap the order in sequence, then it works.
asked by vagif (19.4k points)

5 Answers

0 votes
It looks like we have a bug there.

Thank you for the great report and reproduction - we will let you know when we solve this issue.
answered by dhelper (11.9k points)
0 votes
Impatiently waiting, as usual :wink:
answered by vagif (19.4k points)
0 votes
Hi guys,

Are there any news on the fix for this bug? Just checking to make sure it will make it for the next release. I have to disable a couple of tests because of this issue, and you know this is bad practice :D

Best regards
answered by vagif (19.4k points)
0 votes
Hi Vagif

We have a fix for this issue. 8)
I'm sending you a patch, please let me know if it works.
answered by ohad (35.5k points)
0 votes
Yes it works! My life makes sense again :lol:

Thanks and looking forward for a new version.
answered by vagif (19.4k points)
...