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
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 by Jayme Davis (600 points)

1 Answer

0 votes
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 by lior (13.2k points)