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 Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
I'm trying to fake this code scenario:
    public sealed class MyClass
    {
        public static bool TryThis(Exception ex, object param)
        {
            bool condition = false;
            
            try
            {
                condition = StaticClass.StaticMethod(ex, param1);
            }
            catch (Exception e)
            {
                try
                {
                    condition = StaticClass.StaticMethod(e, param2);
                }
                catch
                {
                    // Some more logic here...
                }
            }
            
            return condition;
        }
    }

My unit test method looks like this:
    public void MyClass_TryThis_Test()
    {
        var ex = new Exception("Test Exception");
        var e = new ConfigurationException("Thrown by StaticClass.StaticMethod");

        // Arrange
        Isolate.Fake.StaticMethods(typeof(StaticClass), Members.ReturnRecursiveFakes);
        Isolate.WhenCalled(() => StaticClass.StaticMethod(null, null)).WillThrow(e);
        Isolate.WhenCalled(() => StaticClass.StaticMethod(null, null)).WillReturn(false);
        
        // Act
        var actualReturnValue = MyClass.TryThis(ex, new object());

        // Assert
        Assert.IsFalse(actualReturnValue, "Cannot return true");
    }

If I run my test it fails miserably giving back a message about a System.InvalidCastException.
I've found a similar scenario in another thread on the forum, in that case though the second fake call was an overloaded version of the method. In that case Doron replied that: "Unfortunately, there [is] currently no support for method overloads in AAA."
In my case no overloaded methods are involved. Hence my question: is this scenario supported in AAA or do I have to use the old way to accomplish the task?

Thanks in advance.
asked by Darkbreet (600 points)

1 Answer

0 votes
Hi Darkbreet,

I managed to confirm you have found a bug in Isolator :(

This is a bug when sequencing expectations where the sequence starts with WillThrow. I will work on fixing this and send you a patch, as well as include it in an upcoming version.

By the way, since the forum post you mentioned, overload support was included in Isolator :).

Thanks!
Doron
answered by doron (17.2k points)
...