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'm having some trouble getting mocking of generic types to work. I get a System.Reflection.TargetException with the following code:

      class Test
      {
         public List<T> GetList<T>()
         {
            return new List<T>();
         }
      }

      [Test]
      [VerifyMocks]
      public void GenericTest()
      {
         List<int> myList = new List<int>();

         Test test = new Test();

         using (RecordExpectations recorder = mocker.Record())
         {
            recorder.ExpectAndReturn(test.GetList<int>(), myList);
         }

         Assert.AreSame(myList, test.GetList<int>());
      }


This should work, shouldn't it?

Cheers,

Rory.
________
marijuana indica
asked by rorydriscoll (3.8k points)

2 Answers

0 votes
Hi Rory,

You have identified a bug :twisted:

We'll work on a solution and get back to you.
answered by gilz (14.5k points)
0 votes
Hi,

The fix for this issue was included as part of the 4.22 release.
answered by lior (13.2k points)
...