private void SetupForUpdateResource(out SPListItem listItem, out DataRow dataRow, string fieldName) { var adFieldMappings = new List <string>() { DummyString }; var adFieldMappingValues = new Hashtable(); var dataTable = CreateDataTable(); listItem = new ShimSPListItem { Update = () => _listItemUpdated = true }.Instance; dataRow = dataTable.NewRow(); dataRow[SIDField] = DummyString; dataRow[TitleField] = DummyString; dataRow[DummyString] = DummyString; dataRow[SharepointAccountField] = DummyString; dataTable.Rows.Add(dataRow); adFieldMappingValues.Add(DummyString, fieldName); _privateObj.SetFieldOrProperty(AdFieldMappingsProperty, adFieldMappings); _privateObj.SetFieldOrProperty(AdFieldMappingValuesProperty, adFieldMappingValues); _privateObj.SetFieldOrProperty(WebProperty, _web.Instance); }
public void WriteValueToListItem_WhenGivenFieldValue_ShouldUpdateFieldValue() { using (ShimsContext.Create()) { // Arrange var setValue = "SomeTitle"; var setField = BuiltInFields.Title; var fakeListItemShim = new ShimSPListItem() { ItemSetStringObject = (internalName, value) => { Assert.AreEqual(setValue, value as string); Assert.AreEqual(setField.InternalName, internalName); } }; IFieldValueWriter writer; SPListItem fakeListItem = fakeListItemShim.Instance; using (var scope = UnitTestServiceLocator.BeginLifetimeScope()) { writer = scope.Resolve <IFieldValueWriter>(); } // Act writer.WriteValueToListItem(fakeListItem, new FieldValueInfo(setField, setValue)); // Assert } }
public void WriteValueToListItem_GivenDateTimeFieldInfo_ShouldUseDateTimeValueWriter() { using (ShimsContext.Create()) { // Arrange var correctWriterWasUsed = false; var fieldInfo = new DateTimeFieldInfo("InternalName", Guid.NewGuid(), string.Empty, string.Empty, string.Empty); ShimDateTimeValueWriter.AllInstances.WriteValueToListItemSPListItemFieldValueInfo = (inst, listItem, fieldValueInfo) => { correctWriterWasUsed = true; }; var fakeListItem = new ShimSPListItem().Instance; IFieldValueWriter writer; using (var scope = UnitTestServiceLocator.BeginLifetimeScope()) { writer = scope.Resolve <IFieldValueWriter>(); } // Act writer.WriteValueToListItem(fakeListItem, new FieldValueInfo(fieldInfo, null)); // Assert Assert.IsTrue(correctWriterWasUsed, "The DateTimeValueWriter should have been used for the DateTimeFieldInfo type."); } }
public void ProcessField_Always_ReturnExpectedValueForDateTime() { // Arrange SPWeb spWeb = new ShimSPWeb { LocaleGet = () => new CultureInfo("en-US") }; SPListItem listItem = new ShimSPListItem { ItemGetGuid = guidValue => "2018-12-05 00:00:00" }; SPField field = new ShimSPField { TypeGet = () => SPFieldType.DateTime, SchemaXmlGet = () => "format=\"DATEONLY\"" }; // Act var result = _privateObject.Invoke( "ProcessField", spWeb, listItem, field) as string; // Assert this.ShouldSatisfyAllConditions( () => result.ShouldNotBeNull(), () => result.ShouldBe("12/5/2018")); }
public void AddColumnValues_ReturnsString() { // Arrange var dataTable = new DataTable(); dataTable.Columns.Add(ColumnName, typeof(string)); dataTable.Columns.Add(InternalName, typeof(string)); var row = dataTable.NewRow(); row[ColumnName] = ItemId; row[InternalName] = InternalName; dataTable.Rows.Add(row); var defColumns = new ArrayList() { ItemId }; var spListItem = new ShimSPListItem(); spListItem.IDGet = () => { return(1); }; var args = new object[] { (SPListItem)spListItem, dataTable, defColumns, new ArrayList(), Insert, string.Empty }; // Act var actual = _privateObj.Invoke(AddColumnValuesMethod, args); // Assert Assert.AreEqual(1, _adoShims.ConnectionsCreated.Count); StringAssert.Contains(actual as string, ValuesSubstring); }
public void ProcessField_Always_ReturnExpectedValueForNumber() { // Arrange SPWeb spWeb = new ShimSPWeb { LocaleGet = () => new CultureInfo("en-US") }; SPListItem listItem = new ShimSPListItem { ItemGetGuid = guidValue => "1" }; SPField field = new ShimSPFieldNumber { ShowAsPercentageGet = () => true }; new ShimSPField(field) { TypeGet = () => SPFieldType.Number }; // Act var result = _privateObject.Invoke( "ProcessField", spWeb, listItem, field) as string; // Assert this.ShouldSatisfyAllConditions( () => result.ShouldNotBeNull(), () => result.ShouldBe("100%")); }
public void UpdateResource_OnError_LogError() { // Arrange var adFieldMappings = new List <string>() { DummyString }; var listItem = new ShimSPListItem { ItemGetString = _ => DummyString, Update = () => { } }; var dataTable = CreateDataTable(); var dataRow = dataTable.NewRow(); dataRow[SIDField] = DummyString; dataTable.Rows.Add(dataRow); _privateObj.SetFieldOrProperty(AdFieldMappingsProperty, adFieldMappings); // Act _privateObj.Invoke(UpdateResourceMethod, listItem.Instance, dataRow); // Assert var executionLogs = (List <string>)_privateObj.GetFieldOrProperty(ExecutionLogsProperty); var hasErrors = (bool)_privateObj.GetFieldOrProperty(HasErrorsProperty); this.ShouldSatisfyAllConditions( () => hasErrors.ShouldBeTrue(), () => executionLogs[0].ShouldContain($" ERROR -- Location: UpdateResource() -- SID: {DummyString} SPField: ADField: -- Message:")); }
public SPListItemEnumerator() { sPListItems[0] = new ShimSPListItem() { ItemGetGuid = (guid) => { return(Guid.NewGuid()); }, IDGet = () => { return(1); }, TitleGet = () => { return("Adam Bar"); } }; sPListItems[1] = new ShimSPListItem() { ItemGetGuid = (guid) => { return(Guid.NewGuid()); }, IDGet = () => { return(2); }, TitleGet = () => { return("Brandon Baker"); } }; }
public void WriteValuesToListItem_WhenGivenNullUrl_ShouldCopyNullUrl() { using (ShimsContext.Create()) { // Arrange var expectedField = new UrlFieldInfo("InternalName", Guid.NewGuid(), null, null, null); var actualUrlValue = new SPFieldUrlValue(); var fakeListItemShim = new ShimSPListItem() { ItemSetStringObject = (internalName, value) => { actualUrlValue = value as SPFieldUrlValue; } }; IFieldValueWriter writer; var fakeListItem = fakeListItemShim.Instance; using (var scope = UnitTestServiceLocator.BeginLifetimeScope()) { writer = scope.Resolve<IFieldValueWriter>(); } // Act writer.WriteValueToListItem(fakeListItem, new FieldValueInfo(expectedField, null)); // Assert Assert.IsNull(actualUrlValue); } }
private void SetupVariables() { guid = new Guid(GuidString); spList = new ShimSPList() { FieldsGet = () => new ShimSPFieldCollection(), ItemsGet = () => new ShimSPListItemCollection() }; spListItem = new ShimSPListItem() { IDGet = () => DummyNumber, UniqueIdGet = () => guid }; spListCollection = new ShimSPListCollection() { ItemGetString = _ => spList }; spSite = new ShimSPSite() { IDGet = () => guid }; spWeb = new ShimSPWeb() { ListsGet = () => spListCollection, UrlGet = () => DummyString, SiteGet = () => spSite, CurrentUserGet = () => new ShimSPUser() { RegionalSettingsGet = () => null } }; }
public void WriteValuesToListItem_WhenGivenNullUrl_ShouldCopyNullUrl() { using (ShimsContext.Create()) { // Arrange var expectedField = new UrlFieldInfo("InternalName", Guid.NewGuid(), null, null, null); var actualUrlValue = new SPFieldUrlValue(); var fakeListItemShim = new ShimSPListItem() { ItemSetStringObject = (internalName, value) => { actualUrlValue = value as SPFieldUrlValue; } }; IFieldValueWriter writer; var fakeListItem = fakeListItemShim.Instance; using (var scope = UnitTestServiceLocator.BeginLifetimeScope()) { writer = scope.Resolve <IFieldValueWriter>(); } // Act writer.WriteValueToListItem(fakeListItem, new FieldValueInfo(expectedField, null)); // Assert Assert.IsNull(actualUrlValue); } }
public void ProcessProjectSummaryItem_WithParams_ExecutesCorrectly() { // Arrange const string ExpectedRiskStatus = "<img src=\"/_layouts/images/green.gif\">"; const string ExpectedIssueStatus = "<img src=\"/_layouts/images/green.gif\">"; const string ExpectedScheduleStatus = "<img src=\"/_layouts/images/red.gif\">"; var title = string.Empty; var startDate = string.Empty; var finishDate = string.Empty; var porcentCompleted = string.Empty; var scheduleStatus = string.Empty; var rowValues = new object[] { }; var listItem = new ShimSPListItem { TitleGet = () => " Title", IDGet = () => 1, ItemGetString = GetValue(new Hashtable { ["Start"] = DateTime.Now, ["Finish"] = DateTime.Now, ["PercentComplete"] = 1, ["Status"] = "Late", ["Projects"] = "Late" }) }.Instance; var site = new ShimSPWeb { UrlGet = () => "Url" }.Instance; var dataTable = new DataTable(); privateObject.SetFieldOrProperty("site", site); privateObject.SetFieldOrProperty("dt", dataTable); ShimDashboard.AllInstances.getTaskCountString = (_, name) => 1; ShimDataRowCollection.AllInstances.AddObjectArray = (_, parameters) => { rowValues = parameters; return(null); }; ShimDashboard.AllInstances.getRiskStatusString = (_, name) => "green"; ShimDashboard.AllInstances.getIssueStatusString = (_, name) => "green"; // Act privateObject.Invoke(ProcessProjectSummaryItemMethodName, listItem); // Assert rowValues.ShouldSatisfyAllConditions( () => rowValues.Count().ShouldBe(8), () => rowValues[1].ShouldBe(DateTime.Now.ToShortDateString()), () => rowValues[2].ShouldBe(DateTime.Now.ToShortDateString()), () => rowValues[3].ShouldBe("100%"), () => rowValues[4].ShouldBe("1"), () => rowValues[5].ShouldBe(ExpectedScheduleStatus), () => rowValues[6].ShouldBe(ExpectedIssueStatus), () => rowValues[7].ShouldBe(ExpectedRiskStatus)); }
public void ShouldReloadListItemOnRequest() { var webId = Guid.NewGuid(); var listId = Guid.NewGuid(); const int ItemId = 1; var siteMock = new ShimSPSite(); var listItemMock = new ShimSPListItem { IDGet = () => ItemId }; var listItemMockNew = new ShimSPListItem { IDGet = () => ItemId }; var listItemCollection = new ShimSPListItemCollection { GetEnumerator = () => Enumerable.Repeat <SPListItem>(listItemMock, 1).GetEnumerator() }; var listMock = new ShimSPList { GetItemsSPQuery = _ => listItemCollection, IDGet = () => listId, GetItemByIdInt32 = _ => listItemMockNew }; var listCollection = new ShimSPListCollection { ItemGetGuid = _ => listMock }; const string TestUrl = "test/url"; var webMock = new ShimSPWeb { ServerRelativeUrlGet = () => TestUrl, ListsGet = () => listCollection }; siteMock.OpenWebGuid = guid => webMock; using (var cache = SaveDataJobExecuteCache.InitializeCache(siteMock)) { string preloadErrors; var preloadHasErrors = cache.PreloadListItems(new[] { new SaveDataJobExecuteCache.ListItemInfo { WebId = webId.ToString(), ListId = listId.ToString(), ListItemId = ItemId.ToString() } }, out preloadErrors); preloadHasErrors.ShouldBe(false); preloadErrors.ShouldBe(string.Empty); var listItem = SaveDataJobExecuteCache.Cache.GetListItem(TestUrl, listId, ItemId, refresh: true); listItem.ShouldBe(listItemMockNew); listItem = SaveDataJobExecuteCache.Cache.GetListItem(TestUrl, listId, ItemId); listItem.ShouldBe(listItemMockNew); } }
public void ShouldReturnListItemFromPropertiesIfListIsNotInCache() { var webId = Guid.NewGuid(); var listId = Guid.NewGuid(); var list2Id = Guid.NewGuid(); const int ItemId = 1; var siteMock = new ShimSPSite(); var listMock = new ShimSPList { GetItemsSPQuery = _ => new ShimSPListItemCollection { GetEnumerator = () => Enumerable.Empty <SPListItem>().GetEnumerator() }, IDGet = () => listId }; var listCollection = new ShimSPListCollection { ItemGetGuid = _ => listMock }; const string TestUrl = "test/url"; var webMock = new ShimSPWeb { ServerRelativeUrlGet = () => TestUrl, ListsGet = () => listCollection }; siteMock.OpenWebGuid = guid => webMock; using (var cache = SaveDataJobExecuteCache.InitializeCache(siteMock)) { string preloadErrors; var preloadHasErrors = cache.PreloadListItems(new[] { new SaveDataJobExecuteCache.ListItemInfo { WebId = webId.ToString(), ListId = listId.ToString(), ListItemId = ItemId.ToString() } }, out preloadErrors); preloadHasErrors.ShouldBe(false); preloadErrors.ShouldBe(string.Empty); var listItemMock = new ShimSPListItem(); var properties = new ShimSPItemEventProperties { RelativeWebUrlGet = () => TestUrl, ListIdGet = () => list2Id, ListItemIdGet = () => ItemId, ListItemGet = () => listItemMock }; var listItem = SaveDataJobExecuteCache.GetListItem(properties); listItem.ShouldBe(listItemMock); } }
public void SetUp() { _shimsContext = ShimsContext.Create(); _resourceUrl = "http://test.test"; _webServerRelativeUrl = "http://test.test"; _resourcePlanListsString = "1,2,3"; _siteId = Guid.NewGuid(); _hours = 1; _workdays = "1"; _listItemShim = new ShimSPListItem { ItemGetGuid = id => new object() }; var listItemCollection = new ShimSPListItemCollection(); var webList = new ShimSPList { GetItemsSPQuery = query => { return(listItemCollection.Bind(new[] { _listItemShim.Instance })); }, FieldsGet = () => new ShimSPFieldCollection { GetFieldByInternalNameString = name => new ShimSPField() } }; var webListCollectionShim = new ShimSPListCollection { ItemGetString = (name) => webList.Instance }; _webShim = new ShimSPWeb { ServerRelativeUrlGet = () => _webServerRelativeUrl, ListsGet = () => webListCollectionShim.Instance }; ShimSPFieldLookupValue.ConstructorString = (element, name) => new ShimSPFieldLookupValue(); _spFieldUserValues = new List <SPFieldUserValue> { new SPFieldUserValue(_webShim.Instance, "1"), new SPFieldUserValue(_webShim.Instance, "2"), }; // (CC-76656, 2018-07-18) Sadly, can not shim SPFieldUserValueCollection constructor to be able to contain elements, due to SP limitations // Therefore, can not test ResourceInfo generation }
public void ShouldReturnListItemFromPropertiesIfNoCache() { var listItemMock = new ShimSPListItem(); var properties = new ShimSPItemEventProperties { ListItemGet = () => listItemMock }; var listItem = SaveDataJobExecuteCache.GetListItem(properties); listItem.ShouldBe(listItemMock); }
public void ProcessProjectSummaryItem2_Should_AddRowInDataTable() { // Arrange var dataTableProjectData = new DataTable(); dataTableProjectData.Columns.Add("name"); dataTableProjectData.Columns.Add("pctcomplete"); dataTableProjectData.Columns.Add("latetasks"); dataTableProjectData.Columns.Add("schedulestatus"); dataTableProjectData.Columns.Add("issuestatus"); dataTableProjectData.Columns.Add("riskstatus"); _privateObject.SetField(DataTableProjectDataFieldName, dataTableProjectData); var listItem = new ShimSPListItem() { ItemGetString = itemName => { switch (itemName) { case "Start": return(DummyDateTimeString); case "Finish": return(DummyDateTimeString); case "PercentComplete": return("1"); case "Status": return("Late"); default: break; } throw new Exception(); } }; // Act _privateObject.Invoke(ProcessProjectSummaryItem2MethodName, listItem.Instance); // Assert this.ShouldSatisfyAllConditions( () => dataTableProjectData.Rows.Count.ShouldBe(1), () => dataTableProjectData.Rows[0].ItemArray.Length.ShouldBe(6), () => dataTableProjectData.Rows[0][0].ShouldBe("<a href=\"/Lists/Project%20Center/DispForm.aspx?ID=0\"></a>"), () => dataTableProjectData.Rows[0][1].ShouldBe("100%"), () => dataTableProjectData.Rows[0][2].ShouldBe(string.Empty), () => dataTableProjectData.Rows[0][3].ShouldBe("<img src=\"/_layouts/images/red.gif\">"), () => dataTableProjectData.Rows[0][4].ShouldBe("<img src=\"/_layouts/images/.gif\">"), () => dataTableProjectData.Rows[0][5].ShouldBe("<img src=\"/_layouts/images/.gif\">")); }
private void SetupShim() { ShimMyWorkListEvents.AllInstances.DeleteItem = (_) => { return(true); }; ShimMyWorkListEvents.AllInstances.LogEventExceptionInt32String = (_, __, ___, ____) => { }; ShimReportData.AllInstances.GetTableNameGuid = (_, __) => { return(DummyString); }; ShimReportData.AllInstances.ListReportsWorkString = (_, __) => { return(true); }; ShimReportData.AllInstances.DeleteWorkGuidInt32 = (_, __, ___) => { return(true); }; ShimReportData.AllInstances.Dispose = (_) => { _disposeWasCalled = true; }; ShimSPEventPropertiesBase.AllInstances.StatusSetSPEventReceiverStatus = (_, __) => { _CancelledCalled = true; }; ShimSPEventPropertiesBase.AllInstances.ErrorMessageSetString = (_, __string) => { _ErrorMessage = __string; }; ShimSPItemEventProperties.AllInstances.BeforePropertiesGet = (_) => { return(new ShimSPItemEventDataCollection() { ItemGetString = (_1) => { return DummyString; }, }); }; var properties = CreateSPItemEventProperties(); var _listItem = new ShimSPListItem { ParentListGet = () => { return(new ShimSPList() { IDGet = () => Guid.Empty }); } }; _privateObject.SetFieldOrProperty("_listItem", _listItem.Instance); _privateObject.SetFieldOrProperty("_myWorkReportData", new ShimMyWorkReportData().Instance); _privateObject.SetFieldOrProperty("_properties", properties.Instance); }
public void ProcessPeriods_Should_ExecuteCorrectly() { // Arrange privateObject.SetFieldOrProperty("arrPeriods", new ArrayList { CreatePeriodItemObject(new Dictionary <string, object> { ["name"] = DummyString, ["start"] = DummyString, ["finish"] = DummyString, ["capacity"] = "1", }) }); var dataRow = new object[DataRowLength]; var rowAdded = new object[] { }; var listItem = new ShimSPListItem { ItemGetGuid = guid => DummyString, FieldsGet = () => new ShimSPFieldCollection { GetFieldByInternalNameString = internalName => new ShimSPField { IdGet = () => Guid.NewGuid() } } }.Instance; privateObject.SetFieldOrProperty("arrResOC", new ArrayList { DummyString }); ShimDataRowCollection.AllInstances.AddObjectArray = (_, row) => { rowAdded = row; return(new ShimDataRow()); }; // Act privateObject.Invoke(ProcessPeriodsMethodName, listItem, dataRow); // Assert rowAdded.ShouldSatisfyAllConditions( () => rowAdded.ShouldNotBeNull(), () => rowAdded.ShouldBe(dataRow)); }
private void SetupVariables() { validations = 0; publicInstance = BindingFlags.Instance | BindingFlags.Public; nonPublicInstance = BindingFlags.Instance | BindingFlags.NonPublic; guid = Guid.Parse(SampleGuidString1); spWeb = new ShimSPWeb() { IDGet = () => guid, ListsGet = () => spListCollection, AllowUnsafeUpdatesSetBoolean = _ => { }, AllUsersGet = () => new ShimSPUserCollection(), SiteGroupsGet = () => new ShimSPGroupCollection(), RoleDefinitionsGet = () => new ShimSPRoleDefinitionCollection() }; spSite = new ShimSPSite() { IDGet = () => guid }; spListCollection = new ShimSPListCollection() { ItemGetGuid = _ => spList }; spList = new ShimSPList() { IDGet = () => guid, FieldsGet = () => spFieldCollection, GetItemByIdInt32 = _ => spListItem }; spListItemCollection = new ShimSPListItemCollection(); spListItem = new ShimSPListItem() { IDGet = () => DummyInt, TitleGet = () => DummyString, ItemGetString = _ => DummyString }; spFieldCollection = new ShimSPFieldCollection(); spField = new ShimSPField(); spUser = new ShimSPUser(); dataReader = new ShimSqlDataReader() { Close = () => { } }; }
public void AddMetaInfoCols_CreatesParameters() { // Arrange int count = 0; ShimSqlParameterCollection parameters = new ShimSqlParameterCollection(); parameters.AddSqlParameter = (_) => { count++; return(_); }; ShimSqlCommand.AllInstances.ParametersGet = (_) => { return(parameters); }; var spListItem = new ShimSPListItem(); var args = new object[] { ListItem, (SPListItem)spListItem, Columns, Values }; // Act _privateObj.Invoke(AddMetaInfoColsMethod, args); // Assert Assert.AreEqual(1, _adoShims.ConnectionsCreated.Count); Assert.AreEqual(2, count); }
public void WriteValuesToListItem_WhenGivenValueAndDescription_ShouldCopyValueAndDescription() { using (ShimsContext.Create()) { // Arrange var actualFieldName = string.Empty; var expectedField = new UrlFieldInfo("InternalName", Guid.NewGuid(), null, null, null); var actualUrlValue = new SPFieldUrlValue(); var expectedUrlValue = new UrlValue() { Description = "Awesome sauce description!", Url = "http://www.gsoft.com/team" }; var fakeListItemShim = new ShimSPListItem() { ItemSetStringObject = (internalName, value) => { actualUrlValue = value as SPFieldUrlValue; actualFieldName = internalName; } }; IFieldValueWriter writer; var fakeListItem = fakeListItemShim.Instance; using (var scope = UnitTestServiceLocator.BeginLifetimeScope()) { writer = scope.Resolve<IFieldValueWriter>(); } // Act writer.WriteValueToListItem(fakeListItem, new FieldValueInfo(expectedField, expectedUrlValue)); // Assert Assert.AreEqual(expectedUrlValue.Url, actualUrlValue.Url); Assert.AreEqual(expectedUrlValue.Description, actualUrlValue.Description); Assert.AreEqual(expectedField.InternalName, actualFieldName); } }
public void WriteValuesToListItem_WhenGivenValueAndDescription_ShouldCopyValueAndDescription() { using (ShimsContext.Create()) { // Arrange var actualFieldName = string.Empty; var expectedField = new UrlFieldInfo("InternalName", Guid.NewGuid(), null, null, null); var actualUrlValue = new SPFieldUrlValue(); var expectedUrlValue = new UrlValue() { Description = "Awesome sauce description!", Url = "http://www.gsoft.com/team" }; var fakeListItemShim = new ShimSPListItem() { ItemSetStringObject = (internalName, value) => { actualUrlValue = value as SPFieldUrlValue; actualFieldName = internalName; } }; IFieldValueWriter writer; var fakeListItem = fakeListItemShim.Instance; using (var scope = UnitTestServiceLocator.BeginLifetimeScope()) { writer = scope.Resolve <IFieldValueWriter>(); } // Act writer.WriteValueToListItem(fakeListItem, new FieldValueInfo(expectedField, expectedUrlValue)); // Assert Assert.AreEqual(expectedUrlValue.Url, actualUrlValue.Url); Assert.AreEqual(expectedUrlValue.Description, actualUrlValue.Description); Assert.AreEqual(expectedField.InternalName, actualFieldName); } }
public void WriteValuesToListItem_WhenGiven5FieldValues_ShouldCallWriteValueToListItem5Times() { using (ShimsContext.Create()) { // Arrange var actualCallCount = 0; var expectedCallCount = 5; var fieldValueInfos = new List<FieldValueInfo>() { new FieldValueInfo(BuiltInFields.Title, null), new FieldValueInfo(BuiltInFields.Title, null), new FieldValueInfo(BuiltInFields.Title, null), new FieldValueInfo(BuiltInFields.Title, null), new FieldValueInfo(BuiltInFields.Title, null) }; ShimFieldValueWriter.AllInstances.WriteValueToListItemSPListItemFieldValueInfo = (writerInst, listItemParam, fieldValuesParam) => { actualCallCount++; }; var fakeListItem = new ShimSPListItem().Instance; IFieldValueWriter writer; using (var scope = UnitTestServiceLocator.BeginLifetimeScope()) { writer = scope.Resolve<IFieldValueWriter>(); } // Act writer.WriteValuesToListItem(fakeListItem, fieldValueInfos); // Assert Assert.AreEqual(expectedCallCount, actualCallCount, string.Format("The call was made {0} out of {1} times.", actualCallCount, expectedCallCount)); } }
public void WriteValuesToListItem_WhenGiven5FieldValues_ShouldCallWriteValueToListItem5Times() { using (ShimsContext.Create()) { // Arrange var actualCallCount = 0; var expectedCallCount = 5; var fieldValueInfos = new List <FieldValueInfo>() { new FieldValueInfo(BuiltInFields.Title, null), new FieldValueInfo(BuiltInFields.Title, null), new FieldValueInfo(BuiltInFields.Title, null), new FieldValueInfo(BuiltInFields.Title, null), new FieldValueInfo(BuiltInFields.Title, null) }; ShimFieldValueWriter.AllInstances.WriteValueToListItemSPListItemFieldValueInfo = (writerInst, listItemParam, fieldValuesParam) => { actualCallCount++; }; var fakeListItem = new ShimSPListItem().Instance; IFieldValueWriter writer; using (var scope = UnitTestServiceLocator.BeginLifetimeScope()) { writer = scope.Resolve <IFieldValueWriter>(); } // Act writer.WriteValuesToListItem(fakeListItem, fieldValueInfos); // Assert Assert.AreEqual(expectedCallCount, actualCallCount, string.Format("The call was made {0} out of {1} times.", actualCallCount, expectedCallCount)); } }
private void SetupShims() { _configJob = new ShimUninstall().Instance; _privateConfigJob = new PrivateObject(_configJob); _privateConfigJob.SetFieldOrProperty(UserIdField, DummyInt); var spUser = new ShimSPUser { UserTokenGet = () => new ShimSPUserToken(), IsSiteAdminGet = () => true }; var spListItem = new ShimSPListItem { ParentListGet = () => _list, IDGet = () => DummyInt, TitleGet = () => DummyString, ItemGetString = item => { switch (item) { case "LinkedCommunity": case "QuickLaunch": case "TopNav": return(DummyInt); case "InstalledFiles": return($@"<Files> <Folder Type='Folder' FullFile='{Folder1}/' Name='{Folder1}'></Folder> <Folder Type='Folder' FullFile='{Folder2}' Name='{Folder2}'> <File Type='File' FullFile='{File1}' Name='{File1}'></File> </Folder> <Folder Type='Folder' FullFile='{Folder3}/File' Name='{Folder3}'></Folder> <Folder Type='Folder' FullFile='{Folder4}' Name='{Folder4}' NoDelete='true'></Folder> </Files>"); default: return(DummyString); } }, Update = () => _listItemUpdated = true, Delete = () => _listItemDeleted = true, Recycle = () => { _listItemRecycled = true; return(Guid.NewGuid()); } }; _list = new ShimSPList { IDGet = () => Guid.NewGuid(), GetItemsSPQuery = _ => new ShimSPListItemCollection { CountGet = () => DummyInt, ItemGetInt32 = __ => spListItem }.Bind(new SPListItem[] { spListItem }), ParentWebGet = () => _web, Delete = () => _listDeleted = true, FieldsGet = () => new ShimSPFieldCollection { GetFieldByInternalNameString = _ => new ShimSPField { SealedGet = () => true, Update = () => _fieldUpdated = true, Delete = () => _fieldDeleted = true } }, ViewsGet = () => new ShimSPViewCollection { ItemGetString = _ => new ShimSPView(), DeleteGuid = _ => _viewDeleted = true }, EventReceiversGet = () => new ShimSPEventReceiverDefinitionCollection().Bind(new SPEventReceiverDefinition[] { new ShimSPEventReceiverDefinition { TypeGet = () => SPEventReceiverType.AppInstalled, AssemblyGet = () => DummyString, ClassGet = () => DummyString, Delete = () => _eventHandlerDeleted = true } }) }; _web = new ShimSPWeb { IDGet = () => new Guid(WebId), SiteGet = () => _site.Instance, CurrentUserGet = () => spUser, AllUsersGet = () => new ShimSPUserCollection { GetByIDInt32 = _ => spUser }, ListsGet = () => new ShimSPListCollection { TryGetListString = item => { if (item == File1) { return(null); } return(_list); } }, FilesGet = () => new ShimSPFileCollection { DeleteString = _ => _webFileDeleted = true }, NavigationGet = () => new ShimSPNavigation { QuickLaunchGet = () => new ShimSPNavigationNodeCollection { DeleteSPNavigationNode = _ => _quickLaunchDeleted = true }.Bind(new SPNavigationNode[] { new ShimSPNavigationNode { IdGet = () => DummyInt, TitleGet = () => DummyString } }), TopNavigationBarGet = () => new ShimSPNavigationNodeCollection { DeleteSPNavigationNode = _ => _topNavigationBarDeleted = true }.Bind(new SPNavigationNode[] { new ShimSPNavigationNode { IdGet = () => DummyInt, TitleGet = () => DummyString }, new ShimSPNavigationNode { IdGet = () => DummyInt + 1, TitleGet = () => $"{DummyString}1", ChildrenGet = () => new ShimSPNavigationNodeCollection { DeleteSPNavigationNode = _ => { } }.Bind(new SPNavigationNode[] { new ShimSPNavigationNode { IdGet = () => DummyInt, TitleGet = () => DummyString } }) } }) }, GetFolderString = _ => new ShimSPFolder { ExistsGet = () => true, Delete = () => _folderDeleted = true }, FeaturesGet = () => new ShimSPFeatureCollection { RemoveGuid = _ => _webFeatureRemoved = true }, GetFileString = _ => new ShimSPFile { ExistsGet = () => true, Delete = () => _fileDeleted = true } }; _site = new ShimSPSite { IDGet = () => Guid.NewGuid(), GetCatalogSPListTemplateType = _ => new ShimSPDocumentLibrary(), SolutionsGet = () => new ShimSPUserSolutionCollection { RemoveSPUserSolution = _ => _solutionDeleted = true }.Bind(new SPUserSolution[] { new ShimSPUserSolution { NameGet = () => DummyString } }), FeaturesGet = () => new ShimSPFeatureCollection { RemoveGuid = _ => _siteFeatureRemoved = true } }; ShimSPList.AllInstances.RootFolderGet = _ => new ShimSPFolder { FilesGet = () => new ShimSPFileCollection().Bind(new SPFile[] { new ShimSPFile { NameGet = () => DummyString, Delete = () => _listFileDeleted = true } }) }; ShimSPSite.ConstructorGuid = (_, __) => { }; ShimSPSite.ConstructorGuidSPUserToken = (_, __, ___) => { }; ShimSPSite.AllInstances.OpenWeb = _ => _web.Instance; ShimSPSite.AllInstances.OpenWebGuid = (_, __) => _web; ShimSPSite.AllInstances.WebApplicationGet = _ => new ShimSPWebApplication(); ShimSPSite.AllInstances.FeatureDefinitionsGet = _ => new ShimSPFeatureDefinitionCollection().Bind(new SPFeatureDefinition[] { new ShimSPFeatureDefinition { IdGet = () => new Guid(Feature1Guid), DisplayNameGet = () => DummyString, CompatibilityLevelGet = () => 14, ScopeGet = () => SPFeatureScope.Site }, new ShimSPFeatureDefinition { IdGet = () => new Guid(Feature2Guid), DisplayNameGet = () => DummyString, CompatibilityLevelGet = () => 15, ScopeGet = () => SPFeatureScope.Site } }); ShimSPSite.AllInstances.Dispose = _ => { }; ShimSPWeb.AllInstances.Dispose = _ => { }; ShimSPPersistedObject.AllInstances.FarmGet = _ => new ShimSPFarm { FeatureDefinitionsGet = () => new ShimSPFeatureDefinitionCollection().Bind(new SPFeatureDefinition[] { new ShimSPFeatureDefinition { IdGet = () => new Guid(Feature3Guid), DisplayNameGet = () => DummyString, CompatibilityLevelGet = () => 14, ScopeGet = () => SPFeatureScope.Web }, new ShimSPFeatureDefinition { IdGet = () => new Guid(Feature4Guid), DisplayNameGet = () => DummyString, CompatibilityLevelGet = () => 15, ScopeGet = () => SPFeatureScope.Web } }) }; ShimSPSiteDataQuery.Constructor = _ => { }; ShimSPQuery.Constructor = _ => { }; ShimApplications.RemoveAppFromCommunitySPListItemInt32 = (_, __) => _appRemovedFromCommunity = true; ShimApplications.DeleteCommunityInt32SPWeb = (_, __) => _communityDeleted = true; ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = action => action(); ShimReportBiz.ConstructorGuid = (_, __) => { }; ShimReportBiz.AllInstances.GetReferencingTablesEPMDataString = (_, __, ___) => new DataTable(); ShimReportBiz.AllInstances.GetListBizGuid = (_, __) => new ShimListBiz { Delete = () => _listBizDeleted = true }; ShimEPMData.ConstructorGuid = (_, __) => { }; ShimEPMData.AllInstances.ExecuteScalarSqlConnection = (_, __) => DummyString; ShimEPMData.AllInstances.AddParamStringObject = (_, __, ___) => { }; ShimCoreFunctions.getLockConfigSettingSPWebStringBoolean = (_, __, ___) => DummyString; ShimCoreFunctions.getLockedWebSPWeb = _ => Guid.NewGuid(); ShimCoreFunctions.setConfigSettingSPWebStringString = (_, __, ___) => _configSettingSet = true; ShimCoreFunctions.getListSettingStringSPList = (_, __) => $"{DummyString}1"; ShimCoreFunctions.iGetListEventTypeString = _ => SPEventReceiverType.AppInstalled; ShimGridGanttSettings.AllInstances.SaveSettingsSPList = (_, __) => _gridGanttSettingsSaved = true; ShimPath.GetDirectoryNameString = _ => DummyString; ShimPath.GetExtensionString = fileName => { if (fileName == Folder1) { return(DummyString); } return(string.Empty); }; }
private void TestConcecutiveNodes(int rowCount) { // Arrange var queueAllItems = new Queue(); SPListItem[] sPListItems = new SPListItem[2]; sPListItems[0] = new ShimSPListItem() { ItemGetGuid = (guid) => { return(Guid.NewGuid()); }, IDGet = () => { return(0); }, TitleGet = () => { return(Name); }, ItemGetString = (a) => { return(string.Empty); } }; sPListItems[1] = new ShimSPListItem() { ItemGetGuid = (guid) => { return(Guid.NewGuid()); }, IDGet = () => { return(1); }, TitleGet = () => { return(Name + "1"); }, ItemGetString = (a) => { return(string.Empty); } }; _userIndex = 0; queueAllItems.Enqueue(sPListItems[0]); queueAllItems.Enqueue(sPListItems[1]); var actualResNodes = _privateObject.GetFieldOrProperty(hshResNodesProperty) as Hashtable; var actualItemNodes = _privateObject.GetFieldOrProperty(hshItemNodesProperty) as Hashtable; var actual = GetXML(queueAllItems, rowCount); // Assert Assert.IsNotNull(actualResNodes); Assert.AreEqual(2, actualResNodes.Count); Assert.IsNotNull(actualItemNodes); Assert.AreEqual(3, actualItemNodes.Count); var firstIndex = actual.IndexOf("cell>project</cell>"); var lastIndex = actual.LastIndexOf("cell>project</cell>"); Assert.IsTrue(firstIndex > 0); Assert.IsTrue(lastIndex > 0); Assert.IsTrue(lastIndex > firstIndex); }
private void SetupVariables() { guid = new Guid(GuidString); spSite = new ShimSPSite() { IDGet = () => guid, UrlGet = () => Url, ContentDatabaseGet = () => new ShimSPContentDatabase(), OpenWebGuid = _ => spWeb }; fields = new ShimSPFieldCollection() { ContainsFieldString = _1 => true }; spListItem = new ShimSPListItem() { IDGet = () => 1, FieldsGet = () => fields, ItemGetString = _1 => DummyString }; spList = new ShimSPList() { IDGet = () => guid, TitleGet = () => Title, GetItemsSPQuery = _ => new ShimSPListItemCollection() { FieldsGet = () => fields, GetEnumerator = () => new List <SPListItem>() { spListItem }.GetEnumerator() }, GetItemByIdInt32 = _ => spListItem }; var currentUser = new ShimSPUser() { IDGet = () => 1, LoginNameGet = () => DummyString, RegionalSettingsGet = () => new ShimSPRegionalSettings() }; spWeb = new ShimSPWeb() { CurrentUserGet = () => currentUser, SiteGet = () => spSite, TitleGet = () => Title, ServerRelativeUrlGet = () => ServerRelativeUrl, ListsGet = () => new ShimSPListCollection() { ItemGetString = _ => spList, ItemGetGuid = _ => spList, TryGetListString = _ => spList }, UrlGet = () => Url }; webApplication = new ShimSPWebApplication(); }
private void SetupVariables() { validations = 0; publicStatic = BindingFlags.Static | BindingFlags.Public; nonPublicStatic = BindingFlags.Static | BindingFlags.NonPublic; publicInstance = BindingFlags.Instance | BindingFlags.Public; nonPublicInstance = BindingFlags.Instance | BindingFlags.NonPublic; guid = Guid.Parse(SampleGuidString1); request = new Dictionary <string, string>() { ["period"] = DummyString, ["action"] = DummyString, ["duser"] = DummyString, ["ts_uids"] = DummyString, ["tsitemuids"] = DummyString }; currentDate = DateTime.Now; spWeb = new ShimSPWeb() { IDGet = () => guid, SiteGet = () => spSite, ListsGet = () => spListCollection, GetFolderString = _ => spFolder, GetFileString = _ => spFile, FoldersGet = () => spFolderCollection, CurrentUserGet = () => spUser, ServerRelativeUrlGet = () => SampleUrl, AllUsersGet = () => new ShimSPUserCollection(), SiteUsersGet = () => new ShimSPUserCollection(), TitleGet = () => DummyString }; spSite = new ShimSPSite() { IDGet = () => guid, WebApplicationGet = () => new ShimSPWebApplication(), RootWebGet = () => spWeb, FeaturesGet = () => new ShimSPFeatureCollection() { ItemGetGuid = _ => new ShimSPFeature() }, ContentDatabaseGet = () => new ShimSPContentDatabase() }; spListCollection = new ShimSPListCollection() { TryGetListString = _ => spList, ItemGetString = _ => spList, ItemGetGuid = _ => spList }; spList = new ShimSPList() { IDGet = () => guid, FieldsGet = () => spFieldCollection, GetItemByIdInt32 = _ => spListItem, ItemsGet = () => spListItemCollection, GetItemsSPQuery = _ => spListItemCollection, RootFolderGet = () => spFolder, ParentWebGet = () => spWeb, DefaultViewGet = () => spView, ViewsGet = () => spViewCollection, ContentTypesGet = () => spContentTypeCollection, TitleGet = () => DummyString, EventReceiversGet = () => new ShimSPEventReceiverDefinitionCollection(), DefaultViewUrlGet = () => SampleUrl }; spListItemCollection = new ShimSPListItemCollection() { CountGet = () => DummyInt, ItemGetInt32 = _ => spListItem }; spListItem = new ShimSPListItem() { IDGet = () => DummyInt, TitleGet = () => DummyString, ItemGetString = _ => DummyString, ItemGetGuid = _ => DummyString, ItemSetGuidObject = (_, __) => { }, Update = () => { }, FileGet = () => spFile, ParentListGet = () => spList, NameGet = () => DummyString }; spFieldCollection = new ShimSPFieldCollection() { GetFieldByInternalNameString = _ => spField, ContainsFieldString = _ => false, GetFieldString = _ => spField, ItemGetString = _ => spField }; spField = new ShimSPField() { IdGet = () => guid, TitleGet = () => DummyString, InternalNameGet = () => DummyString, ReadOnlyFieldGet = () => false, HiddenGet = () => false, ReorderableGet = () => true, TypeAsStringGet = () => DummyString }; spUser = new ShimSPUser() { IDGet = () => DummyInt, IsSiteAdminGet = () => true, UserTokenGet = () => new ShimSPUserToken(), EmailGet = () => DummyString }; spFolderCollection = new ShimSPFolderCollection() { ItemGetString = _ => spFolder, AddString = _ => spFolder }; spFolder = new ShimSPFolder() { ExistsGet = () => false, SubFoldersGet = () => spFolderCollection, FilesGet = () => spFileCollection, UrlGet = () => SampleUrl, UniqueIdGet = () => guid, ParentWebGet = () => spWeb }; spFileCollection = new ShimSPFileCollection() { CountGet = () => DummyInt, AddStringByteArrayBoolean = (_1, _2, _3) => spFile, AddStringStream = (_1, _2) => spFile, ItemGetString = _ => spFile }; spFile = new ShimSPFile() { Delete = () => { }, OpenBinaryStream = () => null, NameGet = () => DummyString, GetListItemStringArray = _ => spListItem }; spViewCollection = new ShimSPViewCollection() { ItemGetString = _ => spView }; spView = new ShimSPView() { ViewFieldsGet = () => spViewFieldCollection, ServerRelativeUrlGet = () => SampleUrl }; spViewFieldCollection = new ShimSPViewFieldCollection(); spContentTypeCollection = new ShimSPContentTypeCollection() { ItemGetString = _ => spContentType }; spContentType = new ShimSPContentType() { IdGet = () => default(SPContentTypeId), FieldLinksGet = () => spFieldLinkCollection }; spFieldLinkCollection = new ShimSPFieldLinkCollection() { ItemGetGuid = _ => new ShimSPFieldLink() }; transaction = new ShimSqlTransaction() { Commit = () => { }, Rollback = () => { } }; dataReader = new ShimSqlDataReader() { Read = () => false, GetInt32Int32 = _ => One, GetDateTimeInt32 = _ => currentDate, GetStringInt32 = _ => DummyString, GetGuidInt32 = _ => guid, Close = () => { } }; }
private void SetupShims() { var listCount = 1; var spListItem = new ShimSPListItem { Update = () => _listItemUpdated = true, ItemGetString = _ => DummyString, Delete = () => { _listItemDeleted = true; listCount--; } }; var spListItemCollection = new ShimSPListItemCollection { CountGet = () => listCount, Add = () => { _listItemAdded = true; return(spListItem); }, GetDataTable = () => new ShimDataTable { Clone = () => CreateDataTable() }, DeleteInt32 = _ => _listItemDeleted = true, ItemGetInt32 = _ => spListItem }; var spList = new ShimSPList { FieldsGet = () => new ShimSPFieldCollection { ContainsFieldString = _ => false, AddStringSPFieldTypeBoolean = (name, __, ___) => { _fieldAdded = true; return(name); }, ItemGetString = _ => new ShimSPField() }, ItemsGet = () => spListItemCollection, Update = () => _listUpdated = true, GetItemByIdInt32 = _ => spListItem, GetItemsSPQuery = _ => spListItemCollection }; _site = new ShimSPSite { IDGet = () => Guid.NewGuid(), AllWebsGet = () => new ShimSPWebCollection { ItemGetString = _ => _web }, RootWebGet = () => _web }; var userCount = 0; _web = new ShimSPWeb { IDGet = () => Guid.NewGuid(), SiteGet = () => _site, ListsGet = () => new ShimSPListCollection { ItemGetString = _ => spList }, UrlGet = () => DummyString, AllUsersGet = () => new ShimSPUserCollection { ItemGetString = _ => { userCount++; return(userCount == 1 ? null : new ShimSPUser()); }, AddStringStringStringString = (_1, _2, _3, _4) => _userAdded = true } }; ShimSPSite.AllInstances.OpenWeb = _ => _web; ShimSPWeb.AllInstances.Dispose = _ => { }; ShimSPContext.CurrentGet = () => new ShimSPContext(); ShimSPContext.AllInstances.WebGet = _ => _web; ShimSPQuery.Constructor = _ => { }; ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = action => action(); ShimEPMData.ConstructorGuid = (_, __) => { }; ShimEPMData.AllInstances.GetEPMLiveConnectionGet = _ => new ShimSqlConnection(); ShimEPMData.AllInstances.ExecuteNonQuerySqlConnection = (instance, __) => { _nonQueryExecuted = true; _sqlString = instance.Command; return(true); }; ShimEPMData.AllInstances.AddParamStringObject = (_, __, ___) => { }; ShimEPMData.AllInstances.Dispose = _ => _daoDisposed = true; ShimCoreFunctions.getConfigSettingSPWebStringBooleanBoolean = (_1, _2, _3, _4) => DummyString; ShimCoreFunctions.getConfigSettingSPWebString = (_, item) => { switch (item) { case "EPMLIVEaddelete": return("true"); case "EPMLIVEadSizeLimit": return(DummyInt.ToString()); case "EPMLIVEadfields": return($"{DummyString};{DummyString}"); default: return(DummyString); } }; ShimDomain.GetComputerDomain = () => new ShimDomain(); ShimActiveDirectoryPartition.AllInstances.ToString01 = _ => $"{DummyString}.Domain"; ShimDirectoryEntry.ConstructorString = (_, __) => { }; ShimDirectoryEntry.ConstructorStringStringStringAuthenticationTypes = (_1, _2, _3, _4, _5) => { }; ShimDirectoryEntry.AllInstances.RefreshCache = _ => _deRefreshCacheCalled = true; ShimDirectoryEntry.AllInstances.PropertiesGet = _ => new ShimPropertyCollection { ItemGetString = item => new ShimPropertyValueCollection { ItemGetInt32 = ___ => new byte[] { } } }; ShimDirectorySearcher.ConstructorDirectoryEntry = (_, __) => { }; ShimDirectorySearcher.ConstructorDirectoryEntryString = (_, __, ___) => { }; ShimDirectorySearcher.AllInstances.FindAll = _ => new ShimSearchResultCollection { Dispose = () => { } }.Bind(new SearchResult[] { new ShimSearchResult { GetDirectoryEntry = () => new ShimDirectoryEntry { NameGet = () => DummyString, PathGet = () => DummyString }, PathGet = () => DummyString }.Instance }); ShimDirectorySearcher.AllInstances.FindOne = _ => new ShimSearchResult { PropertiesGet = () => new ShimResultPropertyCollection { ItemGetString = __ => new ShimResultPropertyValueCollection { ItemGetInt32 = ___ => DummyString } } }; ShimSecurityIdentifier.ConstructorByteArrayInt32 = (_, __, ___) => { }; ShimSecurityIdentifier.AllInstances.ValueGet = _ => DummyString; }
public void WriteValueToListItem_WhenGivenFieldValue_ShouldUpdateFieldValue() { using (ShimsContext.Create()) { // Arrange var setValue = "SomeTitle"; var setField = BuiltInFields.Title; var fakeListItemShim = new ShimSPListItem() { ItemSetStringObject = (internalName, value) => { Assert.AreEqual(setValue, value as string); Assert.AreEqual(setField.InternalName, internalName); } }; IFieldValueWriter writer; SPListItem fakeListItem = fakeListItemShim.Instance; using (var scope = UnitTestServiceLocator.BeginLifetimeScope()) { writer = scope.Resolve<IFieldValueWriter>(); } // Act writer.WriteValueToListItem(fakeListItem, new FieldValueInfo(setField, setValue)); // Assert } }
private void SetupVariables() { guid = new Guid(GuidString); spFarm = new ShimSPFarm(); spField = new ShimSPField(); spList = new ShimSPList() { FieldsGet = () => new ShimSPFieldCollection() { GetFieldByInternalNameString = _ => spField }, IDGet = () => guid }; spListItem = new ShimSPListItem() { ParentListGet = () => spList, FieldsGet = () => new ShimSPFieldCollection(), IDGet = () => 1 }; spSite = new ShimSPSite() { WebApplicationGet = () => new ShimSPWebApplication() { ApplicationPoolGet = () => new ShimSPApplicationPool() } }; spUser = new ShimSPUser() { LoginNameGet = () => DummyString, EmailGet = () => DummyString, IDGet = () => 1 }; spWeb = new ShimSPWeb() { ListsGet = () => new ShimSPListCollection() { ItemGetString = _ => spList }, SiteGet = () => spSite, CurrentUserGet = () => spUser, AllUsersGet = () => new ShimSPUserCollection() { GetByIDInt32 = _ => spUser }, IDGet = () => guid, WebsGet = () => new ShimSPWebCollection() { AddStringStringStringUInt32StringBooleanBoolean = (_, _1, _2, _3, _4, _5, _6) => spWeb }, NavigationGet = () => new ShimSPNavigation() { TopNavigationBarGet = () => new ShimSPNavigationNodeCollection() { NavigationGet = () => new ShimSPNavigation() } }, SiteGroupsGet = () => new ShimSPGroupCollection() { GetByIDInt32 = _ => new ShimSPGroup() }, UrlGet = () => DummyString, ServerRelativeUrlGet = () => DummyString, TitleGet = () => DummyString, AllowUnsafeUpdatesSetBoolean = _ => { }, SiteUserInfoListGet = () => spList, SiteUsersGet = () => new ShimSPUserCollection() { GetByIDInt32 = _ => spUser }, EnsureUserString = _ => spUser }; }
private void SetupVariables() { guid = new Guid(GuidString); spSite = new ShimSPSite() { IDGet = () => guid, OpenWebString = _ => spWeb, OpenWebGuid = _ => spWeb, UrlGet = () => DummyString, MakeFullUrlString = url => url, RootWebGet = () => spWeb }; spListItem = new ShimSPListItem() { IDGet = () => 1, ParentListGet = () => spList }; spList = new ShimSPList() { IDGet = () => guid, GetItemByIdInt32 = _ => spListItem, GetItemsSPQuery = _ => new ShimSPListItemCollection() { GetEnumerator = () => new List <SPListItem>() { spListItem }.GetEnumerator() }, ItemsGet = () => new ShimSPListItemCollection() { ItemGetInt32 = _ => spListItem, GetEnumerator = () => new List <SPListItem>() { spListItem }.GetEnumerator() }, FieldsGet = () => new ShimSPFieldCollection() { GetFieldByInternalNameString = _ => new ShimSPField() { IdGet = () => guid } } }; spWeb = new ShimSPWeb() { IDGet = () => guid, CurrentUserGet = () => new ShimSPUser() { IDGet = () => 111, LoginNameGet = () => DummyString }, ListsGet = () => new ShimSPListCollection() { TryGetListString = _ => spList, ItemGetGuid = _ => spList, ItemGetString = _ => spList, GetListGuidBoolean = (_, __) => spList }, SiteGet = () => spSite, UrlGet = () => DummyString, ExistsGet = () => true, WebsGet = () => new ShimSPWebCollection() { ItemGetString = _ => spWeb } }; }
public void AddBasicSecurityGroupsTest() { using (new SPEmulators.SPEmulationContext(SPEmulators.IsolationLevel.Fake)) { var user = new ShimSPUser() { IDGet = () => { return(1073741823); } }; var listitem = new ShimSPListItem() { ItemGetGuid = (guid) => { return(Guid.NewGuid()); }, IDGet = () => { return(1); }, TitleGet = () => { return("Adam Bar"); }, SystemUpdate = () => { } , FieldsGet = () => { return(new ShimSPFieldCollection() { GetFieldByInternalNameString = (s) => { return new ShimSPField() { IdGet = () => { return Guid.NewGuid(); } }; }, ItemGetGuid = (guid) => { return new ShimSPField() { IdGet = () => { return Guid.NewGuid(); } }; } }); }, ItemSetGuidObject = (a, b) => { }, Update = () => { } }; ShimSPList list = new ShimSPList() { ItemsGet = () => { return(new ShimSPListItemCollection() { GetItemByIdInt32 = (id) => { return listitem; } }); } }; ShimCoreFunctions.AddGroupSPWebStringStringSPMemberSPUserString = (a, b, c, d, e, f) => { return("final"); }; ShimSPWeb fakespweb = fakespweb = new ShimSPWeb() { IDGet = () => { return(Guid.Parse("D4A8A5A3-5C26-45D0-876C-AC2B4FB86D03")); }, CurrentUserGet = () => { return(user); }, SiteGroupsGet = () => { return(new ShimSPGroupCollection() { ItemGetString = (id) => { return new ShimSPGroup() { NameGet = () => { return Guid.NewGuid().ToString(); } }; } }); }, AllowUnsafeUpdatesSetBoolean = (b) => { }, SiteGet = () => { return(new ShimSPSite() { UrlGet = () => { return ""; }, OpenWebGuid = (gg) => { return new ShimSPWeb() { IDGet = () => { return Guid.Parse("D4A8A5A3-5C26-45D0-876C-AC2B4FB86D03"); }, PropertiesGet = () => { var propertyBag = new ShimSPPropertyBag(); var sd = new ShimStringDictionary(propertyBag); sd.ItemGetString = (key) => { return "EPMLive_MyWork_Grid_GlobalViews"; }; return propertyBag; }, SiteGet = () => { return new ShimSPSite() { IDGet = () => { return Guid.Parse("D4A8A5A3-5C26-45D0-876C-AC2B4FB86D03"); } }; }, Dispose = () => { }, AllowUnsafeUpdatesSetBoolean = (b) => { } }; }, RootWebGet = () => { return new ShimSPWeb() { ListsGet = () => { return new ShimSPListCollection() { ItemGetString = (s) => { return list; } }; }, IDGet = () => { return Guid.Parse("D4A8A5A3-5C26-45D0-876C-AC2B4FB86D03"); } }; } }); }, ParentWebGet = () => { return(null); }, PropertiesGet = () => { var propertyBag = new ShimSPPropertyBag(); var sd = new ShimStringDictionary(propertyBag); sd.ItemGetString = (key) => { return("EPMLiveLockConfig"); }; return(propertyBag); } , Update = () => { } }; fakespweb.Dispose = () => { }; var objSecurityUpdates = new SecurityUpdate(); var dict = objSecurityUpdates.AddBasicSecurityGroups(fakespweb, "title", user, listitem); Assert.IsTrue(dict.Count == 3); } }
public void WriteValueToListItem_GivenDateTimeFieldInfo_ShouldUseDateTimeValueWriter() { using (ShimsContext.Create()) { // Arrange var correctWriterWasUsed = false; var fieldInfo = new DateTimeFieldInfo("InternalName", Guid.NewGuid(), string.Empty, string.Empty, string.Empty); ShimDateTimeValueWriter.AllInstances.WriteValueToListItemSPListItemFieldValueInfo = (inst, listItem, fieldValueInfo) => { correctWriterWasUsed = true; }; var fakeListItem = new ShimSPListItem().Instance; IFieldValueWriter writer; using (var scope = UnitTestServiceLocator.BeginLifetimeScope()) { writer = scope.Resolve<IFieldValueWriter>(); } // Act writer.WriteValueToListItem(fakeListItem, new FieldValueInfo(fieldInfo, null)); // Assert Assert.IsTrue(correctWriterWasUsed, "The DateTimeValueWriter should have been used for the DateTimeFieldInfo type."); } }