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
Not sure on where the 'problem' is, so maybe it's in Isolator, maybe somewhere else.

Using Microsoft Patterns & Practices Enterprise Library (version 3.1); Caching Application block specifically.

I have the following set up in my test:

         //fake caching mechanism
         CacheManager cacheManagerFake = Isolate.Fake.Instance<CacheManager>();
         Isolate.WhenCalled(() => CacheFactory.GetCacheManager()).WillReturn(cacheManagerFake);
         Isolate.WhenCalled(() => cacheManagerFake.Contains("")).WillReturn(true);
         Isolate.WhenCalled(() => cacheManagerFake[""]).WillReturn(mock);


The last line is the source of the problem. When I run test, it's returning null (default of the fake), if I change my call to cacheManagerFake.GetData("") as shown below I get expected results.

         //fake caching mechanism
         CacheManager cacheManagerFake = Isolate.Fake.Instance<CacheManager>();
         Isolate.WhenCalled(() => CacheFactory.GetCacheManager()).WillReturn(cacheManagerFake);
         Isolate.WhenCalled(() => cacheManagerFake.Contains("")).WillReturn(true);
         Isolate.WhenCalled(() => cacheManagerFake.GetData("")).WillReturn(mock);


I'm not sure if this is possibile issue with default property indexers or something else but thankfully the work around was easy. Is there a know issue here though? (I'm on 5.2.2)
asked by boo (21.8k points)

1 Answer

0 votes
The difference between the two code snippets is the the first one is using indexer.

In Isolator we have a feature called "True indexers" - When faking indexers only specified index values will behave according to the specified behavior, other indexes will behave according to the fake object default behavior.

In other words - only the defined index ("") will return true other indexes will return false because the fake object was created using default constructor (Recursive fakes).

Isolator uses different rules when using method calls and so int the 2nd code snippet the behavior of all calls to the same method will return "true"
answered by dhelper (11.9k points)
...