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 SetupPro() { pro = new PolicyResponseObject(); pro.ContentCollection = new Collection<IContentItem>(); ContentItem ci = new ContentItem(); ci.Name = "ContentItem1"; pro.ContentCollection.Add(ci); PolicySetResponse setA = new PolicySetResponse("setA"); PolicySetResponse setB = new PolicySetResponse("setB"); ((ContentItem)pro.ContentCollection[0]).PolicySetCollection = new Collection<IPolicySetResponse>(); pro.ContentCollection[0].PolicySetCollection.Add(setA); pro.ContentCollection[0].PolicySetCollection.Add(setB); PolicyResponse policyW = new PolicyResponse(); policyW.Triggered = true; PolicyResponse policyX = new PolicyResponse(); policyX.Triggered = true; PolicyResponse policyY = new PolicyResponse(); policyY.Triggered = true; PolicyResponse policyZ = new PolicyResponse(); policyZ.Triggered = true; setA.PolicyReportCollection = new Collection<IPolicyResponse>(); setA.PolicyReportCollection.Add(policyW); setA.PolicyReportCollection.Add(policyX); setB.PolicyReportCollection = new Collection<IPolicyResponse>(); setB.PolicyReportCollection.Add(policyY); setB.PolicyReportCollection.Add(policyZ); policyW.ActionCollection = new Collection<IPolicyResponseAction>(); policyW.ActionCollection.Add(new PolicyResponseAction()); policyX.ActionCollection = new Collection<IPolicyResponseAction>(); policyX.ActionCollection.Add(new PolicyResponseAction()); ((PolicyResponseAction)policyW.ActionCollection[0]).Type = ((PolicyResponseAction)policyX.ActionCollection[0]).Type = "1stTypeOfAction"; policyY.ActionCollection = new Collection<IPolicyResponseAction>(); policyY.ActionCollection.Add(new PolicyResponseAction()); policyZ.ActionCollection = new Collection<IPolicyResponseAction>(); policyZ.ActionCollection.Add(new PolicyResponseAction()); ((PolicyResponseAction)policyY.ActionCollection[0]).Type = ((PolicyResponseAction)policyZ.ActionCollection[0]).Type = "2ndTypeOfAction"; //Wire up the resolved actions... one of each type. ResolvedAction action1 = new ResolvedAction(); action1.ResponseAction = policyW.ActionCollection[0]; ResolvedAction action2 = new ResolvedAction(); action2.ResponseAction = policyY.ActionCollection[0]; pro.ResolvedActionCollection = new Collection<IResolvedAction>(); pro.ResolvedActionCollection.Add(action1); pro.ResolvedActionCollection.Add(action2); //This bit mimics what happens in action resolution - each resolved actions has a list of which content items it will act on. action1.ContentCollection = new Collection<IContentItem>(); action1.ContentCollection.Add(ci); action2.ContentCollection = new Collection<IContentItem>(); action2.ContentCollection.Add(ci); }