private SPListItem CreateMockSPListItem(SPListItemMockType mockType, string status) { SPListItem listItem = RecorderManager.CreateMockedObject <SPListItem>(); switch (mockType) { case SPListItemMockType.Populate: using (RecordExpectations recorder = RecorderManager.StartRecording()) { recorder.ExpectAndReturn(listItem.ID, 1); } break; case SPListItemMockType.StatusCheck: using (RecordExpectations recorder = RecorderManager.StartRecording()) { recorder.ExpectAndReturn(listItem[new Guid(Fields.RegistrationStatus)], status); } break; default: using (RecordExpectations recorder = RecorderManager.StartRecording()) { recorder.ExpectAndReturn(listItem.ID, 1); } break; } return(listItem); }
private SPWeb GetMockSPWeb(bool userFound) { var web = RecorderManager.CreateMockedObject <SPWeb>(); var user = RecorderManager.CreateMockedObject <SPUser>(); if (!userFound) { user = null; } using (RecordExpectations recorder = RecorderManager.StartRecording()) { SPUser spUser = web.SiteUsers.GetByID(12345); recorder.Return(user); } if (user != null) { using (RecordExpectations recorder = RecorderManager.StartRecording()) { string userName = user.Name; recorder.Return("MockUserName").RepeatAlways(); string userEmail = user.LoginName; recorder.Return("*****@*****.**").RepeatAlways(); } } return(web); }
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); }
public void Activate <T>(T controller, HandleInfo handleInfo) where T : ViewController { View view = controller.View; MockedEvent controlsCreated = null; MockedEvent currentObjectChanged = null; if (handleInfo != null) { if (handleInfo.ControlsCreated) { using (RecorderManager.StartRecording()) { view.ControlsCreated += null; } controlsCreated = RecorderManager.LastMockedEvent; } if (handleInfo.CurrentObjectChanged) { using (RecorderManager.StartRecording()) { view.CurrentObjectChanged += null; } currentObjectChanged = RecorderManager.LastMockedEvent; } } controller.Active.Clear(); controller.Active[""] = true; if (controlsCreated != null) { controlsCreatedHandler = (EventHandler)controlsCreated.GetEventHandle(); } if (currentObjectChanged != null) { currentObjectChangedHandler = (EventHandler)currentObjectChanged.GetEventHandle(); } }
private SPWeb CreateMockSPWeb(bool blank, bool validUser) { SPWeb web = RecorderManager.CreateMockedObject <SPWeb>(); if (!blank) { SPUserCollection users = RecorderManager.CreateMockedObject <SPUserCollection>(); if (validUser) { SPUser user = RecorderManager.CreateMockedObject <SPUser>(); using (RecordExpectations recorder = RecorderManager.StartRecording()) { recorder.ExpectAndReturn(web.SiteUsers.GetCollection(new string[] { }), users); recorder.ExpectAndReturn(users.Count, 1); recorder.ExpectAndReturn(users[0].LoginName, string.Format(@"{0}\{1}", Environment.MachineName, "spgemployee")); recorder.ExpectAndReturn(users[0], user); recorder.ExpectAndReturn(user.ID, 1).RepeatAlways(); recorder.ExpectAndReturn(user.Name, "SPG Employee").RepeatAlways(); recorder.ExpectAndReturn(user.LoginName, string.Format(@"{0}\{1}", Environment.MachineName, "spgemployee")).RepeatAlways(); } } else { using (RecordExpectations recorder = RecorderManager.StartRecording()) { recorder.ExpectAndReturn(web.SiteUsers.GetCollection(new string[] { }), users); recorder.ExpectAndReturn(users.Count, 0); } } } return(web); }
private SPItemEventProperties CreateMockSpItemEventProperties(string title, string code, DateTime enrollmentDate, DateTime startDate, DateTime endDate, float courseCost) { //Create any mock objects we'll need here SPItemEventProperties spItemEventProperties = RecorderManager.CreateMockedObject <SPItemEventProperties>(); SPWeb web = RecorderManager.CreateMockedObject <SPWeb>(); SPItemEventDataCollection afterProperties = RecorderManager.CreateMockedObject <SPItemEventDataCollection>(); //record our main expectations using (RecordExpectations recorder = RecorderManager.StartRecording()) { object obj = spItemEventProperties.AfterProperties; recorder.Return(afterProperties).RepeatAlways(); afterProperties["Title"] = string.Empty; afterProperties["TrainingCourseCode"] = string.Empty; spItemEventProperties.OpenWeb(); recorder.Return(web); obj = spItemEventProperties.ListItem[new Guid(Fields.TrainingCourseCode)]; recorder.Return("12345678").RepeatAlways(); } //Record our expectations for our AfterProperties collection MockHelper.RecordSPItemEventDataCollection(afterProperties, "Title", title); MockHelper.RecordSPItemEventDataCollection(afterProperties, "TrainingCourseCode", code); MockHelper.RecordSPItemEventDataCollection(afterProperties, "TrainingCourseEnrollmentDate", enrollmentDate); MockHelper.RecordSPItemEventDataCollection(afterProperties, "TrainingCourseStartDate", startDate); MockHelper.RecordSPItemEventDataCollection(afterProperties, "TrainingCourseEndDate", endDate); MockHelper.RecordSPItemEventDataCollection(afterProperties, "TrainingCourseCost", courseCost); return(spItemEventProperties); }
/// <summary> /// RecordSPItemEventDataCollection mocks the Get behavior of the /// SPItemEventDataCollection collection. /// </summary> /// <param name="properties">A mocked instance of an SPItemEventDataCollection object</param> /// <param name="fieldName">the name of the SPField that will be used as the indexer</param> /// <param name="value">the mocked value to return</param> public static void RecordSPItemEventDataCollection(SPItemEventDataCollection properties, string fieldName, object value) { using (RecordExpectations recorder = RecorderManager.StartRecording()) { object val = properties[fieldName]; recorder.Return(value).RepeatAlways().WhenArgumentsMatch(); } }
/// <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(); } }
private SPWeb RecordGetFieldName() { SPWeb web = RecorderManager.CreateMockedObject <SPWeb>(); using (RecordExpectations recorder = RecorderManager.StartRecording()) { recorder.ExpectAndReturn(web.Lists[""].Fields[new Guid()].InternalName, "UnitTestField"); } return(web); }
private SPListItem RecordAddSPListItem() { SPListItem item = RecorderManager.CreateMockedObject <SPListItem>(); using (RecordExpectations recorder = RecorderManager.StartRecording()) { recorder.ExpectAndReturn(item[new Guid(Fields.Id)], 1); } return(item); }
private SPWeb RecordUpdateReturnSPWeb() { SPWeb web = RecorderManager.CreateMockedObject <SPWeb>(); SPUser user = RecorderManager.CreateMockedObject <SPUser>(); using (RecordExpectations recorder = RecorderManager.StartRecording()) { recorder.ExpectAndReturn(web.SiteUsers.GetByID(1), user); } return(web); }
private SPListItem RecordGetReturnSPListItem() { SPListItem item = RecorderManager.CreateMockedObject <SPListItem>(); using (RecordExpectations recorder = RecorderManager.StartRecording()) { recorder.ExpectAndReturn(item[new Guid(Fields.Id)], 1); recorder.ExpectAndReturn(item[new Guid(Fields.Title)], "TestTitle"); recorder.ExpectAndReturn(item[new Guid(Fields.WorkflowItemId)], 5); } return(item); }
private SPWeb RecordWebForGetAll() { SPWeb web = RecorderManager.CreateMockedObject <SPWeb>(); SPList list = RecorderManager.CreateMockedObject <SPList>(); SPListItemCollection itemCollection = RecorderManager.CreateMockedObject <SPListItemCollection>(); using (RecordExpectations recorder = RecorderManager.StartRecording()) { recorder.ExpectAndReturn(web.Lists["Registrations"], list).RepeatAlways(); recorder.ExpectAndReturn(list.Items, itemCollection).RepeatAlways(); recorder.ExpectAndReturn(itemCollection.Count, 2); } return(web); }
private SPListItem RecordGetReturnSPListItem() { SPListItem item = RecorderManager.CreateMockedObject <SPListItem>(); using (RecordExpectations recorder = RecorderManager.StartRecording()) { recorder.ExpectAndReturn(item[new Guid(Fields.Id)], 1); recorder.ExpectAndReturn(item[new Guid(Fields.Title)], "UNITTEST"); recorder.ExpectAndReturn(item[new Guid(Fields.CourseId)], 1); recorder.ExpectAndReturn(item[new Guid(Fields.UserId)], 1); recorder.ExpectAndReturn(item[new Guid(Fields.RegistrationStatus)], "Pending"); } return(item); }
private SPListItem RecordGetReturnSPListItem() { SPListItem item = RecorderManager.CreateMockedObject <SPListItem>(); using (RecordExpectations recorder = RecorderManager.StartRecording()) { recorder.ExpectAndReturn(item[new Guid(Fields.Id)], 1); recorder.ExpectAndReturn(item[new Guid(Fields.Title)], "TestTitle"); recorder.ExpectAndReturn(item[new Guid(Fields.TrainingCourseCode)], "TestCode"); recorder.ExpectAndReturn(item[new Guid(Fields.TrainingCourseDescription)], "TestDescription"); recorder.ExpectAndReturn(item[new Guid(Fields.TrainingCourseEnrollmentDate)], DateTime.Today); recorder.ExpectAndReturn(item[new Guid(Fields.TrainingCourseStartDate)], DateTime.Today.AddDays(1)); recorder.ExpectAndReturn(item[new Guid(Fields.TrainingCourseEndDate)], DateTime.Today.AddDays(2)); recorder.ExpectAndReturn(item[new Guid(Fields.TrainingCourseCost)], 123f); } return(item); }
private SPWeb CreateMockSPWeb(SPWebMockType mockType) { SPWeb web = RecorderManager.CreateMockedObject <SPWeb>(); SPUser user = RecorderManager.CreateMockedObject <SPUser>(); SPUser manager = RecorderManager.CreateMockedObject <SPUser>(); switch (mockType) { case SPWebMockType.UserAndManager: using (RecordExpectations recorder = RecorderManager.StartRecording()) { recorder.ExpectAndReturn(web.SiteUsers.GetByID(1), user); recorder.ExpectAndReturn(user.LoginName, @"domain\alias").RepeatAlways(); recorder.ExpectAndReturn(web.SiteUsers[1], manager); recorder.ExpectAndReturn(manager.LoginName, string.Format(@"{0}\{1}", Environment.MachineName, "spgmanager")); recorder.ExpectAndReturn(user.Name, "TestUser").RepeatAlways(); } break; case SPWebMockType.UserOnly: using (RecordExpectations recorder = RecorderManager.StartRecording()) { recorder.ExpectAndReturn(web.SiteUsers.GetByID(1), user); recorder.ExpectAndReturn(user.LoginName, @"domain\alias").RepeatAlways(); recorder.ExpectAndReturn(user.Name, "TestUser").RepeatAlways(); } break; default: using (RecordExpectations recorder = RecorderManager.StartRecording()) { recorder.ExpectAndReturn(web.SiteUsers.GetByID(1), user); recorder.ExpectAndReturn(user.LoginName, @"domain\alias").RepeatAlways(); recorder.ExpectAndReturn(web.SiteUsers[1], manager); recorder.ExpectAndReturn(manager.LoginName, string.Format(@"{0}\{1}", Environment.MachineName, "spgmanager")); recorder.ExpectAndReturn(user.Name, "TestUser").RepeatAlways(); } break; } return(web); }
private SPWeb CreateMockSPWeb(bool blank) { SPWeb web = RecorderManager.CreateMockedObject <SPWeb>(); using (RecordExpectations recorder = RecorderManager.StartRecording()) { recorder.ExpectAndReturn(web.Url, "http://localhost/training"); } if (!blank) { SPUser user = RecorderManager.CreateMockedObject <SPUser>(); using (RecordExpectations recorder = RecorderManager.StartRecording()) { recorder.ExpectAndReturn(web.SiteUsers[string.Empty], user); recorder.ExpectAndReturn(user.Name, @"domain\alias").RepeatAlways(); recorder.ExpectAndReturn(user.ID, 1).RepeatAlways(); } } return(web); }