private SPWeb RecordWebForUpdate() { SPWeb web = RecorderManager.CreateMockedObject <SPWeb>(); SPList list = RecorderManager.CreateMockedObject <SPList>(); SPListItemCollection itemCollection = RecorderManager.CreateMockedObject <SPListItemCollection>(); SPListItem item = RecorderManager.CreateMockedObject <SPListItem>(); using (RecordExpectations recorder = RecorderManager.StartRecording()) { recorder.ExpectAndReturn(web.Lists["Registrations"], list).RepeatAlways(); recorder.ExpectAndReturn(list.GetItems(new SPQuery()), itemCollection).RepeatAlways(); recorder.ExpectAndReturn(itemCollection.Count, 1); recorder.ExpectAndReturn(itemCollection[0], item); item[new Guid(Fields.CourseId)] = 1; recorder.CheckArguments(); item[new Guid(Fields.UserId)] = 1; recorder.CheckArguments(); //recorder.ExpectAndReturn(web.AllowUnsafeUpdates, false); //web.AllowUnsafeUpdates = true; item.Update(); //web.AllowUnsafeUpdates = false; } return(web); }
/// <summary> /// The RecordFieldInternalName method will mock the Get of the InternalName property /// of an SPField /// </summary> /// <param name="list">a mocked SPList object</param> /// <param name="id">the unique identifier of the SPField</param> /// <param name="internalName">the mocked InternalName</param> internal static void RecordFieldInternalName(SPList list, Guid id, string internalName) { using (RecordExpectations recorder = RecorderManager.StartRecording()) { SPField field = list.Fields[id]; recorder.CheckArguments(); string fieldName = field.InternalName; recorder.Return(internalName).RepeatAlways(); } }