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
Try the below code:
    public class GetPrjClass<T>
        where T: class 
    {
        private static string GetPrj()
        {
            throw new NotImplementedException();
        }

        public T RunPrj(string strAA)
        {
            var prjFile = GetPrj();
            return null;
      
        }


    }

    public class GetPrjClass2
    {
        private static string GetPrj()
        {
            throw new NotImplementedException();
        }

        public string RunPrj(string strAA)
        {
            return GetPrj();
           
         
        }     
    }

    public class UserInfo
    {
        public string Name
        { get; set; }
    }
    [TestFixture, Isolated]
    public class ClearMocksTest
    {
        private GetPrjClass<UserInfo> PrjClass;
        private GetPrjClass2 PrjClass2;


        [SetUp]
        public void Init()
        {
            PrjClass = Isolate.Fake.Instance < GetPrjClass<UserInfo>>(Members.CallOriginal);
            PrjClass2 = Isolate.Fake.Instance<GetPrjClass2>(Members.CallOriginal);
        }
        [TestCase("a")]
        [TestCase("b")]
        public void OhPrjClass(string aa)
        {
            Isolate.NonPublic.WhenCalled(PrjClass.GetType(),
                "GetPrj").WillReturn("");
     
            PrjClass.RunPrj(aa);
            
        }

        [TestCase("a")]
        [TestCase("b")]
        public void OhPrjClass2(string aa)
        {
            Isolate.NonPublic.WhenCalled(PrjClass2.GetType(),
                "GetPrj").WillReturn("");

            PrjClass2.RunPrj(aa);

        }
    }


Run this code, and this is what you will get
TestCase 'OhPrjClass("b")' failed: System.NotImplementedException : The method or operation is not implemented.
   C:Documents and SettingsSoon Hui.ESTEEMSOFTMy DocumentsjobspresentationTypemockWinFormWinFormTestClearMocksTest.cs(15,0): at WinFormTest.GetPrjClass`1.GetPrj()
   C:Documents and SettingsSoon Hui.ESTEEMSOFTMy DocumentsjobspresentationTypemockWinFormWinFormTestClearMocksTest.cs(20,0): at WinFormTest.GetPrjClass`1.RunPrj(String strAA)
   C:Documents and SettingsSoon Hui.ESTEEMSOFTMy DocumentsjobspresentationTypemockWinFormWinFormTestClearMocksTest.cs(68,0): at WinFormTest.ClearMocksTest.OhPrjClass(String aa)
   at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
   at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected, Object p1)
   C:Documents and SettingsSoon Hui.ESTEEMSOFTMy DocumentsjobspresentationTypemockWinFormWinFormTestClearMocksTest.cs(64,0): at WinFormTest.ClearMocksTest.OhPrjClass(String aa)


3 passed, 1 failed, 0 skipped, took 1.73 seconds.


It seems that the mocks and expectation for class with generics parameters are not cleared properly, but if the class does not have generics then it can clear properly.
________
DRUG TESTING KIT
asked by nsoonhui (59.1k points)

3 Answers

0 votes
If I use ClearMocks as the class attribute and Isolated as the method attribute, then the problem will go away. But still, I like the idea of Isolated at class level ( and NO MORE attributes at method level) because it makes the code cleaner.

So this is definitely a bug to me.
________
HONDA CIVIC (EIGHTH GENERATION) HISTORY
answered by nsoonhui (59.1k points)
0 votes
Hi,

May I know how this case is going on?

Just to let you know that I stumbled upon this problem again--so maybe you can escalate this case?
________
Colorado Medical Marijuana Dispensary
answered by nsoonhui (59.1k points)
0 votes
Hi,

You're correct, this is a bug. It's related to the combination of TestCase attribute and generic private behavior.

I'll update you when this bug is solved.

Best Regards,
Elisha
Typemock Support Team
answered by Elisha (12k points)
...