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
Hi,

I am trying to create a mock object of an interface containing generics. Please find below a smaller test case I created to reproduce the bug. Any help would be greatly appreciated.

Thanks,
- hemdanw

Code Under Test:
public class CC<T>
{
    long C1(T t) { return 5; }
}
    
public interface A
{
    long B<T>(T t);
    long C<T>(CC<T> t);
}


Test Code:
MockObject mockA = MockManager.MockObject(typeof(A));

... Cann't even create a mock object for the interface type :(

Error Message:
Test method IndexedObjectUnitTest.IndexedObjectTest.GTest threw exception: System.TypeLoadException: Method 'C' in type 'MockA' from assembly 'DynamicMockAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation..

Error Stack:
at System.Reflection.Emit.TypeBuilder.TermCreateClass(Int32 handle, Module module)
at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
at System.Reflection.Emit.TypeBuilder.CreateType()
at t.a(Type A_0, Object[] A_1)
at TypeMock.MockManager.MockObject(Type type, Constructor mockConstructors, Object[] args)
at TypeMock.MockManager.MockObject(Type type, Object[] args)
at IndexedObjectUnitTest.IndexedObjectTest.GTest()
asked by hemdanw (1.7k points)

7 Answers

0 votes
Thanks for reporting this a giving a simple example.
its a bug :twisted:
We will fix this an send you the fix
answered by scott (32k points)
0 votes
Fix sent, this will be included in our next release
answered by scott (32k points)
0 votes
Hi Scott,

Thanks for the patch. It worked for the test case I had sent earlier, but failed for my actual program under test. After some investigation I discovered that my program also contained the following test case below (Note: Added method D<T>(int t) below) that also reproduces the bug described above.

Code Under Test:
public class CC<T>
{
    long C1(T t) { return 5; }
}
   
public interface A
{
    long B<T>(T t);
    long C<T>(CC<T> t);
    long D<T>(int t);
}


Unit Test Code:
MockObject mockA = MockManager.MockObject(typeof(A));


By the way, your customer support response time has been great.
This is greatly appreciated,
Thanks,

- Wael
answered by hemdanw (1.7k points)
0 votes
Nice one,
fixed and sent offline 8)
answered by scott (32k points)
0 votes
Hi,

Can you please re-send the patch. I received an attachment winmail.dat (not TypeMock.dll). Also, you can CC "<REMOVED>" just in case my company's email filter is interfering with the send.

Thanks a lot,
- Wael
answered by hemdanw (1.7k points)
0 votes
Hi,
I resent the patch, please tell me if it works.
I have removed your e-mail address from the previous post to stop spam :evil:
answered by scott (32k points)
0 votes
Hi,

I got the patch and it worked perfectly! I also tried using the private accessors to mock private methods with NaturalMocks in v3.6. Worked like a charm ;)

BTW: Thanks for removing my email address from the previous post.

Your customer support time is great and very much appreciated.
Good work and a very nice product,
- Wael
answered by hemdanw (1.7k points)
...