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
Here's an interesting case. Try the following test code and production code:
    public enum CarType
    {
        Volkswagen=7,
        Ferrari=6,
        BMW=5
    }

    [TestFixture, ClearMocks]
    public class EnumTest
    {
        public EnumTest()
        {

        
        }

        private static List<T> GetEnumList<T>()
        {
            var enumList = Enum.GetValues(typeof(T))
            .Cast<T>().ToList();
            return enumList;
        }
        [Test, Isolated]
        public void RunEnumTest()
        {
           
           Assert.AreEqual(3,GetEnumList<CarType>().Count);
        }
    }


Run the code, you will get an InvalidOperationException:
System.InvalidOperationException : Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.
   at System.Reflection.RuntimeMethodInfo.ThrowNoInvokeException()
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)


Now, try to remove the ClearMocks and the Isolated attributes, rerun the case, the test can pass.

It seems that Typemock interfers with Enum.GetValues() in subtle ways.
________
LORATAB REHAB ADVICE
asked by nsoonhui (59.1k points)

6 Answers

0 votes
Hi Soon Hui,

I need to investigate this issue - let take it offline
answered by dhelper (11.9k points)
0 votes
I'm having this same issue on multiple tests. Did you folks ever resolve it?
answered by RonRatz (3k points)
0 votes
Here's some further information about what I'm seeing. I created the following code to demonstrate the issue. As you can see, I'm not doing any mocking or even any assertions. This "test" fails with the "System.InvalidOperationException: Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true." If I remove the Isolated attribute, the "test" runs w/o error.

    [TestFixture, Isolated]
    public class SampleTestFixture
    {
        [Test]
        public void TestThatUsesGenericMethod()
        {
            GetType<int>();
        }

        void GetType<T>()
        {
            Debug.WriteLine(typeof (T).ToString());
        }
    }


By the way, I'm still on v5.2.3.0.
answered by RonRatz (3k points)
0 votes
Hi Ron,

This bug was fixed and it does not exists in the last version (5.3.1) anymore.
Can you please upgrade to the latest version and tell me if you still see the problem?
answered by ohad (35.4k points)
0 votes
Thank you, Ohad,

I won't be able to get to that for a day or two but I'll let you know when I do.
answered by RonRatz (3k points)
0 votes
Ohad,

I installed v5.3.4 and it does appear that the problem is resolved. Now if I can just get the team to upgrade soon...

Thank you for you help.
answered by RonRatz (3k points)
...