Hi,
I'm experiencing the following problem.
I'm trying to mock this class:
inside this test
But the test fails and I obtain this exception:
Do you have any idea why this happens? I wasn't able to find any help about this problem in the forum, except this one.
I'm working with JustMock Q2 2012 (trial version), VS2010 and Win7x64.
Thanks in advance
Livio
I'm experiencing the following problem.
I'm trying to mock this class:
public
class
UnmockableClass<T>
{
private
bool
_dummyvariable;
public
UnmockableClass()
{
_dummyvariable =
true
;
}
public
static
UnmockableClass<T> GetInstance<TDescriptor>() where TDescriptor : IDescriptor<T>
{
throw
new
NotImplementedException();
}
}
inside this test
[TestClass]
public
class
UnmockableClassTest
{
[TestMethod]
public
void
SimpleTest()
{
Mock.SetupStatic<UnmockableClass<AvailableID>>();
//nothing else. The test will fail with just this line of code above
}
}
But the test fails and I obtain this exception:
Test 'JustMockIssueTestMock.UnmockableClassTest.SimpleTest' failed: Test method JustMockIssueTestMock.UnmockableClassTest.SimpleTest threw exception:
System.ArgumentException: GenericArguments[0], 'JustMockIssue.IDescriptor`1[T]', on 'JustMockIssue.UnmockableClass`1[JustMockIssue.AvailableID] GetInstance[TDescriptor]()' violates the constraint of type 'TDescriptor'. ---> System.Security.VerificationException: Method JustMockIssue.UnmockableClass`1[JustMockIssue.AvailableID].GetInstance: type argument 'JustMockIssue.IDescriptor`1[T]' violates the constraint of type parameter 'TDescriptor'.
at System.RuntimeMethodHandle.GetStubIfNeeded(RuntimeMethodHandleInternal method, RuntimeType declaringType, RuntimeType[] methodInstantiation)
at System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)
--- End of inner exception stack trace ---
at System.RuntimeType.ValidateGenericArguments(MemberInfo definition, RuntimeType[] genericArguments, Exception e)
at System.Reflection.RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)
at Telerik.JustMock.Weaver.WeaverInterceptorBuilder.DefineInterceptor(MethodBase methodBase, FieldBuilder fldInterceptor, Type[] parameters)
at Telerik.JustMock.Weaver.DynamicInjector.EmitInterceptor(ILGenerator il, MethodBase methodInfo)
at Telerik.JustMock.Weaver.DynamicInjector.Inject(Type targetType, MethodBase methodBase, MethodInfo containerMethodInfo)
at Telerik.JustMock.Weaver.DynamicInjector.Inject(Type targetType, MethodBase methodBase, MethodInfo injectingMethod, Boolean force)
at Telerik.JustMock.Weaver.DynamicInjector.Inject(Type targetType, MethodBase methodBase)
at Telerik.JustMock.MockManager.SetupMock(Behavior behavior, Boolean static)
at Telerik.JustMock.MockManager.SetupStatic()
at Telerik.JustMock.Mock.SetupStatic(Type targetType, Behavior behavior, StaticConstructor staticConstructor)
at Telerik.JustMock.Mock.SetupStatic[T]()
UnmockableClassTest.cs(17,0): at JustMockIssueTestMock.UnmockableClassTest.SimpleTest()
Do you have any idea why this happens? I wasn't able to find any help about this problem in the forum, except this one.
I'm working with JustMock Q2 2012 (trial version), VS2010 and Win7x64.
Thanks in advance
Livio