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