Welcome to Typemock Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!

HashTables

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 Feb 2, 2005 by tolisss (3,660 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 Feb 2, 2005 by richard (3,900 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 Feb 2, 2005 by tolisss (3,660 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 Feb 2, 2005 by richard (3,900 points)
...