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 - Class inherit from IConvertible having issue using Version8.6

+1 vote
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 class Class1
    {
        private Class2 _c2;
        public Class1(Class2 c2)
        {
            _c2 = c2;
        }
        public void Method1()
        {
            Test t;
            _c2.TestMtd("Testing", out t);
        }       
    }

    public class Class2
    {
        public void TestMtd(string test, out Test t)
        {
            t = new Test();
        }
    }

    public class
Test : IConvertible
    {
        // please implement all the methods from IConvertible, here space is not allowed
    }
 
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);
            Test t;
            Isolate.WhenCalled(() => c2.TestMtd("test1", out t)).DoInstead(context =>
            {
                t = new Test();
                context.Parameters[1] = t;
            });

            obj.Method1();
        }
    }
 
In the above code, the second parameter I am passing is class inherited from IConvertible. 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 3 by satanova81 (260 points)

For IConvertiable Implementation:

public classTest : IConvertible
    {
        public TypeCode GetTypeCode()
        {
            throw new NotImplementedException();
        }

        public bool ToBoolean(IFormatProvider provider)
        {
            throw new NotImplementedException();
        }

        public byte ToByte(IFormatProvider provider)
        {
            throw new NotImplementedException();
        }

        public char ToChar(IFormatProvider provider)
        {
            throw new NotImplementedException();
        }

        public DateTime ToDateTime(IFormatProvider provider)
        {
            throw new NotImplementedException();
        }

        public decimal ToDecimal(IFormatProvider provider)
        {
            throw new NotImplementedException();
        }

        public double ToDouble(IFormatProvider provider)
        {
            throw new NotImplementedException();
        }

        public short ToInt16(IFormatProvider provider)
        {
            throw new NotImplementedException();
        }

        public int ToInt32(IFormatProvider provider)
        {
            throw new NotImplementedException();
        }

        public long ToInt64(IFormatProvider provider)
        {
            throw new NotImplementedException();
        }

        public sbyte ToSByte(IFormatProvider provider)
        {
            throw new NotImplementedException();
        }

        public float ToSingle(IFormatProvider provider)
        {
            throw new NotImplementedException();
        }

        public string ToString(IFormatProvider provider)
        {
            throw new NotImplementedException();
        }

        public object ToType(Type conversionType, IFormatProvider provider)
        {
            throw new NotImplementedException();
        }

        public ushort ToUInt16(IFormatProvider provider)
        {
            throw new NotImplementedException();
        }

        public uint ToUInt32(IFormatProvider provider)
        {
            throw new NotImplementedException();
        }

        public ulong ToUInt64(IFormatProvider provider)
        {
            throw new NotImplementedException();
        }
    }

1 Answer

0 votes

Hey satanova,

What happened is that when trying to assign the value of 't' to context.Parameters[1], the method "ToType" is activated and throws an excpetion. 

Typemock catches this exception and shows the message on the screen. 

I suggest you to implement "ToType", or, if it's a legacy code - to use "WhenCalled" in order to change the method's behavior. 

Let me know if that helps. 

answered Nov 5 by SapirTypemock (1,130 points)
Hey satanova,

did you manage to solve this issue?
Hi SapirTypemock,

We are having around three out parameters with different datatypes. So can you please help us?
Hey satanova,

Which datatypes do you have?

Can you send me the tests with those datatypes?
sorry, its same datatype. Above program with multiple out parameter with datatype class Test.
Hey satanova,

Did you try to implement "ToType" method?
If we implement the method like below, its working fine.

 public object ToType(Type conversionType, IFormatProvider provider)
        {
            return provider;
        }

But this is product code, so we need to test all unit test. Is there is any way to work in only unit test side without touching our product code.

Because same functionality working fine typemock 8.4.
We will provide a patch that will resolve this issue in the next following days.

I'll keep you updated.
...