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 Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!

TypeMockException - Cannot convert Enum to Nullable using Version8.6

+2 votes
Hi Team,
 
We are upgrading Typemock from version 8.4 to version 8.6(TypemockIsolatorSuite-8.6.0.10.921967232).  I got an exception in one of the test, 
 
Please find the following code snippet simplifies and illustrates the issue
 
Sample C#.Net Code
 
 public enum Enum1
    {
        test1 = 1,
        test2 = 2,
        test3 = 3
    }

    public class Class1
    {
        private Class2 _c2;
        public Class1(Class2 c2)
        {
            _c2 = c2;
        }
        public void Method1()
        {
            Enum1? enumboj;
            _c2.TestMtd("Testing", out enumboj);
        }
        
    }

    public class Class2
    {
        public void TestMtd(string test, out Enum1? enumboj)
        {
            enumboj = null;
            if (test == "test1")
            {
                enumboj = Enum1.test1;
            }
            else if (test == "test2")
            {
                enumboj = Enum1.test2;
            }
        }
    }
 
Typemock UnitTest Code
 
[TestClass]
    public class UnitTest1
    {
        [TestInitialize]
        public void MyTestInitialize()
        {
            MockManager.Init();
        }


        [TestMethod]
        public void TestMethod1()
        {
            Class2 c2 = Isolate.Fake.Instance<Class2>();
            Class1 obj = new Class1(c2);
            Enum1? enumboj;
            Isolate.WhenCalled(() => c2.TestMtd("test1", out enumboj)).DoInstead(context =>
            {
                context.Parameters[1] = enumboj = Enum1.test1;
            });

            obj.Method1();
        }
    }
 
In the above code, the second parameter I am passing is of nullable enum type. Below exception occurred. 
 
The same code is working fine in TypeMock Version 8.4. Please help us to resolve in Typemock 8.6 Version.
asked Nov 5, 2017 by satanova81 (4,180 points)
Hey satanova,

did the patch resolve the issue?
Thanks Rapthy, its working fine!!!

1 Answer

+1 vote
Hey Satanova,

It looks like you encountered a bug.

We will try to solve it as soon as possible, and I will update you when we do.
answered Nov 5, 2017 by SapirTypemock (2,120 points)
...