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
Hi,
I’m having a bit of a funny happening in my code and I was wondering if it’s me or the the API.
I'm tesing against the SharePoint namespace (Microsoft.SharePoint).

I’ve set up the following:
// ———————————————————-
SPList list = Isolate.Fake.Instance(Members.ReturnRecursiveFakes);
SPListItem item = Isolate.Fake.Instance(Members.ReturnRecursiveFakes);

Isolate.Swap.NextInstance().With(list);
Isolate.Swap.NextInstance().With(item);

Isolate.WhenCalled(() => list.GetItemById(1)).WillReturn(item);
Isolate.WhenCalled(() => item["Customer Name"]).WillReturn(â€
asked by GR (1.2k points)

4 Answers

0 votes
Hi GR, and welcome to the forums!

The problem you are seeing is due to Isolator's API currently not supporting conditional expectations - we still can't say "if the parameter is 'customer name' return, otherwise 2". Right now what's happening in this case is that the last behavior you set up always applies. We are working on this feature for an upcoming release.

A workaround for the time being can be using our Natural Mocks API that supports conditional expectations - see our developer's guide for more information at https://www.typemock.com/Docs/UserGuide/index.php.

I'll make sure to notify you when we have conditional expectations in AAA.

Thanks,
Doron
Typemock support
answered by doron (16.5k points)
0 votes
Thank you.
I'm using Natural Mocks now and it's working as expected. :)

Another question on this note I'm trying to set a value on an SPListItem inside the Recoder but I dont know how to set the recorder to expect a list item using something like:
item["CustomerName"] = "Bob Jones";

Is there an example somewhere of this?

//////////////////////////////////////////////

using (RecordExpectations recorder = RecorderManager.StartRecording())
{
// dont know how to tell recorder to expect a set.
// the only thing I can find is AssignField() but dont know how to map
// this.
}

//////////////////////////////////////////////


Thanks :)
answered by GR (1.2k points)
0 votes
Hi

Expect setting an indexer is quit simple.
All you have to do is write it inside the recording block the way you do it in
the code under test:
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
    item["CustomerName"] = "Bob Jones";
   recorder.CheckArguments();
}   


:arrow: Make sure that item in the recording block is faked.
:arrow: Use recorder.CheckArguments() if you want to make sure the indexer is called with the the string "CustomerName" as an argument.
answered by ohad (35.5k points)
0 votes
Ohad,
This is exactly what I wanted. It's in and running.

Thanks
answered by GR (1.2k points)
...