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
Hi,

I'm pretty new to TypeMock so bear with me if i'm doing some crappy stuff :)

here is what i'm doing to Fake some SharePoint Objects :

      private Microsoft.SharePoint.SPWeb FakeSite_RootWeb() {
            SPWeb fakeWeb = Isolate.Fake.Instance<SPWeb>(Members.ReturnRecursiveFakes);
            Isolate.WhenCalled(() => fakeWeb.Title).WillReturn("Intranet");
            Isolate.WhenCalled(() => fakeWeb.Description).WillReturn("Description Intranet");
            Isolate.WhenCalled(() => fakeWeb.Language).WillReturn(1036);
            Isolate.WhenCalled(() => fakeWeb.Lists).WillReturn(this.FakeSite_RootWeb_Lists());
            return fakeWeb;
        }
        
        private Microsoft.SharePoint.SPListCollection FakeSite_RootWeb_Lists() {
            SPListCollection fakeListCollection = Isolate.Fake.Instance<SPListCollection>(Members.ReturnRecursiveFakes);
            Isolate.WhenCalled(() => fakeListCollection[0]).WillReturn(this.FakeSite_RootWeb_Lists_QuizzCategories());
            string FakeSite_rootweb_lists_quizzcategories = "Quizz Catégories";
            Isolate.WhenCalled(() => fakeListCollection[FakeSite_rootweb_lists_quizzcategories]).WillReturn(fakeListCollection[0]);
            Isolate.WhenCalled(() => fakeListCollection[1]).WillReturn(this.FakeSite_RootWeb_Lists_QuizzAnimaux());
            string FakeSite_rootweb_lists_quizzanimaux = "Quizz Animaux";
            Isolate.WhenCalled(() => fakeListCollection[FakeSite_rootweb_lists_quizzanimaux]).WillReturn(fakeListCollection[1]);
            return fakeListCollection;
        }


this.FakeSite_RootWeb_Lists_QuizzCategories() return a SPList with 3 items
this.FakeSite_RootWeb_Lists_QuizzAnimaux() return a SPList with 2 items

I want to be able to get each SPList in SPListCollection via index or/and via name.

but as soon as i'm using Isolate.WhenCalled(() => fakeListCollection["Any string, even Empty"].... it will get the lastest fakeList i assigned to it.

Am i doing something wrong ?

Should i use WillReturnCollectionValuesOf somewhere (like in Isolate.WhenCalled(() => fakeWeb.Lists).WillReturn(this.FakeSite_RootWeb_Lists())) ?
asked by phil (640 points)

4 Answers

0 votes
Hi

What you need here is set conditional expectations on an indexer.
i.e return a specific value when fakeListCollection is called with int or string argument.

Currently it is not possible :(
The Isolator will return that last value as you could see.
The good news is that we are implementing this feature :)
I will send you the patch as soon as it ready so you could test it.
answered by ohad (35.4k points)
0 votes
+1 on the patch:

https://www.typemock.com/community/viewtopic.php?p=4459#4459

(you owe me one - :wink: )
answered by error (6.6k points)
0 votes
Hi

What you need here is set conditional expectations on an indexer.
i.e return a specific value when fakeListCollection is called with int or string argument.

Currently it is not possible :(
The Isolator will return that last value as you could see.
The good news is that we are implementing this feature :)
I will send you the patch as soon as it ready so you could test it.


Thanks, i can't wait :)
answered by phil (640 points)
0 votes
True Indexers feature was added in Isolator version 5.2.0
answered by dhelper (11.9k points)
...