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!

Underlying type is a hashtable which has to be populated

0 votes
I'm having a problem mocking a ResultPropertyCollection object. This object has two fields PropertyNames and PropertyValues. I can successfully mock this object, but it does not help very much - reason being ResultPropertyCollection inherits from DictionaryBase and the underlying hashtable has to be populated. I have read the limits of mscorlib assemblies, etc... but in my case I have to mock this hashtable.

This works, but doesn't seem like the easiest way .... I used a little reflection to add to the underlying hashtable.

Mock<ResultPropertyCollection> pc = MockManager.MockObject<ResultPropertyCollection>(Constructor.Mocked);

            ResultPropertyCollection rpc = pc.Object as ResultPropertyCollection;

                                                        null, rpc, new string[] { "test-key", "test-value" });

Is there an easier way?

asked Jun 13, 2008 by Jayme Davis (120 points)

1 Answer

+1 vote
Hi Jayme,

I'm not sure, I've completely understood you, but look at the following example:
public void MockIndexerTest()
    ResultPropertyCollection target = 
    using (RecordExpectations rec = new RecordExpectations())
        string dum = target["test-key"];
    string actual = target["test-key"];

    Assert.AreEqual("test-value", actual);

was this what you needed to do?
If not(which means that we have misread you), please add your test code.
It should explain better what you are trying to do.
answered Jun 15, 2008 by lior (18,340 points)