DISQUS

DISQUS Hello!  The comments on this profile are unclaimed and thus are unverified.

Do they belong to you? Claim these comments.

Garth's picture

Unregistered

Feeds

aliases

  • Garth

Garth

7 months ago

in Unit Testing SharePoint - Getting into the Object Model on Agile SharePoint Development by 21apps
Here's some sample code of the Natural Mocks I'm using now (nothing worse than a posting that says I've got it working an no sample code ;) )

/////////////////////////////////////////////////
SPList list = RecorderManager.CreateMockedObject();
SPListItem item = RecorderManager.CreateMockedObject();
using (RecordExpectations recorder = RecorderManager.StartRecording())
{
recorder.ExpectAndReturn(list.GetItemById(1), item);

recorder.ExpectAndReturn(item["ID"], 1);
recorder.ExpectAndReturn(item["Customer Name"], "Bob Jones");
recorder.ExpectAndReturn(item["NumberOfItems"], 2);

}

7 months ago

in Unit Testing SharePoint - Getting into the Object Model on Agile SharePoint Development by 21apps
Cool. Thanks for the response. I'm using Natural Mocks for this instance and it's working.

Shotto

7 months ago

in Unit Testing SharePoint - Getting into the Object Model on Agile SharePoint Development by 21apps
Thanks for this article it's great!

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'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("Bob Jones");
Isolate.WhenCalled(() => item["NumberOfItems"]).WillReturn(2);
// ----------------------------------------------------------
However when I call item["Customer Name"] the mock object returns '2' instead of 'Bob Jones' it appears to be ignoring the field name set in the item[] and just returns the last value that was set with 'WhenCalled()'.

Have I set this up incorrectly?
Thanks

10 months ago

in Writing CAML Queries For Retrieving List Items from a SharePoint List on SharePoint Magazine
Karin,
Thank you for this posting. I've been doing a fair amount of CAML lately and have used this page as a starting point for alot of my work.

Thanks
Returning? Login