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
I am (very successfully!) using Isolator for TDD of a SharePoint library, but have found a mocking behaviour that doesn't quite act as expected.

The code under test uses the following statement to get the value from a field in the list item:

listItem[fieldName].ToString()


When mocking an SPListItem, I am trying to set the values returned by fields in this list item using that above statement. In my test I have the following:

SPListItem fakeListItem = Isolate.Fake.Instance<SPListItem>();
Isolate.WhenCalled(() => fakeListItem["Data"].ToString()).WillReturn("SomeData");
Isolate.WhenCalled(() => fakeListItem["Description"].ToString()).WillReturn("SomeDescription");


However, when I call the "listItem[fieldName].ToString()" method with fieldName set to "Data", I get the value "SomeDescription" returned during my tests. If I swap the order of those two Isolate.WhenCalled lines, then both fieldNames return "SomeData"

Does that mean that Isolator does not fake the list item to the level of the explicitly named fields?
asked by garypayne (600 points)

4 Answers

0 votes
Hi,

As far as i know, the AAA syntax does not have the ability to distinguish calls to method based on input arguments.
basically this means that the expectations set by this:
Isolate.WhenCalled(() => fakeListItem["Data"].ToString()).WillReturn("SomeData"); 

is overridden by the one set here:
Isolate.WhenCalled(() => fakeListItem["Description"].ToString()).WillReturn("SomeDescription");


therefore calls to fakeListItem[????].ToString();
will always return "SomeDescription"


(the actual feature that you are looking for is named "Conditional mocking" in which the return value can vary according to input parameters)
I hope that Typemock team will implement this feature but currently you should be able to use natural syntax to do such things.

Hope this helps
answered by error (6.6k points)
0 votes
Hi Gary,

Error's reply is correct (Thanks!) - the current version of AAA in Isolator does not support conditional expectations (i.e. setting different behavior depends on parameters).

This is something we've been working on internally specifically for collections: we plan to make collection indexers conditional by default. I will send you a patch containing this feature once it's ready.

Doron
Typemock Support
answered by doron (16.5k points)
0 votes
I'd like notice too when this is done. Experiencing the same problem...
answered by mads.nissen@puzzlepa (140 points)
0 votes
True indexers feature was added in Isolator version 5.2.0
answered by dhelper (11.9k points)
...