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 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!
+1 vote
I'm working with the Autodesk Inventor SDK Com Interop library.

I've got a test set up where I need to return a mocked object from an indexed accessor but it gives me null instead of what I set it up to return:

            var drawing = Isolate.Fake.Instance<DrawingDocument>();
            var sheets = Isolate.Fake.Instance<Sheets>();
            var sheet = Isolate.Fake.Instance<Sheet>();
            Isolate.WhenCalled(() => sheets[null]).WillReturn(sheet);
            var testSheet = drawing.Sheets[1];

that last line throws an exception because testSheet is null. What am I doing wrong with this?
asked by (6.1k points)
reshown by

1 Answer

0 votes


When faking an indexer you need to pass the index into the `WhenCalled` as well (in this case the index is 1):

Isolate.WhenCalled(() => sheets[1]).WillReturn(sheet);


answered by (3.9k points)