public void TestWriteRuleAttributes() { Guid languageId = new Guid("{CBEB31FA-7FE8-4E27-A01A-1D19AFCA604C}"); PolicyLanguage language = new PolicyLanguage(languageId, "en"); language[new Guid("{B067FF7F-2DA0-4AA1-A69F-DEFCD8B4CE90}")] = "Test rule"; language[new Guid("{305F5FFD-9C46-4BE7-896E-2ACE709E5D7E}")] = "Test policy"; language[new Guid("{EBF8443B-4912-44F2-89BE-A0A055332D1B}")] = "This is my first custom property"; language[new Guid("{8053E60C-EED7-464D-84EA-ECB51C291237}")] = "This is my second custom property"; XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.AddLanguage(language); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; Guid catalogueGuid = new Guid("{BC626464-1524-407C-8CD4-2B2B9C5BFE87}"); PolicyCatalogue policyCatalogue = new PolicyCatalogue(catalogueGuid, languageId, catalogueStore); XmlStore store = new XmlStore(); ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{305F5FFD-9C46-4BE7-896E-2ACE709E5D7E}"), store, policyCatalogue, false); P5Policy policy = new P5Policy(policySet, new Guid("{8E915159-5F01-41B3-9FFF-20731544ADFA}"), new TranslateableLanguageItem("{B067FF7F-2DA0-4AA1-A69F-DEFCD8B4CE90}"), PolicyStatus.Active); policy["custom1"] = new TranslateableLanguageItem("{EBF8443B-4912-44F2-89BE-A0A055332D1B}"); policy["custom2"] = new TranslateableLanguageItem("{8053E60C-EED7-464D-84EA-ECB51C291237}"); IPolicyStoreWriter writer = store.Writer; writer.WritePolicySet(policySet); writer.WritePolicy(policySet, policy); writer.Close(); TestHelpers.CompareXml(m_testPath + "ExpectedWriteRuleAttributes.xml", store.StoreXML); }
public void TestCreatePreRoutingSetWithInternalExternalSmptRoutingTable() { string testCatalogue = m_testPath + "TestRealPolicyCatalogue.xml"; string testLanguage = m_testPath + "TestRealPolicyLanguage.xml"; XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage)); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue)); PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.SMTP); XmlStore store = new XmlStore(); ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false); P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active); channel.Routing = BuildInternalExternalSmtpRouting(); channel.Actions = BuildActionMatrix(policy, false); NxPreRoutingSet nxprs = new NxPreRoutingSet(channel, policy, Guid.NewGuid(), Guid.NewGuid()); XmlNode xml = nxprs.Create(); XmlNodeList nodes = xml.SelectNodes("ObjectLookup"); XmlNode objLookup = nodes[0]; Assert.AreEqual("LDAPAnalyzer", objLookup.Attributes["objectId"].Value); Assert.AreEqual("IsLdapEnabled", objLookup.Attributes["member"].Value); }
public void TestAddPolicySetWindow() { //setup XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.Reset(); IPolicyLanguage language = new PolicyLanguage(new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"), "en"); languageStore.AddLanguage(language); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; catalogueStore.Reset(); PolicyCatalogue policyCatalogue = new PolicyCatalogue(new Guid("{AB5E2A43-01FB-4AA6-98FC-8F74BB0621CA}"), language.Identifier, new TranslateableLanguageItem("{B5C31A66-1B39-4CA7-BF02-AF271B5864F7}"), catalogueStore); catalogueStore.AddPolicyCatalogue(policyCatalogue); IPolicyStore policyStore = new XmlStore(); //try to add two policy sets with the same GUID. Should create two nodes in the tree, each with //unique GUIDs, and with the tree node GUIDs unequal to the policy set GUIDs. This proves we can load two .policy files //each with the same GUID without things screwing up. Guid policySetGuid = new Guid("{8D6C9D98-0B49-4dbe-9AE8-CEE5DC6535BF}"); IPolicySet policySet1 = new PolicySet(policySetGuid, new TranslateableLanguageItem("PolicySet1"), policyStore, policyCatalogue, false); IPolicySet policySet2 = new PolicySet(policySetGuid, new TranslateableLanguageItem("PolicySet2"), policyStore, policyCatalogue, false); PolicySetExplorerForm policySetExplorerForm = new PolicySetExplorerForm(); policySetExplorerForm.AddPolicySetWindow(policySet1, Workshare.Policy.Interfaces.PolicySetVersionStatus.Disabled, "1.0"); policySetExplorerForm.AddPolicySetWindow(policySet2, Workshare.Policy.Interfaces.PolicySetVersionStatus.Disabled, "1.0"); Assert.AreEqual(2, policySetExplorerForm.TreeView.Nodes.Count, "unexpected number of nodes in tree"); Assert.AreNotEqual(((TreeObject)policySetExplorerForm.TreeView.Nodes[0]).Guid, ((TreeObject)policySetExplorerForm.TreeView.Nodes[1]).Guid, ("Treeview node GIUDs match")); Assert.AreNotEqual(policySetGuid, ((TreeObject)policySetExplorerForm.TreeView.Nodes[0]).Guid, ("Treeview node GIUD matches policy set GUID")); Assert.AreNotEqual(policySetGuid, ((TreeObject)policySetExplorerForm.TreeView.Nodes[1]).Guid, ("Treeview node GIUD matches policy set GUID")); }
public void TestPolicyLanguageWhenNoLanguagesLoaded() { PolicyLanguage englishLang = new PolicyLanguage(Guid.NewGuid(), "en"); PolicyLanguageCache.Instance().AddLanguage(englishLang); PolicySet testSet = new PolicySet("This is my PolicySet name"); P5Policy test = new P5Policy(testSet, new Guid("D803727B-5C81-44CC-8BFC-9B68797AC6EB"), "LALALA", PolicyStatus.Active); Assert.AreEqual("LALALA", test.Name); Assert.AreEqual("This is my PolicySet name", testSet.Name); test.Name = "Cool Bananas"; Assert.AreEqual("Cool Bananas", test.Name); }
public IPolicySet ApplyFilter(IPolicySet policySet) { if (null == policySet) return null; // Lets create a dummy catalgue store. Store.XMLPolicyCatalogueStore catalogueStore = new Store.XMLPolicyCatalogueStore(); IPolicyCatalogue reducedCatalogue = new PolicyCatalogue(Guid.NewGuid(), policySet.MasterCatalogue.LanguageId, catalogueStore); Store.XmlStore store = new Store.XmlStore(); m_reducedPolicySet = new PolicySet(policySet.Identifier, policySet.Name, store, reducedCatalogue, policySet.ReadOnly); Dictionary<string, IPolicyLanguageItem>.Enumerator enumerator = policySet.GetAttributeEnumerator(); while (enumerator.MoveNext()) { m_reducedPolicySet[enumerator.Current.Key] = enumerator.Current.Value; } FilterPolicies(policySet); return m_reducedPolicySet; }
public void TestWriteConditionWithParent() { string testCatalogue = m_testPath + "TestRealPolicyCatalogue.xml"; string testLanguage = m_testPath + "TestRealPolicyLanguage.xml"; XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage)); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue)); XmlStore store = new XmlStore(); Store.IPolicyStoreWriter writer = store.Writer; Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer"); ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false); P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active); ICondition condition = new Condition(new Guid("{6B7F6B0C-747A-4BD0-A65D-A1FB9E44FE7C}"), "ITestOne", OperatorType.GreaterThan); condition.DataLeft = new DataElement(new Guid("{5A1A6AE2-C228-4240-B204-B80B8B14889E}"), new TranslateableLanguageItem("Test element"), new TranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new TranslateableLanguageItem(""), DataType.String, "This is data to the left")); condition.DataRight = new DataElement(new Guid("{1EE58193-DA9D-4688-98F8-A76C74E2183E}"), new TranslateableLanguageItem("Test element"), new TranslateableLanguageItem(""), DataType.String, DataItem.CreateDataItem(new TranslateableLanguageItem(""), DataType.String, "This is data to the right")); writer.WritePolicySet(policySet); writer.WritePolicy(policySet, policy); writer.WriteCondition(policySet, policy, condition, ConditionLogic.AND); writer.Close(); TestHelpers.CompareXml(m_testPath + "ExpectedWriteConditionWithParent.xml", store.StoreXML); }
public void TestWriteConditionGroupWithParent() { string testCatalogue = m_testPath + "TestRealPolicyCatalogue.xml"; string testLanguage = m_testPath + "TestRealPolicyLanguage.xml"; XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage)); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue)); XmlStore store = new XmlStore(); Store.IPolicyStoreWriter writer = store.Writer; Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer"); ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false); P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active); IConditionGroup conditionGroup = new ConditionGroup(new Guid("{661EDD6F-D750-493A-9932-E56C8C22E2CF}"), new TranslateableLanguageItem("{55FB0DE7-DCAF-47CF-A1F3-1F93E8AC1EE7}"), ConditionLogic.AND, false); writer.WritePolicySet(policySet); writer.WritePolicy(policySet, policy); writer.WriteConditionGroup(policySet, policy, conditionGroup); writer.Close(); TestHelpers.CompareXml(m_testPath + "ExpectedWriteConditionGroupWithParent.xml", store.StoreXML); }
public void TestWriteRule() { string testCatalogue = m_testPath + "TestRealPolicyCatalogue.xml"; string testLanguage = m_testPath + "TestRealPolicyLanguage.xml"; XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage)); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue)); XmlStore store = new XmlStore(); Store.IPolicyStoreWriter writer = store.Writer; Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer"); ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false); writer.WritePolicySet(policySet); ICataloguePolicy cataloguePolicy = new CataloguePolicy(new Guid("{8E915159-5F01-41B3-9FFF-20731544ADFA}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Disabled); writer.WritePolicy(policySet, cataloguePolicy); writer.Close(); TestHelpers.CompareXml(m_testPath + "ExpectedWriteRule.xml", store.StoreXML); }
public void TestCreatePolicy() { //setup XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.Reset(); IPolicyLanguage language = new PolicyLanguage(new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"), "en"); languageStore.AddLanguage(language); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; catalogueStore.Reset(); PolicyCatalogue policyCatalogue = new PolicyCatalogue(new Guid("{AB5E2A43-01FB-4AA6-98FC-8F74BB0621CA}"), language.Identifier, new TranslateableLanguageItem("{B5C31A66-1B39-4CA7-BF02-AF271B5864F7}"), catalogueStore); catalogueStore.AddPolicyCatalogue(policyCatalogue); IPolicyStore policyStore = new XmlStore(); IPolicySet policySet = new PolicySet(Guid.NewGuid(), new TranslateableLanguageItem("TestPolicySet"), policyStore, policyCatalogue, false); IPolicy policy = PolicyFactory.CreatePolicy("TestPolicy", policySet, PolicyStatus.Active, "None"); //tests //policy Assert.AreEqual("TestPolicy", policy.Name.Value, "Incorrect name on policy"); Assert.AreEqual(false, policy.ReadOnly, "Incorrect readonly on policy"); Assert.AreEqual(PolicyStatus.Active, policy.Status, "Incorrect status on policy"); Assert.AreEqual("None", policy["AuditLevel"].Value, "Incorrect auditlevel on policy"); Assert.AreEqual(5, policy.Channels.Count, "Incorrect number of channels on policy"); Assert.AreEqual(1, policy.Conditions.Count, "Incorrect number of conditions on policy"); //policy.Conditions[0] IConditionGroup conditionGroup = policy.Conditions[0] as IConditionGroup; Assert.AreEqual("Default Condition Group", conditionGroup.Name.Value, "Incorrect name on policy.condition[0]"); Assert.AreEqual(ConditionLogic.AND, conditionGroup.Logic, "Incorrect logic on policy.condition[0]"); Assert.AreEqual(0, conditionGroup.Conditions.Count, "Incorrect number of conditions on policy.condition[0]"); //policy.channel[0] IPolicyChannel channel = policy.Channels[0]; Assert.AreEqual("SMTP", channel.Name.Value, "Incorrect name on policy.channel[0]"); Assert.AreEqual(ChannelType.SMTP, channel.Type, "Incorrect type on policy.channel[0]"); //policy.channel[1] channel = policy.Channels[1]; Assert.AreEqual("HTTP", channel.Name.Value, "Incorrect name on policy.channel[1]"); Assert.AreEqual(ChannelType.HTTP, channel.Type, "Incorrect type on policy.channel[1]"); //policy.channel[2] channel = policy.Channels[2]; Assert.AreEqual("ActiveContent", channel.Name.Value, "Incorrect name on policy.channel[2]"); Assert.AreEqual(ChannelType.ActiveContent, channel.Type, "Incorrect type on policy.channel[2]"); //policy.channel[3] channel = policy.Channels[3]; Assert.AreEqual("RemoveableDevice", channel.Name.Value, "Incorrect name on policy.channel[3]"); Assert.AreEqual(ChannelType.RemoveableDevice, channel.Type, "Incorrect type on policy.channel[3]"); //policy.channel[4] channel = policy.Channels[4]; Assert.AreEqual("Mta", channel.Name.Value, "Incorrect name on policy.channel[4]"); Assert.AreEqual(ChannelType.Mta, channel.Type, "Incorrect type on policy.channel[4]"); }
public void TestCreatePolicySetConditionsMasterCatalogue() { string testCatalogue = m_testPath + "TestCreatePolicySetConditionsMasterCatalogue.xml"; string languageFilename = m_testPath + "TestCreatePolicySetConditionsMasterCatalogueLanguage.xml"; string policySetFilename = m_testPath + "TestCreatePolicySetConditionsMasterCataloguePolicySet.xml"; XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.Reset(); Guid languageId = new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"); IPolicyLanguage language = new PolicyLanguage(languageId, "en"); language.DefaultLanguage = true; languageStore.AddLanguage(language); PolicyLanguageCache policyLanguageCache = PolicyLanguageCache.Instance; policyLanguageCache.SetLanguageItemText(languageId, new Guid("{B5C31A66-1B39-4CA7-BF02-AF271B5864F7}"), "New catalogue"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{9465CA41-A0A1-40BD-BE26-E83E17D83148}"), "New policy set"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{08BC5764-4879-42ED-9AD8-15040C4ADEDE}"), "New policy"); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; catalogueStore.Reset(); PolicyCatalogue policyCatalogue = new PolicyCatalogue(new Guid("{AB5E2A43-01FB-4AA6-98FC-8F74BB0621CA}"), language.Identifier, new TranslateableLanguageItem("{B5C31A66-1B39-4CA7-BF02-AF271B5864F7}"), catalogueStore); catalogueStore.AddPolicyCatalogue(policyCatalogue); IPolicyStore policyStore = new XmlStore(); IPolicySet policySet = new PolicySet(new Guid("{29EC30A5-1271-4306-89C8-5811172D901A}"), new TranslateableLanguageItem("{9465CA41-A0A1-40BD-BE26-E83E17D83148}"), policyStore, policyCatalogue, false); IPolicy newPolicy = new P5Policy(policySet, new Guid("{D257D4DC-4A12-438F-A32A-CF1CE4474441}"), new TranslateableLanguageItem("{08BC5764-4879-42ED-9AD8-15040C4ADEDE}"), PolicyStatus.Active); policySet.Policies.Add(newPolicy); // Create a condition group for the policy. policyLanguageCache.SetLanguageItemText(languageId, new Guid("{8EB7FF08-1DC8-4F11-9D55-AF47F83F843A}"), "Test condition group"); IConditionGroup conditionGroup = new ConditionGroup(new Guid("{B87DF614-2400-4C1F-BEA8-3C2EB3964EAE}"), new TranslateableLanguageItem("{8EB7FF08-1DC8-4F11-9D55-AF47F83F843A}"), ConditionLogic.AND, false); newPolicy.Conditions.Add(conditionGroup); // Create a condition for the condition group. policyLanguageCache.SetLanguageItemText(languageId, new Guid("{EC8E1E63-7097-4330-8130-5776D4FDF1ED}"), "Test condition"); ICondition condition = new Condition(new Guid("{98C73BC3-3E20-403C-8023-C91E2818355F}"), "TestClass", new TranslateableLanguageItem("{EC8E1E63-7097-4330-8130-5776D4FDF1ED}"), OperatorType.Equals); conditionGroup.Conditions.Add(condition); // Create the data left for the condition data. DataMethod dataMethod = new DataMethod("ThisIsATest"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{BA56AB4C-43D0-465A-BE67-D8A569A1894C}"), "Test data item to the left"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{AB454A4B-1A0F-4864-9F46-3AAC8A34ACA5}"), "Test parameter data element"); DataElement parameterDataElement = new DataElement(new Guid("{015035B7-1793-464D-AF69-030E9DC7151E}"), new TranslateableLanguageItem("{AB454A4B-1A0F-4864-9F46-3AAC8A34ACA5}"), new NonTranslateableLanguageItem(""), DataType.String, "Lets go dynamo"); dataMethod.Parameters.Add(new Parameter("somethingTerrible", parameterDataElement)); IDataSource dataSource = new DataSource("ThisIsADodgyAssembly.dll", "ItWantsToTakeOverYourComputer", dataMethod); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{79784B11-5FCC-47A8-A35E-C8399BE71C05}"), "Test data left"); condition.DataLeft = new DataElement(new Guid("{454672AC-BCED-4DAB-813F-6CF14E6289C5}"), new TranslateableLanguageItem("{79784B11-5FCC-47A8-A35E-C8399BE71C05}"), new NonTranslateableLanguageItem(""), DataType.Object, dataSource); // Create the data right for the condition data. policyLanguageCache.SetLanguageItemText(languageId, new Guid("{BD40DDEE-B045-4D3B-8092-D596329230FE}"), "Test data item to the right"); IDataItem dataRightDataItem = DataItem.CreateDataItem(new TranslateableLanguageItem("{BD40DDEE-B045-4D3B-8092-D596329230FE}"), DataType.String, "This is a test"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{8549333F-0A4D-4939-8A36-36FB0FF1C89A}"), "Test data right"); condition.DataRight = new DataElement(new Guid("{4E2F50C5-D310-47A1-AE3A-621F5C77FA68}"), new TranslateableLanguageItem("{8549333F-0A4D-4939-8A36-36FB0FF1C89A}"), new NonTranslateableLanguageItem(""), DataType.String, dataRightDataItem); // Save everything IPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(policyCatalogue.Identifier, language.Identifier); catalogueWriter.WriteCatalogue(policyCatalogue); catalogueWriter.Close(); policySet.Save(); TestHelpers.CompareXml(policySetFilename, policyStore.XMLRepresentation); TestHelpers.CompareXml(testCatalogue, catalogueStore.GetStoreXML(policySet.MasterCatalogue.Identifier)); TestHelpers.CompareXml(languageFilename, languageStore.GetXMLRepresentation(language.Identifier, language.Name.Value)); }
public void TestActionExceptionHandlerWithOffline() { string testCatalogue = m_testPath + "TestActionExceptionHandlerWithOffline.Catalogue.xml"; string testLanguage = m_testPath + "TestActionExceptionHandlerWithOffline.Language.xml"; Guid languageId = XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage)); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue)); XmlStore store = new XmlStore(); ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false); P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active); IPolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>(); PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.SMTP); // Build the ActionException cell for the action matrix. IActionMatrix actions = new ObjectModel.ActionMatrix(); ActionExceptionCell actionExceptionCell = actions.ActionExceptionHandler as ObjectModel.ActionExceptionCell; Assert.IsNotNull(actionExceptionCell); OfflineActionMatrixCell offlineCell = actions.Offline as OfflineActionMatrixCell; ConditionGroup conditionGroup = new ConditionGroup(new Guid("{661EDD6F-D750-493A-9932-E56C8C22E2CF}"), new TranslateableLanguageItem("Test condition group"), ConditionLogic.AND, false); ICondition subCondition = new Condition(new Guid("{6B7F6B0C-747A-4BD0-A65D-A1FB9E44FE7C}"), "ITestOne", OperatorType.GreaterThan); DataMethod dataMethod = new DataMethod("Test method"); dataMethod.Parameters.Add(new Parameter("FindSomething", new DataElement(new TranslateableLanguageItem("string value"), new TranslateableLanguageItem(""), DataType.String, "missing"))); dataMethod.Parameters.Add(new Parameter("RunSomething", new DataElement(new TranslateableLanguageItem("string value"), new TranslateableLanguageItem(""), DataType.String, "just do it!"))); DataSource dataSource = new DataSource("Testme.dll", "TestMe", dataMethod); subCondition.DataLeft = new DataElement(new Guid("{4E2F50C5-D310-47A1-AE3A-621F5C77FA68}"), new TranslateableLanguageItem("Do testing stuff"), new TranslateableLanguageItem(""), DataType.Object, dataSource); IDataItem dataItem = DataItem.CreateDataItem(new TranslateableLanguageItem("Test data item"), DataType.Long, "10"); subCondition.DataRight = new DataElement(new Guid("{EB56B397-954D-45C2-ADBA-263372A8B59F}"), new TranslateableLanguageItem("Test data item stored in data element"), new TranslateableLanguageItem(""), DataType.Long, dataItem); conditionGroup.Conditions.Add(subCondition); policy.Conditions.Add(conditionGroup); actionExceptionCell.AddActionCondition(conditionGroup, BuildActionGroup(), false); channel.Actions = actions; channels.Add(channel); policy.Channels = channels; Store.IPolicyStoreWriter writer = store.Writer; Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer"); writer.WritePolicySet(policySet); writer.WritePolicy(policySet, policy); writer.WriteChildCollection(policySet, policy, policy.Name.Value, policy.Conditions); writer.WriteChildCollection(policySet, policy, policy.Name.Value, CollectionConverter.Convert<IPolicyChannel, IPolicyObject>(channels)); writer.Close(); string expectedPolicySetFile = m_testPath + "TestActionExceptionHandlerWithOffline.PolicySet.xml"; TestHelpers.CompareXml(expectedPolicySetFile, store.StoreXML); }
public void TestWriteHttpOfflineRouting() { string testCatalogue = m_testPath + "TestHttpOfflineRouting.Catalogue.xml"; string testLanguage = m_testPath + "TestHttpOfflineRouting.Language.xml"; Guid languageId = XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage)); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue)); XmlStore store = new XmlStore(); Store.IPolicyStoreWriter writer = store.Writer; Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer"); ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false); P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active); IPolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>(); PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.HTTP); IRoutingTable routings = new RoutingTable(new Guid("{AF6E5D89-0C6F-4B10-9A6C-658D13CD3EA8}"), new TranslateableLanguageItem("{8819B8B3-38AE-4D89-A05C-AB0904E979D1}"), ChannelType.HTTP); IRoutingItemCollection defaultSender = routings.DefaultSource; IRoutingItemCollection defaultRecipient = routings.DefaultDestination; IRoutingMatrixCell routingCell = routings[defaultSender, defaultRecipient]; IRoutingOfflineCell offlineCell = routings.Offline; // The offline cell will get creates the first time this is called channel.Routing = routings; channels.Add(channel); policy.Channels = channels; // Persist the changes to the catalogue. IPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(policyCatalogue.Identifier, languageId); catalogueWriter.WriteName(policyCatalogue.Name.Identifier.ToString("B").ToUpper()); catalogueWriter.WriteCatalogue(policyCatalogue); catalogueWriter.Close(); string expectedCatalogueFile = m_testPath + "TestHttpOfflineRouting.Catalogue.Modified.xml"; string expectedCatalogue = System.IO.File.ReadAllText(expectedCatalogueFile); expectedCatalogue = expectedCatalogue.Replace("{91FDC9A5-CEA5-4A9C-BB58-576F57B1C329}", offlineCell.Name.Identifier.ToString("B").ToUpper()); expectedCatalogue = expectedCatalogue.Replace("{E088C5CD-F5C9-48D5-9D3F-459A5D4BAB84}", offlineCell.Description.Identifier.ToString("B").ToUpper()); expectedCatalogue = expectedCatalogue.Replace("{73B623E3-7D1A-470B-9C3A-BCE2B4D2B3CD}", defaultSender.Identifier.ToString("B").ToUpper()); expectedCatalogue = expectedCatalogue.Replace("{0FC0FBD3-FC51-4D19-B7CE-04C6A5447E8C}", defaultSender.Name.Identifier.ToString("B").ToUpper()); expectedCatalogue = expectedCatalogue.Replace("{E811E002-16F5-41B6-877E-6C7741529965}", defaultRecipient.Identifier.ToString("B").ToUpper()); expectedCatalogue = expectedCatalogue.Replace("{3D594866-8C44-4896-91FD-A549B6481722}", defaultRecipient.Name.Identifier.ToString("B").ToUpper()); expectedCatalogue = expectedCatalogue.Replace("{6ACC2C34-071A-445E-88A2-4C5B94452E5B}", routingCell.Name.Identifier.ToString("B").ToUpper()); expectedCatalogue = expectedCatalogue.Replace("{1BE90656-9FF3-4747-960D-176E6183C673}", routingCell.Description.Identifier.ToString("B").ToUpper()); expectedCatalogueFile = expectedCatalogueFile + ".tmp"; System.IO.File.WriteAllText(expectedCatalogueFile, expectedCatalogue); TestHelpers.CompareXml(expectedCatalogueFile, catalogueStore.GetStoreXML(policyCatalogue.Identifier)); }
public void TestWriteRuleHttpRouting() { string testLanguage = m_testPath + "TestHttpRoutingLanguage.xml"; Guid languageId = XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage)); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; PolicyCatalogue policyCatalogue = new PolicyCatalogue(new Guid("{E4C8224A-4CBC-4BFF-B50E-A7E60AAABCFD}"), languageId, catalogueStore); policyCatalogue.Name = new TranslateableLanguageItem("{3DDE25D7-E892-430D-A85C-075EBA5535AC}"); catalogueStore.AddPolicyCatalogue(policyCatalogue); XmlStore store = new XmlStore(); ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false); P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active); IPolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>(); PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.HTTP); RoutingTable routing = RoutingTableFactory.Instance.Create(ChannelType.HTTP, new Guid("{8B097CCF-02C8-40C4-9866-AD6EC09C5AB2}"), new NonTranslateableLanguageItem("Test active content routing"), false) as RoutingTable; Assert.IsNotNull(routing); IRoutingItemCollection defaultRecipient = routing.DefaultDestination; Assert.IsNotNull(defaultRecipient); IRoutingItemCollection defaultSender = routing.DefaultSource; Assert.IsNotNull(defaultSender); IRoutingMatrixCell routingCell = routing[defaultSender, defaultRecipient]; Assert.IsNotNull(routingCell); channel.Routing = routing; channels.Add(channel); policy.Channels = channels; Store.IPolicyStoreWriter writer = store.Writer; Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer"); writer.WritePolicySet(policySet); writer.WritePolicy(policySet, policy); writer.WriteChildCollection(policySet, policy, policy.Name.Value, CollectionConverter.Convert<IPolicyChannel, IPolicyObject>(channels)); writer.Close(); TestHelpers.CompareXml(m_testPath + "TestHttpRoutingPolicySet.xml", store.StoreXML); string expectedCatalogue = System.IO.File.ReadAllText(m_testPath + "TestHttpRoutingCatalogue.xml"); expectedCatalogue = expectedCatalogue.Replace("{A176A59A-8AFB-4820-B7D4-4074B64C9F14}", defaultSender.Identifier.ToString("B").ToUpper()); expectedCatalogue = expectedCatalogue.Replace("{14C8BE82-D52D-4CE3-9131-FBEA60C88731}", defaultRecipient.Identifier.ToString("B").ToUpper()); expectedCatalogue = expectedCatalogue.Replace("{6ACC2C34-071A-445E-88A2-4C5B94452E5B}", routingCell.Name.Identifier.ToString("B").ToUpper()); expectedCatalogue = expectedCatalogue.Replace("{ABBFAC23-846B-42D8-BA14-84CB9E5A095A}", routingCell.Description.Identifier.ToString("B").ToUpper()); expectedCatalogue = expectedCatalogue.Replace("{6D82D228-A194-4F00-BEE1-DF01368E572F}", defaultSender.Name.Identifier.ToString("B").ToUpper()); expectedCatalogue = expectedCatalogue.Replace("{7EC9EBD4-67B3-42C3-A750-12CFC9B4DFD0}", defaultRecipient.Name.Identifier.ToString("B").ToUpper()); string catalogueFile = m_testPath + "TestHttpRoutingCatalogue.xml.tmp"; System.IO.File.WriteAllText(catalogueFile, expectedCatalogue); // Persist the changes to the catalogue. IPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(policyCatalogue.Identifier, languageId); catalogueWriter.WriteName(policyCatalogue.Name.Identifier.ToString("B").ToUpper()); catalogueWriter.WriteCatalogue(policyCatalogue); catalogueWriter.Close(); TestHelpers.CompareXml(catalogueFile, catalogueStore.GetStoreXML(policyCatalogue.Identifier)); }
public void TestWriteChildCollectionRuleConditions() { string testCatalogue = m_testPath + "TestRealPolicyCatalogue.xml"; string testLanguage = m_testPath + "TestRealPolicyLanguage.xml"; XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage)); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue)); XmlStore store = new XmlStore(); Store.IPolicyStoreWriter writer = store.Writer; Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer"); ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false); P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active); IPolicyObjectCollection<IPolicyObject> conditions = BuildConditions(); writer.WritePolicySet(policySet); writer.WritePolicy(policySet, policy); writer.WriteChildCollection(policySet, policy, "Copy of test rule", conditions); writer.Close(); TestHelpers.CompareXml(m_testPath + "ExpectedWriteChildCollectionRuleConditions.xml", store.StoreXML); }
public void TestWritePolicies() { Guid languageGuid = new Guid("{054846D4-6540-4C78-BA7D-141C91EE6A4C}"); IPolicyLanguage language = new PolicyLanguage(languageGuid, "en"); language[new Guid("{84DCA455-723A-4F30-8B5A-26A20E0CBE45}")] = "Test policy"; language[new Guid("{31060488-7C3C-41BF-BD08-188796288AE0}")] = "Test rule"; language[new Guid("{6AD791C1-5403-488F-8AD9-D6CEAE79DC3E}")] = "Test rule 2"; XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.AddLanguage(language); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; catalogueStore.Reset(); XmlStore store = new XmlStore(); Guid catalogueId = new Guid("{B496E117-29DA-4770-87E9-62573B28BB4F}"); IPolicyCatalogue policyCatalogue = new PolicyCatalogue(catalogueId, language.Identifier, catalogueStore); XmlPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(catalogueId, languageGuid) as XmlPolicyCatalogueWriter; Assert.IsNotNull(catalogueWriter, "Expected a valid [IPolicyStoreWriter] writer"); catalogueWriter.WriteName("{D0FE23B8-B8A0-4DD6-A0F1-A7836DC0417E}"); ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{0A62F323-CB79-47ED-A83D-67A9B2E032D7}"), new TranslateableLanguageItem("{84DCA455-723A-4F30-8B5A-26A20E0CBE45}"), store, policyCatalogue, false); string ruleGuid = "{8E915159-5F01-41B3-9FFF-20731544ADFA}"; P5Policy policy = new P5Policy(store, policySet, new Guid(ruleGuid), new TranslateableLanguageItem("{31060488-7C3C-41BF-BD08-188796288AE0}"), PolicyStatus.Active); catalogueWriter.WriteCataloguePolicy(policy); ruleGuid = "{33AF2331-C69D-44EE-85F7-56188938BD9B}"; policy = new P5Policy(store, policySet, new Guid(ruleGuid), new TranslateableLanguageItem("{6AD791C1-5403-488F-8AD9-D6CEAE79DC3E}"), PolicyStatus.Active); catalogueWriter.WriteCataloguePolicy(policy); catalogueWriter.Close(); TestHelpers.CompareXml(m_testPath + "ExpectedWriteRules.xml", catalogueStore.GetStoreXML(catalogueId)); }
public void TestWriteRoutingMatrixCellAttributes() { Guid languageId = new Guid("{CBEB31FA-7FE8-4E27-A01A-1D19AFCA604C}"); PolicyLanguage language = new PolicyLanguage(languageId, "en"); language[new Guid("{B067FF7F-2DA0-4AA1-A69F-DEFCD8B4CE90}")] = "Custom routing"; language[new Guid("{8809EBFF-D902-4C91-BE56-1ABD13C054A1}")] = "Test policy"; language[new Guid("{EBF8443B-4912-44F2-89BE-A0A055332D1B}")] = "This is my first custom property"; language[new Guid("{8053E60C-EED7-464D-84EA-ECB51C291237}")] = "This is my second custom property"; XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.AddLanguage(language); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; Guid catalogueGuid = new Guid("{751AEC6C-C164-4E6A-8581-A9ECCED87013}"); PolicyCatalogue policyCatalogue = new PolicyCatalogue(catalogueGuid, languageId, catalogueStore); IRoutingItemCollection senders1 = new RoutingItemCollection(new Guid("{79C512E8-3912-4709-B7D7-E91EFA3BD9FD}"), "Test sources"); IRoutingItemCollection recipients1 = new RoutingItemCollection(new Guid("{FDC166E4-EBE5-4285-8F09-6A145D88C707}"), "Test destinations"); IRoutingMatrixCell cell1 = new RoutingMatrixCell(new TranslateableLanguageItem("C1"), new TranslateableLanguageItem("Description of the blue cell"), new TranslateableLanguageItem("blue"), 1, senders1, recipients1); cell1["custom1"] = new TranslateableLanguageItem("{EBF8443B-4912-44F2-89BE-A0A055332D1B}"); cell1["custom2"] = new TranslateableLanguageItem("{8053E60C-EED7-464D-84EA-ECB51C291237}"); IRoutingMatrixCell cell2 = new RoutingMatrixCell(new TranslateableLanguageItem("C2"), new TranslateableLanguageItem("Description of the red cell"), new TranslateableLanguageItem("red"), 2, senders1, recipients1); IRoutingMatrixCell cell3 = new RoutingMatrixCell(new TranslateableLanguageItem("C3"), new TranslateableLanguageItem("Description of the green cell"), new TranslateableLanguageItem("green"), 3, senders1, recipients1); RoutingTable routingTable = new RoutingTable(new Guid("{AF6E5D89-0C6F-4B10-9A6C-658D13CD3EA8}"), new TranslateableLanguageItem("{B067FF7F-2DA0-4AA1-A69F-DEFCD8B4CE90}"), ChannelType.SMTP); routingTable["{A81631A6-6AA3-45F7-AADD-4853447E5BD6}", "{D23F36C4-953F-4ED9-B1EB-8921BD50562B}"] = cell1; routingTable["{FA13BE82-9EB1-407E-9DD5-8005F3E840E4}", "{4E1B9EAB-E892-4E47-BBE6-9D70B2438333}"] = cell2; routingTable["{3AD507B6-5E1E-44BB-9ABF-C27A31603C1B}", "{D23F36C4-953F-4ED9-B1EB-8921BD50562B}"] = cell3; XmlStore store = new XmlStore(); ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{8809EBFF-D902-4C91-BE56-1ABD13C054A1}"), store, policyCatalogue, false); P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("Test rule"), PolicyStatus.Active); IPolicyObjectCollection<IPolicyObject> channels = new PolicyObjectCollection<IPolicyObject>(); PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("Test channel"), ChannelType.SMTP); channel.Routing = routingTable; channels.Add(channel); Store.IPolicyStoreWriter writer = store.Writer; Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer"); writer.WritePolicySet(policySet); writer.WritePolicy(policySet, policy); writer.WriteChildCollection(policySet, policy, policy.Name.Value, channels); writer.Close(); TestHelpers.CompareXml(m_testPath + "ExpectedWriteRoutingMatrixCellAttributes.xml", store.StoreXML); }
public void TestWriteActionMatrixAttributes() { Guid languageId = new Guid("{CBEB31FA-7FE8-4E27-A01A-1D19AFCA604C}"); PolicyLanguage language = new PolicyLanguage(languageId, "en"); language[new Guid("{B067FF7F-2DA0-4AA1-A69F-DEFCD8B4CE90}")] = "Test condition"; language[new Guid("{5570ABC5-188E-4893-92E4-6930802F9C05}")] = "Test policy"; language[new Guid("{EBF8443B-4912-44F2-89BE-A0A055332D1B}")] = "This is my first custom property"; language[new Guid("{8053E60C-EED7-464D-84EA-ECB51C291237}")] = "This is my second custom property"; XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.AddLanguage(language); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; Guid catalogueGuid = new Guid("{751AEC6C-C164-4E6A-8581-A9ECCED87013}"); PolicyCatalogue policyCatalogue = new PolicyCatalogue(catalogueGuid, languageId, catalogueStore); IDataItem dataItem = DataItem.CreateDataItem(new TranslateableLanguageItem("Test data item"), DataType.Long, 10); ObjectModel.IAction action = new ObjectModel.Action(new Guid("{26BCFA7E-3605-4EE7-ACC6-0AFB4D5EBB71}"), "CustomAction.dll", "Test.Clean", RunAt.Client, false, 1); //TODO JE action.DataElements.Add(new DataElement(new Guid("{EB56B397-954D-45C2-ADBA-263372A8B59F}"), new TranslateableLanguageItem("Test data item stored in data element"), new NonTranslateableLanguageItem(""), DataType.Long, dataItem)); ActionGroup actionGroup = new ObjectModel.ActionGroup(new Guid("{987B7C8B-5ADD-4696-8456-DDE11D95CE0B}"), new TranslateableLanguageItem("Test action group"), 1); actionGroup.Actions.Add(action); ActionMatrix actionMatrix = new ObjectModel.ActionMatrix(); ConditionGroup conditionGroup = new ConditionGroup(new Guid("{661EDD6F-D750-493A-9932-E56C8C22E2CF}"), new TranslateableLanguageItem("Profanity"), ConditionLogic.OR, false); IRoutingItemCollection senders = new RoutingItemCollection(new Guid("{79C512E8-3912-4709-B7D7-E91EFA3BD9FD}"), "Test sources"); IRoutingItemCollection recipients = new RoutingItemCollection(new Guid("{FDC166E4-EBE5-4285-8F09-6A145D88C707}"), "Test destinations"); ActionMatrixCell actionMatrixCell = new ObjectModel.ActionMatrixCell(senders, recipients); actionMatrixCell.AddActionCondition(conditionGroup, actionGroup, false); actionMatrix["{A81631A6-6AA3-45F7-AADD-4853447E5BD6}", "{D23F36C4-953F-4ED9-B1EB-8921BD50562B}"] = actionMatrixCell; actionMatrix["custom1"] = new TranslateableLanguageItem("{EBF8443B-4912-44F2-89BE-A0A055332D1B}"); actionMatrix["custom2"] = new TranslateableLanguageItem("{8053E60C-EED7-464D-84EA-ECB51C291237}"); IPolicyObjectCollection<IActionMatrix> actions = new PolicyObjectCollection<IActionMatrix>(); actions.Add(actionMatrix); PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("Test channel"), ChannelType.SMTP); channel.Actions = actionMatrix; IPolicyObjectCollection<IPolicyObject> channels = new PolicyObjectCollection<IPolicyObject>(); channels.Add(channel); XmlStore store = new XmlStore(); ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{5570ABC5-188E-4893-92E4-6930802F9C05}"), store, policyCatalogue, false); P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("Test policy"), PolicyStatus.Active); IPolicyStoreWriter writer = store.Writer; writer.WritePolicySet(policySet); writer.WritePolicy(policySet, policy); writer.WriteConditionGroup(policySet, policy, conditionGroup); writer.WriteChildCollection(policySet, policy, policy.Name.Value, channels); writer.Close(); TestHelpers.CompareXml(m_testPath + "ExpectedWriteActionMatrixAttributes.xml", store.StoreXML); }
public void TestWriteChildCollectionRuleChannels() { string testCatalogue = m_testPath + "TestRealPolicyCatalogue.xml"; string testLanguage = m_testPath + "TestRealPolicyLanguage.xml"; XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage)); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue)); XmlStore store = new XmlStore(); Store.IPolicyStoreWriter writer = store.Writer; Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer"); ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false); P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active); IPolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>(); PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.SMTP); channel.Actions = BuildActionMatrix(policy, false); channel.Routing = BuildSmtpRouting(); channels.Add(channel); writer.WritePolicySet(policySet); writer.WritePolicy(policySet, policy); writer.WriteChildCollection(policySet, policy, null, policy.Conditions); writer.WriteChildCollection(policySet, policy, "Copy of test rule", CollectionConverter.Convert<IPolicyChannel, IPolicyObject>(channels)); writer.Close(); TestHelpers.CompareXml(m_testPath + "ExpectedWriteChildCollectionRuleChannels.xml", store.StoreXML); }
public void Test08_GetDefaultAddressCollectionName() { XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.Reset(); IPolicyLanguage language = new PolicyLanguage(new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"), "en"); languageStore.AddLanguage(language); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; catalogueStore.Reset(); PolicyCatalogue policyCatalogue = new PolicyCatalogue(new Guid("{AB5E2A43-01FB-4AA6-98FC-8F74BB0621CA}"), language.Identifier, new TranslateableLanguageItem("{B5C31A66-1B39-4CA7-BF02-AF271B5864F7}"), catalogueStore); catalogueStore.AddPolicyCatalogue(policyCatalogue); IPolicyStore policyStore = new XmlStore(); IPolicySet policySet = new PolicySet(Guid.NewGuid(), new TranslateableLanguageItem("TestPolicySet"), policyStore, policyCatalogue, false); IPolicy policy = PolicyFactory.CreatePolicy("TestPolicy", policySet, PolicyStatus.Active, "None"); IRoutingTable routingTable = policy.Channels[3].Routing; Assert.IsNotNull(routingTable, "Expected the routing table type to be SMTP"); string defaultName = AddressSearchHelper.Instance.GetDefaultAddressCollectionName(); Assert.AreEqual(Properties.Resources.IDS_DEFAULT_ADDRESSGROUPNAME + Convert.ToString(1), defaultName); RoutingItemCollection addressCollection = new RoutingItemCollection(Guid.NewGuid(), defaultName); RoutingHelper.AddCollectionToAddressGroup(policy.Channels[3].Routing, routingTable.Destinations, addressCollection); defaultName = AddressSearchHelper.Instance.GetDefaultAddressCollectionName(); Assert.AreEqual(Properties.Resources.IDS_DEFAULT_ADDRESSGROUPNAME + Convert.ToString(2), defaultName); }
public void TestWriteSmtpOfflineRouting() { string testCatalogue = m_testPath + "TestSmtpOfflineRouting.Catalogue.xml"; string testLanguage = m_testPath + "TestSmtpOfflineRouting.Language.xml"; Guid languageId = XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage)); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue)); XmlStore store = new XmlStore(); Store.IPolicyStoreWriter writer = store.Writer; Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer"); ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false); P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active); IPolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>(); PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.SMTP); IRoutingTable routings = new RoutingTable(new Guid("{AF6E5D89-0C6F-4B10-9A6C-658D13CD3EA8}"), new TranslateableLanguageItem("{8819B8B3-38AE-4D89-A05C-AB0904E979D1}"), ChannelType.SMTP); IRoutingOfflineCell offlineCell = routings.Offline; // The offline cell will get creates the first time this is called channel.Routing = routings; channels.Add(channel); policy.Channels = channels; // Persist the changes to the catalogue. IPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(policyCatalogue.Identifier, languageId); catalogueWriter.WriteName(policyCatalogue.Name.Identifier.ToString("B").ToUpper()); catalogueWriter.WriteCatalogue(policyCatalogue); catalogueWriter.Close(); string expectedCatalogueFile = m_testPath + "TestSmtpOfflineRouting.Catalogue.Modified.xml"; string expectedCatalogue = System.IO.File.ReadAllText(expectedCatalogueFile); expectedCatalogue = expectedCatalogue.Replace("{91FDC9A5-CEA5-4A9C-BB58-576F57B1C329}", offlineCell.Name.Identifier.ToString("B").ToUpper()); expectedCatalogue = expectedCatalogue.Replace("{E088C5CD-F5C9-48D5-9D3F-459A5D4BAB84}", offlineCell.Description.Identifier.ToString("B").ToUpper()); expectedCatalogueFile = expectedCatalogueFile + ".tmp"; System.IO.File.WriteAllText(expectedCatalogueFile, expectedCatalogue); TestHelpers.CompareXml(expectedCatalogueFile, catalogueStore.GetStoreXML(policyCatalogue.Identifier)); }
public void TestWriteReadOnlyChannelActions() { string testCatalogue = m_testPath + "TestRealPolicyCatalogue.xml"; string testLanguage = m_testPath + "TestRealPolicyLanguage.xml"; XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage)); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue)); XmlStore store = new XmlStore(); Store.IPolicyStoreWriter writer = store.Writer; Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer"); ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false); P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active); IPolicyObjectCollection<IPolicyObject> channels = new PolicyObjectCollection<IPolicyObject>(); PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.SMTP); channel.Actions = BuildActionMatrix(policy, false); Dictionary<KeyValuePair<Guid, Guid>, IActionMatrixCell>.Enumerator actionMatrixEnumerator = channel.Actions.GetEnumerator(); actionMatrixEnumerator.MoveNext(); IActionMatrixCell actionMatrixCell = actionMatrixEnumerator.Current.Value; IActionConditionGroup actionConditionGroup = actionMatrixCell.ActionConditionGroups[0]; ObjectModel.Action action = actionConditionGroup.ActionGroup.ActionGroups[0].Actions[0] as ObjectModel.Action; actionConditionGroup.ActionGroup.ActionGroups[0].Actions.RemoveAt(0); actionConditionGroup.ActionGroup.ActionGroups[0].Actions.Insert(0, action.DeepCopy(true)); channels.Add(channel); writer.WritePolicySet(policySet); writer.WritePolicy(policySet, policy); writer.WriteChildCollection(policySet, policy, policy.Name.Value, channels); writer.Close(); TestHelpers.CompareXml(m_testPath + "ExpectedWriteReadOnlyChannelActions.xml", store.StoreXML); }
public void TestWriteHttpOfflineNoActions() { string testCatalogue = m_testPath + "TestHttpOfflineRouting.Catalogue.xml"; string testLanguage = m_testPath + "TestHttpOfflineRouting.Language.xml"; Guid languageId = XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage)); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue)); XmlStore store = new XmlStore(); ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false); P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active); IPolicyObjectCollection<IPolicyChannel> channels = new PolicyObjectCollection<IPolicyChannel>(); PolicyChannel channel = new PolicyChannel(new Guid("{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.HTTP); // Build the offline cell for the action matrix. IActionMatrix actions = new ObjectModel.ActionMatrix(); OfflineActionMatrixCell offlineCell = actions.Offline as OfflineActionMatrixCell; Assert.IsNotNull(offlineCell); ConditionGroup conditionGroup = new ConditionGroup(new Guid("{661EDD6F-D750-493A-9932-E56C8C22E2CF}"), new NonTranslateableLanguageItem("Test condition group"), ConditionLogic.AND, false); policy.Conditions.Add(conditionGroup); offlineCell.AddActionCondition(conditionGroup, BuildActionGroupNoActions(), false); channel.Actions = actions; channels.Add(channel); policy.Channels = channels; Store.IPolicyStoreWriter writer = store.Writer; Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer"); writer.WritePolicySet(policySet); writer.WritePolicy(policySet, policy); writer.WriteChildCollection(policySet, policy, policy.Name.Value, CollectionConverter.Convert<IPolicyChannel, IPolicyObject>(channels)); writer.Close(); string expectedPolicySetFile = m_testPath + "TestHttpOfflineNoActions.PolicySet.xml"; TestHelpers.CompareXml(expectedPolicySetFile, store.StoreXML); IPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(policyCatalogue.Identifier, languageId); catalogueWriter.WriteCatalogue(policySet.MasterCatalogue); catalogueWriter.Close(); string expectedCatalogueFile = m_testPath + "TestHttpOfflineNoActions.Catalogue.xml"; TestHelpers.CompareXml(expectedCatalogueFile, catalogueStore.GetStoreXML(policyCatalogue.Identifier)); }
public void TestWriteMultiplePolicies() { string testCatalogue = m_testPath + "TestRealPolicyCatalogue.xml"; string testLanguage = m_testPath + "TestRealPolicyLanguage.xml"; XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage)); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue)); XmlStore store = new XmlStore(); Store.IPolicyStoreWriter writer = store.Writer; Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer"); ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false); P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active); writer.WritePolicySet(policySet); writer.WritePolicy(policySet, policy); IPolicyObjectCollection<IPolicyObject> conditions = new PolicyObjectCollection<IPolicyObject>(BuildConditions() as PolicyObjectCollection<IPolicyObject>); writer.WriteChildCollection(policySet, policy, policy.Name.Value, conditions); ObjectModel.PolicySet policySet2 = new ObjectModel.PolicySet(new Guid("{807F2757-373C-4629-AB4E-F0AEB3DE447B}"), new TranslateableLanguageItem("{F7916FE9-8871-4650-A3ED-9597A3F91A74}"), store, policyCatalogue, false); writer.WritePolicySet(policySet2); writer.WritePolicy(policySet2, policy); conditions.RemoveAt(0); writer.WriteChildCollection(policySet2, policy, policy.Name.Value, conditions); writer.Close(); TestHelpers.CompareXml(m_testPath + "ExpectedWriteMultiplePolicies.xml", store.StoreXML); }
public void TestCreateNewPolicySet() { string testCatalogue = m_testPath + "TestCreateNewPolicyCatalogue.xml"; string languageFilename = m_testPath + "TestCreateNewPolicySetLanguage.xml"; string policySetFilename = m_testPath + "TestCreateNewPolicySet.xml"; XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.Reset(); Guid languageId = new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"); IPolicyLanguage language = new PolicyLanguage(languageId, "en"); language.DefaultLanguage = true; languageStore.AddLanguage(language); PolicyLanguageCache policyLanguageCache = PolicyLanguageCache.Instance; policyLanguageCache.SetLanguageItemText(languageId, new Guid("{B5C31A66-1B39-4CA7-BF02-AF271B5864F7}"), "New catalogue"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{9465CA41-A0A1-40BD-BE26-E83E17D83148}"), "New policy set"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{08BC5764-4879-42ED-9AD8-15040C4ADEDE}"), "New policy"); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; PolicyCatalogue policyCatalogue = new PolicyCatalogue(new Guid("{AB5E2A43-01FB-4AA6-98FC-8F74BB0621CA}"), language.Identifier, new TranslateableLanguageItem("{B5C31A66-1B39-4CA7-BF02-AF271B5864F7}"), catalogueStore); catalogueStore.AddPolicyCatalogue(policyCatalogue); IPolicyStore policyStore = new XmlStore(); IPolicySet policySet = new PolicySet(new Guid("{29EC30A5-1271-4306-89C8-5811172D901A}"), new TranslateableLanguageItem("{9465CA41-A0A1-40BD-BE26-E83E17D83148}"), policyStore, policyCatalogue, false); IPolicy newPolicy = new P5Policy(policySet, new Guid("{D257D4DC-4A12-438F-A32A-CF1CE4474441}"), new TranslateableLanguageItem("{08BC5764-4879-42ED-9AD8-15040C4ADEDE}"), PolicyStatus.Active); policySet.Policies.Add(newPolicy); // Save everything IPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(policyCatalogue.Identifier, language.Identifier); catalogueWriter.WriteCatalogue(policyCatalogue); catalogueWriter.Close(); policySet.Save(); TestHelpers.CompareXml(testCatalogue, catalogueStore.GetStoreXML(policyCatalogue.Identifier)); TestHelpers.CompareXml(policySetFilename, policyStore.XMLRepresentation); TestHelpers.CompareXml(languageFilename, languageStore.GetXMLRepresentation(language.Identifier, language.Name.Value)); policySet.Save(); TestHelpers.CompareXml(testCatalogue, catalogueStore.GetStoreXML(policyCatalogue.Identifier)); TestHelpers.CompareXml(policySetFilename, policyStore.XMLRepresentation); TestHelpers.CompareXml(languageFilename, languageStore.GetXMLRepresentation(language.Identifier, language.Name.Value)); }
public void TestWriteMultiplePoliciesMultipleChannels() { string testCatalogue = m_testPath + "TestRealPolicyCatalogue.xml"; string testLanguage = m_testPath + "TestRealPolicyLanguage.xml"; XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(testLanguage)); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; PolicyCatalogue policyCatalogue = catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(testCatalogue)); XmlStore store = new XmlStore(); Store.IPolicyStoreWriter writer = store.Writer; Assert.IsNotNull(writer, "Expected a valid [IPolicyStoreWriter] writer"); ObjectModel.PolicySet policySet = new ObjectModel.PolicySet(new Guid("{8FC9EB93-C376-4E96-B22E-71FAA848393D}"), new TranslateableLanguageItem("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}"), store, policyCatalogue, false); P5Policy policy = new P5Policy(store, policySet, new Guid("{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}"), new TranslateableLanguageItem("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}"), PolicyStatus.Active); writer.WritePolicySet(policySet); writer.WritePolicy(policySet, policy); IPolicyObjectCollection<IPolicyObject> channels = new PolicyObjectCollection<IPolicyObject>(); PolicyChannel channel = new PolicyChannel(new Guid("{EB97BB54-CB76-46EE-B024-3F747ED4424F}"), new TranslateableLanguageItem("{463A0FAF-CE8C-470E-8077-A093B9350719}"), ChannelType.SMTP); channel.Routing = BuildSmtpRouting(); channel.Actions = BuildActionMatrix(policy, false); channels.Add(channel); writer.WriteChildCollection(policySet, policy, policy.Name.Value, channels); ObjectModel.PolicySet policySet2 = new ObjectModel.PolicySet(new Guid("{807F2757-373C-4629-AB4E-F0AEB3DE447B}"), new TranslateableLanguageItem("{F7916FE9-8871-4650-A3ED-9597A3F91A74}"), store, policyCatalogue, false); writer.WritePolicySet(policySet2); writer.WritePolicy(policySet2, policy); writer.WriteChildCollection(policySet2, policy, "Conditions", policy.Conditions); channel = new PolicyChannel(new Guid("{B28CD900-603B-4FE7-9994-EE2B7BCAD2F8}"), new TranslateableLanguageItem("{BFC3A7A1-E753-48CF-BB41-F2765D08B1B5}"), ChannelType.SMTP); channel.Routing = BuildSmtpRouting(); channels.Add(channel); writer.WriteChildCollection(policySet2, policy, policy.Name.Value, channels); writer.Close(); TestHelpers.CompareXml(m_testPath + "ExpectedWriteMultiplePoliciesMultipleChannels.xml", store.StoreXML); }
public void TestCreatePolicySetChannelsMasterCataloguePrepopulateRouting() { string testCatalogue = m_testPath + "TestCreatePolicySetChannelsMasterCatalogue.xml"; string languageFilename = m_testPath + "TestCreatePolicySetChannelsMasterCatalogueLanguage.xml"; string policySetFilename = m_testPath + "TestCreatePolicySetChannelsMasterCataloguePolicySet.xml"; XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.Reset(); Guid languageId = new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"); PolicyLanguageCache.Instance.ActiveLanguageId = languageId; IPolicyLanguage language = new PolicyLanguage(languageId, "en"); language.DefaultLanguage = true; languageStore.AddLanguage(language); PolicyLanguageCache policyLanguageCache = PolicyLanguageCache.Instance; policyLanguageCache.SetLanguageItemText(languageId, new Guid("{B5C31A66-1B39-4CA7-BF02-AF271B5864F7}"), "New catalogue"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{9465CA41-A0A1-40BD-BE26-E83E17D83148}"), "New policy set"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{08BC5764-4879-42ED-9AD8-15040C4ADEDE}"), "New policy"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{39C06E29-074C-46C8-BE3D-F1CD92BB8D66}"), "Test channel"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{03005F4E-04FC-4287-B2A6-25F877D9C31B}"), "Test sources"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{3BF2C1D6-0F40-4A32-A311-6F65A5D271BD}"), "Test destinations"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{A8CEBEDF-92EA-4DCC-8053-08E5245ED84D}"), "Test routing table"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{86D8056D-BA38-44FA-B9BD-100CFB7113F8}"), "Test condition group"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{040C4E16-EE88-4B91-833F-8F30A536DAC6}"), "Test action group"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{F03E6CD1-98C0-4590-B789-907ECF90BEBF}"), "Test data element"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{6197CDBE-9F42-4A61-9369-238355BAB404}"), "Test data element display"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{E5C29C65-9600-42D9-8CD6-6638F40F9341}"), "Test data item"); policyLanguageCache.SetLanguageItemText(languageId, new Guid("{463295F1-A5A2-4BB1-B029-7917AC75E9E6}"), "Test action"); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; catalogueStore.Reset(); PolicyCatalogue policyCatalogue = new PolicyCatalogue(new Guid("{AB5E2A43-01FB-4AA6-98FC-8F74BB0621CA}"), language.Identifier, new TranslateableLanguageItem("{B5C31A66-1B39-4CA7-BF02-AF271B5864F7}"), catalogueStore); catalogueStore.AddPolicyCatalogue(policyCatalogue); IPolicyStore policyStore = new XmlStore(); IPolicySet policySet = new PolicySet(new Guid("{29EC30A5-1271-4306-89C8-5811172D901A}"), new TranslateableLanguageItem("{9465CA41-A0A1-40BD-BE26-E83E17D83148}"), policyStore, policyCatalogue, false); IPolicy newPolicy = new P5Policy(policySet, new Guid("{D257D4DC-4A12-438F-A32A-CF1CE4474441}"), new TranslateableLanguageItem("{08BC5764-4879-42ED-9AD8-15040C4ADEDE}"), PolicyStatus.Active); policySet.Policies.Add(newPolicy); // Create policy set channel PolicyChannel channel = new PolicyChannel(new Guid("{0FE26539-7AAD-46DC-8D5B-9651CC00B9E4}"), new TranslateableLanguageItem("{39C06E29-074C-46C8-BE3D-F1CD92BB8D66}"), ChannelType.SMTP); // Create routing table RoutingTable routingTable = new RoutingTable(new Guid("{CDF0252C-3D5D-4AFB-98C2-89CF00FE2175}"), new TranslateableLanguageItem("{A8CEBEDF-92EA-4DCC-8053-08E5245ED84D}"), ChannelType.SMTP); IRoutingItemCollection senders = new RoutingItemCollection(new Guid("{441FDCBF-B606-4325-8CD5-E829AD5303B9}"), "{03005F4E-04FC-4287-B2A6-25F877D9C31B}"); senders.Add(new RoutingItem(new Guid("{D41A47E2-CC13-46FF-BE83-829625792576}"), "James Brown", "*****@*****.**")); senders.Add(new RoutingItem(new Guid("{B031DFE9-54E7-482B-8955-18CFB8F06A40}"), "Nat King Cole", "*****@*****.**")); IRoutingItemCollection recipients = new RoutingItemCollection(new Guid("{29C44E5C-5405-409F-8513-A99AE246536F}"), "{3BF2C1D6-0F40-4A32-A311-6F65A5D271BD}"); recipients.Add(new RoutingItem(new Guid("{9E26C6A2-ABE2-427D-9D78-5B8547ADA8D2}"), "Jet Li", "*****@*****.**")); routingTable.Sources.Add(senders); routingTable.Destinations.Add(recipients); // Assign routing table to channel channel.Routing = routingTable; // Create action matrix ActionMatrix actionMatrix = new ObjectModel.ActionMatrix(false); // Create an action matrix cell ActionMatrixCell actionMatrixCell = new ObjectModel.ActionMatrixCell(senders, recipients); // Populate the action matrix cell ConditionGroup conditionGroup = new ConditionGroup(new Guid("{661EDD6F-D750-493A-9932-E56C8C22E2CF}"), new TranslateableLanguageItem("{86D8056D-BA38-44FA-B9BD-100CFB7113F8}"), ConditionLogic.AND, false); ActionGroup actionGroup = new ObjectModel.ActionGroup(new Guid("{32D97853-2680-4B02-A391-22CAEE87B017}"), new TranslateableLanguageItem("{040C4E16-EE88-4B91-833F-8F30A536DAC6}"), 1); IActionConditionGroup actionConditionGroup = new ObjectModel.ActionConditionGroup(conditionGroup, actionGroup, false); ObjectModel.Action action = new ObjectModel.Action(new Guid("{5153B00E-7D30-4D37-90F9-75E55AA1B32B}"), new TranslateableLanguageItem("{463295F1-A5A2-4BB1-B029-7917AC75E9E6}"), "TestAction.dll", "Test.Action", RunAt.Client, false, 1); //TODO JE DataItem dataItem = DataItem.CreateDataItem(new TranslateableLanguageItem("{E5C29C65-9600-42D9-8CD6-6638F40F9341}"), DataType.String, "Not again, when will it ever end!"); DataElement dataElement = new DataElement(new Guid("{39500989-0B41-4C4E-85DF-CCB4FBD5BEB8}"), new TranslateableLanguageItem("{F03E6CD1-98C0-4590-B789-907ECF90BEBF}"), new TranslateableLanguageItem("{6197CDBE-9F42-4A61-9369-238355BAB404}"), DataType.String, dataItem); action.DataElements.Add(dataElement); actionConditionGroup.ActionGroup.Actions.Add(action); // Assign the action condition group to the matrix cell actionMatrixCell.ActionConditionGroups.Add(actionConditionGroup); // Assign the action matrix cell to the action matrix actionMatrix[senders, recipients] = actionMatrixCell; // Assign action matrix to channel channel.Actions = actionMatrix; // Assign channel to policy newPolicy.Channels.Add(channel); // Save everything IPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(policyCatalogue.Identifier, language.Identifier); catalogueWriter.WriteCatalogue(policyCatalogue); catalogueWriter.Close(); policySet.Save(); TestHelpers.CompareXml(policySetFilename, policyStore.XMLRepresentation); IRoutingMatrixCell routingMatrixCell = routingTable[senders, recipients]; string expectedCatalogueXml = System.IO.File.ReadAllText(testCatalogue); expectedCatalogueXml = expectedCatalogueXml.Replace("{0}", routingMatrixCell.Name.Identifier.ToString("B").ToUpper()); expectedCatalogueXml = expectedCatalogueXml.Replace("{1}", routingMatrixCell.Description.Identifier.ToString("B").ToUpper()); testCatalogue += ".tmp"; System.IO.File.WriteAllText(testCatalogue, expectedCatalogueXml); TestHelpers.CompareXml(testCatalogue, catalogueStore.GetStoreXML(policySet.MasterCatalogue.Identifier)); string expectedLanguageXml = System.IO.File.ReadAllText(languageFilename); expectedLanguageXml = expectedLanguageXml.Replace("{0}", routingMatrixCell.Name.Identifier.ToString("B").ToUpper()); expectedLanguageXml = expectedLanguageXml.Replace("{1}", routingMatrixCell.Description.Identifier.ToString("B").ToUpper()); languageFilename += ".tmp"; System.IO.File.WriteAllText(languageFilename, expectedLanguageXml); TestHelpers.CompareXml(languageFilename, languageStore.GetXMLRepresentation(language.Identifier, language.Name.Value)); }
public void TestIsInMyMasterCatalogue() { XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.Reset(); IPolicyLanguage language = new PolicyLanguage(new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"), "en"); languageStore.AddLanguage(language); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; catalogueStore.Reset(); PolicyCatalogue policyCatalogue = new PolicyCatalogue(new Guid("{AB5E2A43-01FB-4AA6-98FC-8F74BB0621CA}"), language.Identifier, new TranslateableLanguageItem("{B5C31A66-1B39-4CA7-BF02-AF271B5864F7}"), catalogueStore); catalogueStore.AddPolicyCatalogue(policyCatalogue); IPolicyStore policyStore = new XmlStore(); IPolicySet policySet = new PolicySet(Guid.NewGuid(), new TranslateableLanguageItem("TestPolicySet"), policyStore, policyCatalogue, false); IPolicy policy = PolicyFactory.CreatePolicy("TestPolicy", policySet, PolicyStatus.Active, "None"); //Item not in any catalogues doesn't appear in master catalogue Workshare.Policy.ObjectModel.IAction action = new Workshare.Policy.ObjectModel.Action(new Guid("{2814A571-5979-4065-A588-5E31A391ECF9}"), "AnAssembly", "AClassName", RunAt.Both, false, 1); //TODO JE Assert.AreEqual(false, PolicyFactory.IsInMyMasterCatalogue(policy, action), "Unexpectedly found IPolicyObject in catalogue"); IRoutingTable smtpRouting = policy.Channels[0].Routing; Assert.IsNotNull(smtpRouting, "Expected the routing table type to be SMTP"); //Same item does appear after adding to my master catalogue... RoutingHelper.AddCellToActionMatrix(policy.Channels[0].Actions, smtpRouting.Sources[0], smtpRouting.Sources[0]); IActionMatrixCell cell = policy.Channels[0].Actions[smtpRouting.Sources[0], smtpRouting.Sources[0]]; cell.ActionConditionGroups[0].ActionGroup.Actions.Add(action); Assert.AreEqual(true, PolicyFactory.IsInMyMasterCatalogue(policy, action), "Didn't find IPolicyObject in catalogue"); //...and try again using the other override Assert.AreEqual(true, PolicyFactory.IsInMyMasterCatalogue(policySet, action), "Didn't find IPolicyObject in catalogue"); //Different item in another catalogue doesn't appear in my master catalogue... PolicyCatalogue otherPolicyCatalogue = new PolicyCatalogue(new Guid("{6F294319-CE31-4919-9BC7-4AC6EDD8656D}"), language.Identifier, new TranslateableLanguageItem("otherCatalogue"), catalogueStore); catalogueStore.AddPolicyCatalogue(otherPolicyCatalogue); IPolicySet otherPolicySet = new PolicySet(Guid.NewGuid(), new TranslateableLanguageItem("TestPolicySet"), policyStore, otherPolicyCatalogue, false); IPolicy otherPolicy = PolicyFactory.CreatePolicy("OtherTestPolicy", otherPolicySet, PolicyStatus.Active, "None"); action = new Workshare.Policy.ObjectModel.Action(new Guid("{27F68034-A414-4043-BD6A-BD3A912CF7ED}"), "AnAssembly", "AClassName", RunAt.Both, false, 1); //TODO JE IRoutingTable otherSmtpRouting = otherPolicy.Channels[0].Routing; Assert.IsNotNull(smtpRouting, "Expected the other routing table type to be SMTP"); RoutingHelper.AddCellToActionMatrix(otherPolicy.Channels[0].Actions, otherSmtpRouting.Sources[0], otherSmtpRouting.Sources[0]); cell = otherPolicy.Channels[0].Actions[otherSmtpRouting.Sources[0], otherSmtpRouting.Sources[0]]; cell.ActionConditionGroups[0].ActionGroup.Actions.Add(action); Assert.AreEqual(false, PolicyFactory.IsInMyMasterCatalogue(policy, action), "Unexpectedly found IPolicyObject in catalogue"); //...but does appear in the other policy's master catalogue Assert.AreEqual(true, PolicyFactory.IsInMyMasterCatalogue(otherPolicy, action), "Didn't find IPolicyObject in catalogue"); //Item in another catalogue, with same GUID as an item in my catalogue, doesn't appear in my master catalogue... action = new Workshare.Policy.ObjectModel.Action(new Guid("{2814A571-5979-4065-A588-5E31A391ECF9}"), "AnAssembly", "AClassName", RunAt.Both, false, 1); //TODO JE cell = otherPolicy.Channels[0].Actions[otherSmtpRouting.Sources[0], otherSmtpRouting.Sources[0]]; cell.ActionConditionGroups[0].ActionGroup.Actions.Add(action); Assert.AreEqual(false, PolicyFactory.IsInMyMasterCatalogue(policy, action), "Unexpectedly found IPolicyObject in catalogue"); //...but does appear in the other policy's master catalogue Assert.AreEqual(true, PolicyFactory.IsInMyMasterCatalogue(otherPolicy, action), "Didn't find IPolicyObject in catalogue"); //Test a new type of IPolicyObject isn't handled try { MockIPolicyObject mockObject = new MockIPolicyObject(); bool value = PolicyFactory.IsInMyMasterCatalogue(policy, mockObject); Assert.IsTrue(false, "Unexpectedly handled an unknown IPolicyObject type"); } catch (ArgumentException) { Assert.IsTrue(true); } catch (Exceptions.PolicyDesignerException) { Assert.IsTrue(true); } }