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 please some explanation on the following
MockManager.Init();
         Mock mock=MockManager.Mock(typeof(Class6));
         mock.Strict=true;
         
            Class6 class6=new Class6();
            class6.testMethod();


fails as expected

Mock mock=MockManager.Mock(typeof(Hashtable));
            mock.Strict=true;
         Hashtable hashtable=new Hashtable();
            hashtable.Add("","");


not expected to pass but it does :?:
asked by tolisss (28.8k points)

3 Answers

0 votes
Hi please some explanation on the following
Mock mock=MockManager.Mock(typeof(Hashtable));
            mock.Strict=true;
         Hashtable hashtable=new Hashtable();
            hashtable.Add("","");


not expected to pass but it does :?:


Hi,
You are very thorough! :) , Well this is by design, There are some basic types that cannot be mocked. This is because the TypeMock framework itself uses these objects, and mocking them will cause an infinit recursion that will lead to a stack overflow. These are mainly from the root System namespace. We actually should have failed the Mock and told you that these cannot be mocked, but we haven't though of any reason that someone would want to Mock these types -
They are fast, they work well, they implement interfaces.

Can you tell me why you want to mock the hashTable?
answered by richard (3.9k points)
0 votes
Can you tell me why you want to mock the hashTable?


very simple i had to know what values have been added to a field of type hastable.
answered by tolisss (28.8k points)
0 votes
Can you tell me why you want to mock the hashTable?


very simple i had to know what values have been added to a field of type hastable.

Hmmm,
Are you checking a private member of your class? For testing private members, you can see a discussion about this here.

TypeMock has a solution for this, using ObjectState, you can get the field and check it.
answered by richard (3.9k points)
...