public void EnableTeamFeatures_ExceptionUpdate_ReturnsFalse() { // Arrange var countGetField = 0; var list = new ShimSPList() { FieldsGet = () => new ShimSPFieldCollection() { GetFieldByInternalNameString = internalName => { if (countGetField == 0) { countGetField++; return(null); } return(new ShimSPField() { Update = () => { throw new Exception(); } }); }, AddStringSPFieldTypeBoolean = (displayName, type, required) => string.Empty } }; // Act var actualResult = ListCommands.EnableTeamFeatures(list); // Assert actualResult.ShouldBeFalse(); }
public void ShouldReturnCachedList() { var siteMock = new ShimSPSite(); const string TestUrl = "test/url"; var listMock = new ShimSPList(); var listCollection = new ShimSPListCollection { ItemGetGuid = _ => listMock }; var webMock = new ShimSPWeb { ServerRelativeUrlGet = () => TestUrl, ListsGet = () => listCollection }; siteMock.OpenWebGuid = guid => webMock; using (var cache = SaveDataJobExecuteCache.InitializeCache(siteMock)) { var properties = new ShimSPItemEventProperties { RelativeWebUrlGet = () => TestUrl }; var webById = cache.GetWeb(Guid.Empty.ToString()); var list = SaveDataJobExecuteCache.GetList(properties); webById.ShouldNotBeNull(); list.ShouldBe(listMock); } }
private void SetupForGetResourcepoolItem() { var dataTable = CreateDataTable(); var dataRow = dataTable.NewRow(); dataRow[SIDField] = DummyString; dataRow[IDField] = DummyInt; dataTable.Rows.Add(dataRow); var list = new ShimSPList { ItemsGet = () => new ShimSPListItemCollection { Add = () => { _listItemAdded = true; return(new ShimSPListItem { NameGet = () => DummyString }); } }, GetItemByIdInt32 = _ => new ShimSPListItem { NameGet = () => DummyString }.Instance }.Instance; _privateObj.SetFieldOrProperty(HasSIDProperty, true); _privateObj.SetFieldOrProperty(ResourcePoolProperty, dataTable); _privateObj.SetFieldOrProperty(ListProperty, list); }
public void TryHideField_Found_ReturnsTrue() { // Arrange var countUpdatedField = 0; var countUpdatedList = 0; var list = new ShimSPList() { FieldsGet = () => new ShimSPFieldCollection() { GetFieldByInternalNameString = internalName => new ShimSPField() { SealedGet = () => true, Update = () => countUpdatedField++ } }, Update = () => countUpdatedList++ }; // Act var actualResult = (bool)_privateType.InvokeStatic("TryHideField", list.Instance, DummyInternalName); // Assert this.ShouldSatisfyAllConditions( () => actualResult.ShouldBeTrue(), () => countUpdatedList.ShouldBe(1), () => countUpdatedField.ShouldBe(2)); }
public void DisableTimesheets_Should_RemoveStringFromList() { // Arrange var actualEpmLiveTsLists = string.Empty; var list = new ShimSPList() { FieldsGet = () => new ShimSPFieldCollection() { GetFieldByInternalNameString = internalName => new ShimSPField() }, TitleGet = () => DummyTitle }; var web = new ShimSPWeb() { SiteGet = () => new ShimSPSite() { RootWebGet = () => new ShimSPWeb() } }; ShimSPFieldLink.ConstructorSPField = (sender, spField) => new ShimSPFieldLink(); ShimCoreFunctions.getConfigSettingSPWebString = (rootWeb, setting) => $"{DummyTitle}\r\n{DummyInternalName}"; ShimCoreFunctions.setConfigSettingSPWebStringString = (rootWeb, setting, value) => actualEpmLiveTsLists = value; // Act ListCommands.DisableTimesheets(list, web); // Assert actualEpmLiveTsLists.ShouldBe(DummyInternalName); }
public void AuditResourcePool_OnError_LogError() { // Arrange var list = new ShimSPList { ItemsGet = () => new ShimSPListItemCollection { CountGet = () => 1, ItemGetInt32 = _ => { throw new Exception(DummyError); } } }.Instance; _privateObj.SetFieldOrProperty(ListProperty, list); // Act _privateObj.Invoke(AuditResourcePoolMethod); // Assert var executionLogs = (List <string>)_privateObj.GetFieldOrProperty(ExecutionLogsProperty); var hasErrors = (bool)_privateObj.GetFieldOrProperty(HasErrorsProperty); this.ShouldSatisfyAllConditions( () => _listItemUpdated.ShouldBeFalse(), () => hasErrors.ShouldBeTrue(), () => executionLogs.ShouldContain($" ERROR -- Location: AuditResourcePool() -- SID: -- Message: {DummyError}")); }
public void UpdateResourcePool_OnValidCall_ConfirmResult() { // Arrange var dataTable = CreateDataTable(); var dataRow = dataTable.NewRow(); dataRow[SIDField] = DummyString; dataTable.Rows.Add(dataRow); var list = new ShimSPList { ItemsGet = () => new ShimSPListItemCollection { Add = () => { _listItemAdded = true; return(new ShimSPListItem()); } } }.Instance; var dao = new ShimEPMData().Instance; _privateObj.SetFieldOrProperty(AdUsersProperty, dataTable); _privateObj.SetFieldOrProperty(ListProperty, list); _privateObj.SetFieldOrProperty(DAOProperty, dao); // Act _privateObj.Invoke(UpdateResourcePoolMethod); // Assert this.ShouldSatisfyAllConditions( () => _listItemAdded.ShouldBeTrue(), () => _nonQueryExecuted.ShouldBeTrue()); }
public void EnableTeamFeatures_Updated_ReturnsTrue() { // Arrange var actualUpdatedField = false; var countGetField = 0; var list = new ShimSPList() { FieldsGet = () => new ShimSPFieldCollection() { GetFieldByInternalNameString = internalName => { if (countGetField == 0) { countGetField++; return(null); } return(new ShimSPField() { Update = () => actualUpdatedField = true }); }, AddStringSPFieldTypeBoolean = (displayName, type, required) => string.Empty } }; // Act var actualResult = ListCommands.EnableTeamFeatures(list); // Assert this.ShouldSatisfyAllConditions( () => actualResult.ShouldBeTrue(), () => actualUpdatedField.ShouldBeTrue()); }
private SPList ShimSPEventReceiverDefinitionCollectionMethods(SPWeb parentWeb = null) { _definitionsList = new List <SPEventReceiverDefinition>(); var list = new ShimSPList { EventReceiversGet = () => new ShimSPEventReceiverDefinitionCollection { AddSPEventReceiverTypeStringString = (type, assembly, klass) => { _definitionsList.Add(new ShimSPEventReceiverDefinition { TypeGet = () => type, AssemblyGet = () => assembly, ClassGet = () => klass, Delete = () => _eventsDeleted++ }); } }.Instance, FieldsGet = () => GetFieldsShim().Instance, Update = () => { _listUpdated = true; }, ParentWebGet = () => parentWeb }.Instance; ShimSPBaseCollection.AllInstances.GetEnumerator = _ => _definitionsList.GetEnumerator(); return(list); }
public void BuildResourceCap_Should_ExecuteCorrectly() { // Arrange var list = new ShimSPList { ItemsGet = () => new ShimSPListItemCollection { GetEnumerator = () => new List <SPListItem> { new ShimSPListItem { ItemGetString = name => "1" }, new ShimSPListItem { ItemGetString = name => "1" } }.GetEnumerator() } }.Instance; // Act privateObject.Invoke(BuildResourceCapMethodName, list, DummyString); var resourceList = privateObject.GetFieldOrProperty("lstResourceCap") as SortedList; // Assert resourceList.ShouldSatisfyAllConditions( () => resourceList.ShouldNotBeNull(), () => resourceList.Count.ShouldBeGreaterThan(0)); }
public void SaveIconToReporting_Should_ExecuteQuery() { // Arrange var actualQueryExecute = string.Empty; IDictionary <string, object> actualParameters = new Dictionary <string, object>(); var list = new ShimSPList() { IDGet = () => DummyGuid, ParentWebGet = () => new ShimSPWeb() }; ShimGridGanttSettings.ConstructorSPList = (sender, listParam) => sender.ListIcon = DummyIcon; ShimQueryExecutor.ConstructorSPWeb = (sender, web) => new ShimQueryExecutor(); ShimQueryExecutor.AllInstances.ExecuteReportingDBNonQueryStringIDictionaryOfStringObject = (sender, query, parameters) => { actualQueryExecute = query; actualParameters = parameters; }; // Act ListCommands.SaveIconToReporting(list); // Assert this.ShouldSatisfyAllConditions( () => actualQueryExecute.ShouldBe(@"INSERT INTO ReportListIds (Id, ListIcon) VALUES (@Id, @Icon)"), () => actualParameters.Count.ShouldBe(2), () => actualParameters.ShouldContainKeyAndValue("@Id", DummyGuid), () => actualParameters.ShouldContainKeyAndValue("@Icon", DummyIcon)); }
private static void SetupForPageLoad(ShimSPList templates) { ShimPage.AllInstances.IsPostBackGet = _ => false; ShimCoreFunctions.getConfigSettingSPWebString = (web, setting) => { switch (setting) { case EPMLiveGroupsPermAssignments: return($"{DummyIntOne}~{DummyIntOne}"); case EPMLiveUseWEPeoplePicker: case EPMLiveUseLiveTemplates: return(TrueString); case EPMLiveCreateNewSettings: return($"{Default}^{DummyString};#{Online}^{TrueString}|{Local}^{TrueString}|{Existing}^{TrueString}"); default: return(DummyString); } }; ShimCoreFunctions.getConfigSettingSPWebStringBooleanBoolean = (_, __, ___, ____) => DummyString; ShimSPListCollection.AllInstances.TryGetListString = (_, __) => templates; }
private void SetupForCheckForSIDandDisableColumn(bool containsField, int itemCount) { var list = new ShimSPList { FieldsGet = () => new ShimSPFieldCollection { ContainsFieldString = _ => containsField, AddStringSPFieldTypeBoolean = (_, __, ___) => { _fieldAdded = true; return(DummyString); }, ItemGetString = _ => new ShimSPField() }, ItemsGet = () => new ShimSPListItemCollection { CountGet = () => itemCount, GetDataTable = () => CreateDataTable(), Add = () => { _listItemAdded = true; return(new ShimSPListItem { Update = () => _listItemUpdated = true }); }, DeleteInt32 = _ => _listItemDeleted = true }, Update = () => _listUpdated = true }.Instance; _privateObj.SetFieldOrProperty(ListProperty, list); }
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 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 EnableTimesheets_Should_UpdateFields() { // Arrange var countUpdatedField = 0; var countUpdatedContentType = 0; var countUpdatedList = 0; var actualEpmLiveTsLists = string.Empty; var list = new ShimSPList() { FieldsGet = () => new ShimSPFieldCollection() { GetFieldByInternalNameString = internalName => new ShimSPField() { Update = () => countUpdatedField++ } }, ContentTypesGet = () => new ShimSPContentTypeCollection() { ItemGetString = itemName => new ShimSPContentType() { FieldLinksGet = () => new ShimSPFieldLinkCollection() { ItemGetGuid = guid => null }, Update = () => countUpdatedContentType++ } }, Update = () => countUpdatedList++, TitleGet = () => DummyTitle }; var web = new ShimSPWeb() { SiteGet = () => new ShimSPSite() { RootWebGet = () => new ShimSPWeb() } }; ShimSPFieldLink.ConstructorSPField = (sender, spField) => new ShimSPFieldLink(); ShimCoreFunctions.getConfigSettingSPWebString = (rootWeb, setting) => string.Empty; ShimCoreFunctions.setConfigSettingSPWebStringString = (rootWeb, setting, value) => actualEpmLiveTsLists = value; // Act ListCommands.EnableTimesheets(list, web); // Assert this.ShouldSatisfyAllConditions( () => countUpdatedField.ShouldBe(2), () => countUpdatedContentType.ShouldBe(2), () => countUpdatedList.ShouldBe(1), () => actualEpmLiveTsLists.ShouldBe($"\r\n{DummyTitle}")); }
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 EnableFancyForms_FancyFormNotFound_SaveChangesAndDispose() { // Arrange var actualCountSaveChanges = 0; var actualDisposeWeb = false; var list = new ShimSPList() { ParentWebGet = () => new ShimSPWeb() { ServerRelativeUrlGet = () => DummyUrl, GetFileString = strUrl => new ShimSPFile() { GetLimitedWebPartManagerPersonalizationScope = scope => new ShimSPLimitedWebPartManager() { WebPartsGet = () => new ShimSPLimitedWebPartCollection() { ItemGetInt32 = itemId => { if (itemId == 0) { return(new ShimWebPart(new ShimGridListView().Instance) { TitleGet = () => "Fancy Display Form" }); } return(new ShimWebPart(new ShimListFormWebPart().Instance)); } } .Bind( new WebPart[] { new ShimWebPart(new ShimGridListView().Instance), new ShimWebPart(new ShimListFormWebPart().Instance) }), SaveChangesWebPart = webPartChanged => actualCountSaveChanges++, WebGet = () => new ShimSPWeb() { Dispose = () => actualDisposeWeb = true } } } }, RootFolderGet = () => new ShimSPFolder() }; // Act ListCommands.EnableFancyForms(list); // Assert this.ShouldSatisfyAllConditions( () => actualCountSaveChanges.ShouldBe(2), () => actualDisposeWeb.ShouldBeTrue()); }
public void ShouldReturnListFromPropertiesIfNoCache() { var listMock = new ShimSPList(); var properties = new ShimSPItemEventProperties { ListGet = () => listMock }; var list = SaveDataJobExecuteCache.GetList(properties); list.ShouldBe(listMock); }
public void FieldExistsInList_WhenNotFindField_ConfirmResult() { // Arrange var list = new ShimSPList(); // Act var result = _testObj.FieldExistsInList(list, DummyString); // Assert result.ShouldBeFalse(); }
public void RemoveEventReceiver_ReceiverExists_ExecutesCorrectly() { // Arrange ShimEventReceiverManager.AllInstances.RemoveEventReceiverSPListStringStringSPEventReceiverTypeXElementRef = null; ShimXContainer.AllInstances.ElementXName = null; const string ExpectedValue = "0"; const string ExpectedMessage = "Event receiver successfully uninstalled."; var receiverType = SPEventReceiverType.GroupUserDeleted; var receiverElement = new XElement(DummyString); var spList = new ShimSPList { ParentWebGet = () => new ShimSPWeb { IDGet = () => DummyGuid, SiteGet = () => new ShimSPSite { IDGet = () => DummyGuid } }, EventReceiversGet = () => { var list = new List <SPEventReceiverDefinition> { new ShimSPEventReceiverDefinition { AssemblyGet = () => DummyString, ClassGet = () => DummyString, TypeGet = () => receiverType } }; return(new ShimSPEventReceiverDefinitionCollection().Bind(list)); } }.Instance; var args = new object[] { spList, DummyString, DummyString, receiverType, receiverElement }; // Act privateObject.Invoke(RemoveEventReceiverMethodName, args); receiverElement = args[4] as XElement; var dataElement = receiverElement.Element(DataAttribute); // Assert receiverElement.ShouldNotBeNull(); dataElement.ShouldNotBeNull(); dataElement.Value.ShouldBe(ExpectedMessage); dataElement.Attribute(StatusAttribute)?.Value.ShouldBe(ExpectedValue); }
public void InstallListsViewsWebParts_FoundGridListView_AddGridView() { // Arrange var actualAddedGridView = false; var actualDisposeWeb = false; var spList = new ShimSPList() { BaseTemplateGet = () => SPListTemplateType.AccessApp, ParentWebGet = () => new ShimSPWeb() { GetFileString = strUrl => new ShimSPFile() { ExistsGet = () => true, GetLimitedWebPartManagerPersonalizationScope = scope => new ShimSPLimitedWebPartManager() { WebPartsGet = () => new ShimSPLimitedWebPartCollection().Bind( new WebPart[] { new ShimWebPart(new ShimGridListView().Instance) }), AddWebPartWebPartStringInt32 = (webPart, zoneId, zoneIndex) => { if (webPart.GetType() == typeof(GridListView)) { actualAddedGridView = true; } }, WebGet = () => new ShimSPWeb() { Dispose = () => actualDisposeWeb = true } } } }, ViewsGet = () => new ShimSPViewCollection().Bind( new SPView[] { new ShimSPView() { UrlGet = () => DummyUrl } }) }; // Act ListCommands.InstallListsViewsWebparts(spList); // Assert this.ShouldSatisfyAllConditions( () => actualAddedGridView.ShouldBeFalse(), () => actualDisposeWeb.ShouldBeTrue()); }
public SPList CreateListInstance(SPWeb web) { var id = web.Lists.Add(ListTitle, null, ListTemplateType); var list = web.Lists[id]; var shimList = new ShimSPList(list) { DescriptionGet = () => ListDescription, BaseTemplateGet = () => ListTemplateType, OnQuickLaunchGet = () => OnQuickLaunch }; return(shimList.Instance); }
public SPList CreateListInstance(SPWeb web) { var id = web.Lists.Add(ListTitle, null, ListTemplateType); var list = web.Lists[id]; var shimList = new ShimSPList(list) { DescriptionGet = () => ListDescription, BaseTemplateGet = () => ListTemplateType, OnQuickLaunchGet = () => OnQuickLaunch }; return shimList.Instance; }
public void GetAssociatedLists_NotFound_ReturnsArrayList() { // Arrange var list = new ShimSPList() { IDGet = () => ListId, ParentWebGet = () => new ShimSPWeb() { ListsGet = () => new ShimSPListCollection().Bind( new SPList[] { new ShimSPList() { FieldsGet = () => new ShimSPFieldCollection().Bind( new SPField[] { new ShimSPField( new ShimSPFieldLookup() { LookupListGet = () => $"{{{ListId}}}" }) { TypeGet = () => SPFieldType.Lookup, InternalNameGet = () => DummyInternalName } }), ImageUrlGet = () => DummyImageUrl, IDGet = () => DummyGuid, TitleGet = () => DummyTitle } }) } }; ShimGridGanttSettings.ConstructorSPList = (sender, listParam) => sender.AssociatedItems = true; // Act var actualResult = ListCommands.GetAssociatedLists(list); // Assert var associatedListInfo = (AssociatedListInfo)actualResult[0]; this.ShouldSatisfyAllConditions( () => actualResult.Count.ShouldBe(1), () => actualResult[0].ShouldBeOfType <AssociatedListInfo>(), () => associatedListInfo.Title.ShouldBe(DummyTitle), () => associatedListInfo.LinkedField.ShouldBe(DummyInternalName), () => associatedListInfo.ListId.ShouldBe(DummyGuid), () => associatedListInfo.icon.ShouldBe(DummyImageUrl)); }
public void GetReportQueryNode_ValuesNodeNotEmpty_ReturnExpectedContent() { // Arrange var expectedText = $"({DummyString}Text = '{DummyString}' )"; var spWeb = new ShimSPWeb().Instance; var xmlNode = new ShimXmlNode(new XmlDocument()).Instance; var spList = new ShimSPList { FieldsGet = () => new ShimSPFieldCollection { GetFieldByInternalNameString = name => new ShimSPField { TypeGet = () => SPFieldType.User } } }.Instance; var privateType = new PrivateType(typeof(ReportingData)); ShimXmlDocument.AllInstances.NameGet = _ => "Contains"; ShimXmlNode.AllInstances.SelectSingleNodeString = (_, nodeName) => new ShimXmlNode(new XmlDocument()) { AttributesGet = () => new ShimXmlAttributeCollection { ItemOfGetString = attrName => new ShimXmlAttribute { ValueGet = () => "Dummy" } } }.Instance; ShimXmlNode.AllInstances.SelectNodesString = (_, name) => { var document = new XmlDocument(); var element = document.CreateElement("Dummy"); element.InnerText = "Dummy"; document.AppendChild(element); return(document.ChildNodes); }; var args = new object[] { spWeb, xmlNode, spList }; // Act var result = privateType.InvokeStatic(GetReportQueryNodeMethodName, args) as string; // Assert result.ShouldSatisfyAllConditions( () => result.ShouldNotBeNullOrEmpty(), () => result.ShouldBe(expectedText)); }
public void ShouldReturnListFromPropertiesIfItIsNotFoundInCache() { var siteMock = new ShimSPSite(); const string TestUrl = "test/url"; var listMock = new ShimSPList(); using (SaveDataJobExecuteCache.InitializeCache(siteMock)) { var properties = new ShimSPItemEventProperties { RelativeWebUrlGet = () => TestUrl, ListGet = () => listMock }; var list = SaveDataJobExecuteCache.GetList(properties); list.ShouldBe(listMock); } }
public void GetReportQueryNode_FieldTypeUser() { // Arrange var expectedText = $"{DummyString}ID Is Null"; var spWeb = new ShimSPWeb { CurrentUserGet = () => new ShimSPUser { IDGet = () => 1 } }.Instance; var xmlNode = new ShimXmlNode(new XmlDocument()).Instance; var spList = new ShimSPList { FieldsGet = () => new ShimSPFieldCollection { GetFieldByInternalNameString = name => new ShimSPFieldLookup { LookupListGet = () => Guid.NewGuid().ToString(), LookupFieldGet = () => DummyString } } }.Instance; ShimSPField.AllInstances.TypeGet = _ => SPFieldType.User; ShimXmlDocument.AllInstances.NameGet = _ => "IsNull"; ShimXmlNode.AllInstances.SelectSingleNodeString = (_, nodeName) => { if (nodeName == ValuesNodeName || nodeName == UserIdNodeName) { return(null); } else { return(GetDefaultXmlNode("1", DummyString)); } }; var args = new object[] { spWeb, xmlNode, spList }; // Act var result = _privateType.InvokeStatic(GetReportQueryNodeMethodName, args) as string; // Assert result.ShouldSatisfyAllConditions( () => result.ShouldNotBeNullOrEmpty(), () => result.ShouldContain(expectedText)); }
public void GetReportQueryNode_FieldTypeCalculated() { // Arrange var expectedText = $"{DummyString} Like '%100%'"; var spWeb = new ShimSPWeb { CurrentUserGet = () => new ShimSPUser { IDGet = () => 1 } }.Instance; var xmlNode = new ShimXmlNode(new XmlDocument()).Instance; var spList = new ShimSPList { FieldsGet = () => new ShimSPFieldCollection { GetFieldByInternalNameString = name => new ShimSPFieldCalculated { ShowAsPercentageGet = () => true } } }.Instance; ShimSPField.AllInstances.TypeGet = _ => SPFieldType.Calculated; ShimXmlDocument.AllInstances.NameGet = _ => "Contains"; ShimXmlNode.AllInstances.SelectSingleNodeString = (_, nodeName) => { if (nodeName == "Values") { return(null); } else { return(GetDefaultXmlNode(DummyString, DummyString)); } }; var args = new object[] { spWeb, xmlNode, spList }; // Act var result = _privateType.InvokeStatic(GetReportQueryNodeMethodName, args) as string; // Assert result.ShouldSatisfyAllConditions( () => result.ShouldNotBeNullOrEmpty(), () => result.ShouldBe(expectedText)); }
public void GetIssueStatus_OnSuccess_ReturnsExpectedContent() { // Arrange const string DummyValue = "DummyValue"; dashboard.MyIssueState = Milestone; const string ProjectName = "Project"; var issueList = new ShimSPList { GetItemsSPQuery = query => new ShimSPListItemCollection { GetEnumerator = () => new List <SPListItem> { new ShimSPListItem { ItemGetString = GetValue(new Hashtable()) }, new ShimSPListItem { ItemGetString = GetValue(new Hashtable { [Milestone] = DummyValue, [DueDate] = DateTime.Now }) } }.GetEnumerator() } }.Instance; var issues = new SortedList { [DummyValue] = 1 }; privateObject.SetFieldOrProperty("issueList", issueList); privateObject.SetFieldOrProperty("arrIssues", issues); // Act var result = privateObject.Invoke(GetIssueStatusMethodName, ProjectName) as string; // Assert result.ShouldSatisfyAllConditions( () => result.ShouldNotBeNullOrEmpty(), () => result.ShouldBe("green"), () => issues[DummyValue].ShouldNotBeNull(), () => issues[DummyValue].ShouldBe(2)); }