public static void AddActionToContentCollection(IPolicyResponseObject pro, IAction3 action, bool skipRootContainer, bool triggeredPolicy) { ResolvedAction resAction = new ResolvedAction(); PolicyResponseAction pra = new PolicyResponseAction(); pra.Action = action; pra.InternalProperties = new MockActionPropertySet(); for (int index = 0; index < pro.ContentCollection.Count; ++index) { ContentItem contentItem = pro.ContentCollection[index] as ContentItem; if (null == contentItem) continue; if (skipRootContainer && (0 == index) && (contentItem.File.IsCollection)) continue; if (resAction.ContentCollection == null) resAction.ContentCollection = new Collection<IContentItem>(); resAction.ContentCollection.Add(contentItem); resAction.ResponseAction = pra; if (pro.ResolvedActionCollection == null) (pro as PolicyResponseObject).ResolvedActionCollection = new Collection<IResolvedAction>(); if(!pro.ResolvedActionCollection.Contains(resAction)) pro.ResolvedActionCollection.Add(resAction); AddActionToContentItem(contentItem, pra, triggeredPolicy); } }
public PolicyResponseActionMerger(IPolicyResponseAction action) { PolicyResponseAction input = action as PolicyResponseAction; m_pra = input.DeepCopy(); m_propertiesList = new List<ActionPropertySet>(); if (m_pra.InternalProperties != null) AddActionPropertySet(m_pra.InternalProperties); }
public static void AddActionToContentItem(ContentItem contentItem, PolicyResponseAction responseAction, bool triggeredPolicy) { PolicySetResponse psr = new PolicySetResponse("Test Policy Set"); PolicyResponse pr = new PolicyResponse(); pr.Triggered = triggeredPolicy; pr.ActionCollection = new Collection<IPolicyResponseAction>(); pr.ActionCollection.Add(responseAction); psr.PolicyReportCollection = new Collection<IPolicyResponse>(); psr.PolicyReportCollection.Add(pr); contentItem.PolicySetCollection = new Collection<IPolicySetResponse>(); contentItem.PolicySetCollection.Add(psr); }
public void ResolveActionsForVerifiedResponses_MultipleContentItems() { pro.VerifiedOnClient = true; pro.ContentCollection[0].PolicySetCollection[0].PolicyReportCollection[0].SkipVerifiedMessages = true; pro.ContentCollection[0].PolicySetCollection[0].PolicyReportCollection[1].SkipVerifiedMessages = true; //These two policies trigger the same type of action. pro.ContentCollection[0].PolicySetCollection[1].PolicyReportCollection[0].SkipVerifiedMessages = true; pro.ContentCollection[0].PolicySetCollection[1].PolicyReportCollection[1].SkipVerifiedMessages = true; //These two pols trigger the same type of action, but different from 1st two policies. ContentItem ci = new ContentItem(); ci.Name = "ContentItem2"; pro.ContentCollection.Add(ci); Assert.AreEqual(2, pro.ContentCollection.Count); ci.PolicySetCollection = new Collection<IPolicySetResponse>(); PolicySetResponse psr = new PolicySetResponse("PolicyC"); PolicyResponse pol = new PolicyResponse(); pol.Triggered = true; pol.SkipVerifiedMessages = false; //Therefore, this policy vetoes the skipping. We expect to see any actions from this policy show up in the resolved list. psr.PolicyReportCollection = new Collection<IPolicyResponse>(); psr.PolicyReportCollection.Add(pol); ci.PolicySetCollection.Add(psr); pol.ActionCollection = new Collection<IPolicyResponseAction>(); PolicyResponseAction pra1 = new PolicyResponseAction(); pra1.Type = "1stTypeOfAction"; PolicyResponseAction pra2 = new PolicyResponseAction(); pra2.Type = "2ndTypeOfAction"; pol.ActionCollection.Add(pra1); pol.ActionCollection.Add(pra2); //We've now mimicked an existing action being triggered on a new content item. //Update the content collections that the resolved actions maintain. pro.ResolvedActionCollection[0].ContentCollection.Add(ci); pro.ResolvedActionCollection[1].ContentCollection.Add(ci); ActionUtils.ResolveActionsForVerifiedResponses(pro); Assert.AreEqual(2, pro.ResolvedActionCollection.Count, "Both actions should be present."); IResolvedAction action1 = pro.ResolvedActionCollection[0]; IResolvedAction action2 = pro.ResolvedActionCollection[1]; Assert.AreEqual("1stTypeOfAction", action1.ResponseAction.Type); Assert.AreEqual("2ndTypeOfAction", action2.ResponseAction.Type); Assert.AreEqual(1, action1.ContentCollection.Count, "Expected a single item in the content collection, because this action should only apply to one of the content items, not both"); Assert.AreEqual(1, action2.ContentCollection.Count, "Expected a single item in the content collection."); pol.SkipVerifiedMessages = true; ActionUtils.ResolveActionsForVerifiedResponses(pro); Assert.AreEqual(0, pro.ResolvedActionCollection.Count); }
public void TestMergePra() { BasicAction basic = new BasicAction(); ActionPropertySet set = new ActionPropertySet(); set.Add("Test", new ActionProperty("Test","test")); basic.PropertySet = set; PolicyResponseAction pra = new PolicyResponseAction(); pra.Action = basic; pra.InternalProperties = set; PolicyResponseActionMerger merger = new PolicyResponseActionMerger(pra); set["Test"].Value = "test2"; merger.AddActionPropertySet(set); PolicyResponseAction praNew = (PolicyResponseAction) merger.MergePra(); Assert.AreEqual(praNew.InternalProperties["ThisWasMerged"].Value.ToString(), "sisterhood", "Property value should be - sisterhood"); Assert.AreEqual(2, basic.CountMerged, "Expected 2 property sets to be sent to the action"); Assert.AreNotEqual(praNew, pra, "Expected a new {0} back", praNew.GetType().ToString()); }
public void CorrectlyMergedUIProperties() { string[] props = { "EXECUTE", "transparent", "autoexpand" }; #region setup BasicAction basic = new BasicAction(); PolicyResponseAction pra = new PolicyResponseAction(); pra.Action = basic; PolicyResponseActionMerger merger = new PolicyResponseActionMerger(pra); bool propValue = true; for (int i = 0; i < 3; i++) { //set the property sets up such that the properties have different values ActionPropertySet newSet = new ActionPropertySet(); foreach (string s in props) { newSet[s] = new ActionProperty(s, typeof(bool), PropertyDisplayType.Checkbox, propValue, propValue, propValue, false); } merger.AddActionPropertySet(newSet); propValue = !propValue; } #endregion PolicyResponseAction resultPra = merger.MergePra() as PolicyResponseAction; // if at least one user override is false then the override is false // if at least one visible is true the it should be what ? foreach (string s in props) { Assert.IsFalse((bool)resultPra.InternalProperties[s].Override, "Override should be disallowed for {0}", s); Assert.IsTrue((bool)resultPra.InternalProperties[s].Visible, "props should be visible for {0}", s); } Assert.IsTrue((bool)(resultPra.InternalProperties["EXECUTE"].Value), "EXECUTE property should be true if at least one set specifies true"); Assert.IsFalse((bool)(resultPra.InternalProperties["transparent"].Value), "transparent property should be false if at least one set specifies false"); Assert.IsTrue((bool)resultPra.InternalProperties["autoexpand"].Value, "autoexpand property value should be true"); }
public void EnsureSystemPropertiesArePreserved() { #region setup string[] systemProperties = { "CurrentUser", "Date", "RecipientList", "RunAt", "FileType" }; BasicAction basic = new BasicAction(); ActionPropertySet set = new ActionPropertySet(); set["Add"] = new ActionProperty("TEST", "test"); basic.PropertySet = set; PolicyResponseAction pra = new PolicyResponseAction(); pra.Action = basic; pra.InternalProperties = set; set["Add"].Value = "test2"; foreach (string s in systemProperties) { set.SystemProperties[s] = new ActionProperty(s, s); } PolicyResponseActionMerger merger = new PolicyResponseActionMerger(pra); merger.AddActionPropertySet(set); #endregion //execute pra = merger.MergePra() as PolicyResponseAction; //verify foreach (string s in systemProperties) { SortedList<string, IActionProperty> aps = pra.InternalProperties.SystemProperties; Assert.IsTrue(aps.ContainsKey(s) && aps[s].Value.ToString() == s, "System property {0} has been modified after merge", s); } }