public void TestConvertSingleLanguage() { Guid languageId = Guid.NewGuid(); PolicyLanguage englishPolicy = new PolicyLanguage(languageId, "en"); englishPolicy[new Guid("{897EB1E3-AE92-4c51-8F71-2536A03F3E05}")] = "test"; englishPolicy[new Guid("{18878EC1-3F94-4331-B660-C59ACEBC5D41}")] = "computer"; englishPolicy[new Guid("{326C103E-6815-4720-AED5-82577F8CD068}")] = "commuter"; englishPolicy[new Guid("{153AEE87-AD26-4003-947E-FCE9F9229DA0}")] = "oblivion"; PolicyLanguageCache.Instance.AddLanguage(englishPolicy); NxLanguageStore nxLanguage = new NxLanguageStore(languageId); XmlDocument lang = nxLanguage.Languages; XmlNodeList nodes = lang.SelectNodes("/Languages/Language/PolicySetLanguage/*"); Assert.AreEqual(4, nodes.Count); Assert.AreEqual("897EB1E3-AE92-4C51-8F71-2536A03F3E05", nodes[0].Attributes["id"].Value.ToUpper()); Assert.AreEqual("test", nodes[0].Attributes["value"].Value); Assert.AreEqual("18878EC1-3F94-4331-B660-C59ACEBC5D41", nodes[1].Attributes["id"].Value.ToUpper()); Assert.AreEqual("computer", nodes[1].Attributes["value"].Value); Assert.AreEqual("326C103E-6815-4720-AED5-82577F8CD068", nodes[2].Attributes["id"].Value.ToUpper()); Assert.AreEqual("commuter", nodes[2].Attributes["value"].Value); Assert.AreEqual("153AEE87-AD26-4003-947E-FCE9F9229DA0", nodes[3].Attributes["id"].Value.ToUpper()); Assert.AreEqual("oblivion", nodes[3].Attributes["value"].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 TestWriteConditionAttributes() { 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("{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"; language[new Guid("{6B37988A-2D68-4249-BB26-CBDE39091E7A}")] = "This is test condition"; XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.AddLanguage(language); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; catalogueStore.Reset(); Guid catalogueGuid = new Guid("{8CF1172E-476C-46A5-AECF-A7A8BC5ACE30}"); PolicyCatalogue policyCatalogue = new PolicyCatalogue(catalogueGuid, languageId, catalogueStore); Condition condition = new Condition(new Guid("{8E915159-5F01-41B3-9FFF-20731544ADFA}"), "{B067FF7F-2DA0-4AA1-A69F-DEFCD8B4CE90}", new TranslateableLanguageItem("{6B37988A-2D68-4249-BB26-CBDE39091E7A}"), OperatorType.Equals); condition.DataLeft = new DataElement(new Guid("{A4BCB713-B1E8-42BA-8B70-3C8814D03D0C}"), new TranslateableLanguageItem("DataLeft"), new TranslateableLanguageItem("DataLeft"), DataType.String, DataItem.CreateDataItem(new TranslateableLanguageItem("StringItem"), DataType.String, "StringData")); condition.DataRight = new DataElement(new Guid("{FCF77B46-B6C9-4E5C-BA15-4B5AE31FF4E7}"), new TranslateableLanguageItem("DataRight"), new TranslateableLanguageItem("DataRight"), DataType.String, DataItem.CreateDataItem(new TranslateableLanguageItem("StringItem"), DataType.String, "StringData")); condition["custom1"] = new TranslateableLanguageItem("{EBF8443B-4912-44F2-89BE-A0A055332D1B}"); condition["custom2"] = new TranslateableLanguageItem("{8053E60C-EED7-464D-84EA-ECB51C291237}"); IPolicyCatalogueWriter policyCatalogueWriter = catalogueStore.GetWriter(catalogueGuid, languageId); policyCatalogueWriter.WriteName("Test catalogue"); policyCatalogueWriter.WriteCondition(condition); policyCatalogueWriter.Close(); TestHelpers.CompareXml(m_testPath + "ExpectedWriteConditionAttributes.xml", catalogueStore.GetXMLRepresentation(catalogueGuid)); }
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 TestWriteChannelAttributes() { Guid languageId = new Guid("{CBEB31FA-7FE8-4E27-A01A-1D19AFCA604C}"); PolicyLanguage language = new PolicyLanguage(languageId, "en"); language[new Guid("{B067FF7F-2DA0-4AA1-A69F-DEFCD8B4CE90}")] = "Test channel"; 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("{93634DD0-904C-435E-B282-4E650E55E90D}"); PolicyCatalogue policyCatalogue = new PolicyCatalogue(catalogueGuid, languageId, catalogueStore); PolicyChannel channel = new PolicyChannel(new Guid("{8E915159-5F01-41B3-9FFF-20731544ADFA}"), new TranslateableLanguageItem("{B067FF7F-2DA0-4AA1-A69F-DEFCD8B4CE90}"), ChannelType.SMTP); channel["custom1"] = new TranslateableLanguageItem("{EBF8443B-4912-44F2-89BE-A0A055332D1B}"); channel["custom2"] = new TranslateableLanguageItem("{8053E60C-EED7-464D-84EA-ECB51C291237}"); IPolicyCatalogueWriter policyCatalogueWriter = catalogueStore.GetWriter(catalogueGuid, languageId); policyCatalogueWriter.WriteName("Test catalogue"); policyCatalogueWriter.WriteChannel(channel); policyCatalogueWriter.Close(); TestHelpers.CompareXml(m_testPath + "ExpectedWriteChannelAttributes.xml", catalogueStore.GetXMLRepresentation(catalogueGuid)); }
public void TestAddConditionGroupWithChildren() { IPolicyLanguage language = new PolicyLanguage(new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"), "en"); 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); PolicySetObserver policySetObserver = new PolicySetObserver(policyCatalogue); Assert.AreEqual(0, policyCatalogue.Conditions.Count); Assert.AreEqual(0, policyCatalogue.ConditionGroups.Count); IConditionGroup conditionGroup = new ConditionGroup(new Guid("{5823E98A-1F4D-44B9-BC0E-A538BD2C9262}"), new TranslateableLanguageItem("Test group"), ConditionLogic.AND, false); IConditionGroup subConditionGroup = new ConditionGroup(new Guid("{B87DF614-2400-4C1F-BEA8-3C2EB3964EAE}"), new TranslateableLanguageItem("Test sub group"), ConditionLogic.AND, false); ICondition condition = new Condition(new Guid("{98C73BC3-3E20-403C-8023-C91E2818355F}"), "TestClass", new TranslateableLanguageItem("This is a test"), OperatorType.Equals); subConditionGroup.Conditions.Add(condition); conditionGroup.Conditions.Add(subConditionGroup); policySetObserver.AddObject(conditionGroup); Assert.AreEqual(1, policyCatalogue.Conditions.Count); Assert.AreEqual(2, policyCatalogue.ConditionGroups.Count); }
public void TestWriteChannels() { Guid languageGuid = new Guid("{054846D4-6540-4C78-BA7D-141C91EE6A4C}"); PolicyLanguage language = new PolicyLanguage(languageGuid, "en"); language[new Guid("{D0FE23B8-B8A0-4DD6-A0F1-A7836DC0417E}")] = "Test catalogue"; language[new Guid("{A056EB78-E531-4B13-AA2E-0241BFDE3889}")] = "Test channel"; language[new Guid("{C0845AEC-C8C8-4531-BACB-E932B08DF4F0}")] = "Test channel 2"; XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.AddLanguage(language); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; catalogueStore.Reset(); Guid catalogueId = new Guid("{B496E117-29DA-4770-87E9-62573B28BB4F}"); XmlPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(catalogueId, languageGuid) as XmlPolicyCatalogueWriter; Assert.IsNotNull(catalogueWriter, "Expected a valid [IPolicyStoreWriter] writer"); catalogueWriter.WriteName("{D0FE23B8-B8A0-4DD6-A0F1-A7836DC0417E}"); string channelGuid = "{390F589A-24B0-4DF0-B750-D47EDD1FF0BE}"; PolicyChannel channel = new PolicyChannel(new Guid(channelGuid), new TranslateableLanguageItem("{A056EB78-E531-4B13-AA2E-0241BFDE3889}"), ChannelType.SMTP); catalogueWriter.WriteChannel(channel); channelGuid = "{2F1F664B-74B7-4c4d-B8C2-AB13FAF66F19}"; channel = new PolicyChannel(new Guid(channelGuid), new TranslateableLanguageItem("{C0845AEC-C8C8-4531-BACB-E932B08DF4F0}"), ChannelType.HTTP); catalogueWriter.WriteChannel(channel); catalogueWriter.Close(); TestHelpers.CompareXml(m_testPath + "ExpectedWriteChannels.xml", catalogueStore.GetStoreXML(catalogueId)); }
public void SetUpTest() { XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.Reset(); IPolicyLanguage language = new PolicyLanguage(new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"), "en"); languageStore.AddLanguage(language); PolicyLanguageCache.Instance.ActiveLanguageId = language.Identifier; }
public PolicyLanguage(PolicyLanguage rhs, bool readOnly, bool createNewId) : base(rhs, readOnly, createNewId) { foreach (KeyValuePair<Guid, string> rhsItem in rhs.m_languageItems) { m_languageItems[rhsItem.Key] = rhsItem.Value; } }
public void SetUpFixture() { m_info = Workshare.DirectorySearcher.Tests.Test_Helper.GetValuesFromRegistry(); Workshare.DirectorySearcher.Tests.Test_Helper.SetupWsQADomain(); //ensures the directory searcher singleton is initialised to be pointing at the right directory. PolicyLanguage language = new PolicyLanguage(new Guid("{AEFF49D2-3C18-40A0-9387-D4EAD9E60B70}"), "en"); language.DefaultLanguage = true; PolicyLanguageCache.Instance.AddLanguage(language); ResetDirAnalyzer(); }
public void TestWrite() { Guid languageGuid = new Guid("{EEB07AE7-8506-4BAC-AD84-8297003426BB}"); PolicyLanguage policyLanguage = new PolicyLanguage(languageGuid, "en"); policyLanguage[new Guid("{D803727B-5C81-44CC-8BFC-9B68797AC6EB}")] = "Test item 1"; policyLanguage[new Guid("{F0DD86A0-5D21-4784-88AF-C5321B5998F6}")] = "Test item 2"; XmlPolicyLanguageStore xmlPolicyLanguageStore = XmlPolicyLanguageStore.Instance(); IPolicyLanguageWriter writer = xmlPolicyLanguageStore.GetWriter(languageGuid); writer.Write(policyLanguage); writer.Close(); TestHelpers.CompareXml(m_testPath + "ExpectedWriteLanguage.xml", xmlPolicyLanguageStore.GetXMLRepresentation(languageGuid)); }
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 void SetUpTest() { m_stateMachine = new DynamicMock(typeof(IStateMachine)); XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.Reset(); IPolicyLanguage language = new PolicyLanguage(new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"), "en"); languageStore.AddLanguage(language); PolicyLanguageCache.Instance.ActiveLanguageId = language.Identifier; 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(); m_policySet = new PolicySet(Guid.NewGuid(), new TranslateableLanguageItem("TestPolicySet"), policyStore, policyCatalogue, false); }
public void TestCreateNonTranslateableLanguageItemFromGuidNotInLanguageTable() { Guid languageGuid = new Guid("{054846D4-6540-4C78-BA7D-141C91EE6A4C}"); PolicyLanguage language = new PolicyLanguage(languageGuid, "en"); language[new Guid("{D0FE23B8-B8A0-4DD6-A0F1-A7836DC0417E}")] = "Item in language table"; XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.AddLanguage(language); string name = "{C405B981-EAC4-4638-99E6-1E27D660664A}"; IPolicyLanguageItem languageItem = LanguageItemFactory.Create(name); Assert.IsNotNull(languageItem, "Expected a valid language item"); Assert.AreEqual(name, languageItem.Value); Assert.AreEqual(Guid.Empty, languageItem.Identifier); Assert.IsInstanceOf(typeof(NonTranslateableLanguageItem), languageItem); }
public void TestAddChannel() { IPolicyLanguage language = new PolicyLanguage(new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"), "en"); 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); PolicySetObserver policySetObserver = new PolicySetObserver(policyCatalogue); Assert.AreEqual(0, policyCatalogue.Channels.Count); IPolicyChannel channel = new PolicyChannel(new Guid("{0FE26539-7AAD-46DC-8D5B-9651CC00B9E4}"), new TranslateableLanguageItem("Test channel"), ChannelType.SMTP); policySetObserver.AddObject(channel); Assert.AreEqual(1, policyCatalogue.Channels.Count); }
public void TestAddConditionGroup() { IPolicyLanguage language = new PolicyLanguage(new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"), "en"); 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); PolicySetObserver policySetObserver = new PolicySetObserver(policyCatalogue); Assert.AreEqual(0, policyCatalogue.ConditionGroups.Count); IConditionGroup conditionGroup = new ConditionGroup(new Guid("{B87DF614-2400-4C1F-BEA8-3C2EB3964EAE}"), new TranslateableLanguageItem("Test group"), ConditionLogic.AND, false); policySetObserver.AddObject(conditionGroup); Assert.AreEqual(1, policyCatalogue.ConditionGroups.Count); }
public void TestAddCondition() { IPolicyLanguage language = new PolicyLanguage(new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"), "en"); 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); PolicySetObserver policySetObserver = new PolicySetObserver(policyCatalogue); Assert.AreEqual(0, policyCatalogue.Conditions.Count); ICondition condition = new Condition(new Guid("{98C73BC3-3E20-403C-8023-C91E2818355F}"), "TestClass", new TranslateableLanguageItem("This is a test"), OperatorType.Equals); policySetObserver.AddObject(condition); Assert.AreEqual(1, policyCatalogue.Conditions.Count); }
public void TestWriteNullChannels() { Guid languageId = new Guid("{054846D4-6540-4C78-BA7D-141C91EE6A4C}"); PolicyLanguage language = new PolicyLanguage(languageId, "en"); XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.AddLanguage(language); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; catalogueStore.Reset(); Guid catalogueId = new Guid("{B496E117-29DA-4770-87E9-62573B28BB4F}"); XmlPolicyCatalogueWriter catalogueWriter = catalogueStore.GetWriter(catalogueId, languageId) as XmlPolicyCatalogueWriter; Assert.IsNotNull(catalogueWriter, "Expected a valid [IPolicyStoreWriter] writer"); catalogueWriter.WriteChannel(null); catalogueWriter.Close(); TestHelpers.CompareXml(m_testPath + "ExpectedEmptyCatalogue.xml", catalogueStore.GetStoreXML(catalogueId)); }
public void TestCreateNonTranslateableLanguageItemFromGuidInLanguageTable() { Guid languageGuid = new Guid("{054846D4-6540-4C78-BA7D-141C91EE6A4C}"); PolicyLanguage language = new PolicyLanguage(languageGuid, "en"); language[new Guid("{D0FE23B8-B8A0-4DD6-A0F1-A7836DC0417E}")] = "Item in language table"; XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance; languageStore.AddLanguage(language); string itemId = "{D0FE23B8-B8A0-4DD6-A0F1-A7836DC0417E}"; IPolicyLanguageItem languageItem = LanguageItemFactory.Create(itemId); Assert.IsNotNull(languageItem, "Expected a valid language item"); Assert.AreEqual("Item in language table", languageItem.Value); Guid itemGuid = new Guid(itemId); Assert.AreEqual(itemGuid, languageItem.Identifier); Assert.IsInstanceOf(typeof(TranslateableLanguageItem), languageItem); }
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 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 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 TestAddDataElement() { IPolicyLanguage language = new PolicyLanguage(new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"), "en"); 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); PolicySetObserver policySetObserver = new PolicySetObserver(policyCatalogue); Assert.AreEqual(0, policyCatalogue.DataElements.Count); // Create data elements DataMethod dataMethod = new DataMethod("ThisIsATest"); DataItem parameterDataItem = DataItem.CreateDataItem(new TranslateableLanguageItem("Test data item to the left"), DataType.String, "Lets go dynamo"); DataElement parameterDataElement = new DataElement(new Guid("{015035B7-1793-464D-AF69-030E9DC7151E}"), new TranslateableLanguageItem("Test parameter data element"), new TranslateableLanguageItem(""), DataType.String, parameterDataItem); dataMethod.Parameters.Add(new Parameter("somethingTerrible", parameterDataElement)); IDataSource dataSource = new DataSource("ThisIsADodgyAssembly.dll", "ItWantsToTakeOverYourComputer", dataMethod); DataElement leftDataElement = new DataElement(new Guid("{454672AC-BCED-4DAB-813F-6CF14E6289C5}"), new TranslateableLanguageItem("Test data left"), new TranslateableLanguageItem(""), DataType.Object, dataSource); policySetObserver.AddObject(leftDataElement); IDataItem dataRightDataItem = DataItem.CreateDataItem(new TranslateableLanguageItem("Test data item to the right"), DataType.String, "This is a test"); DataElement rightDataElement = new DataElement(new Guid("{4E2F50C5-D310-47A1-AE3A-621F5C77FA68}"), new TranslateableLanguageItem("Test data right"), new TranslateableLanguageItem(""), DataType.String, dataRightDataItem); policySetObserver.AddObject(rightDataElement); Assert.AreEqual(2, policyCatalogue.DataElements.Count); }
public void SetUpSuite() { PolicyLanguage language = new PolicyLanguage(new Guid("{AEFF49D2-3C18-40A0-9387-D4EAD9E60B70}"), "en"); PolicyLanguageCache.Instance.Reset(); PolicyLanguageCache.Instance.AddLanguage(language); }
private void AddActionPostAddToChannel(out PolicyChannel channel, out PolicyCatalogue policyCatalogue) { IPolicyLanguage language = new PolicyLanguage(new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"), "en"); XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance; catalogueStore.Reset(); policyCatalogue = new PolicyCatalogue(new Guid("{AB5E2A43-01FB-4AA6-98FC-8F74BB0621CA}"), language.Identifier, new TranslateableLanguageItem("{B5C31A66-1B39-4CA7-BF02-AF271B5864F7}"), catalogueStore); catalogueStore.AddPolicyCatalogue(policyCatalogue); PolicySetObserver policySetObserver = new PolicySetObserver(policyCatalogue); Assert.AreEqual(0, policyCatalogue.Channels.Count); Assert.AreEqual(0, policyCatalogue.ActionGroups.Count); Assert.AreEqual(0, policyCatalogue.Actions.Count); Assert.AreEqual(0, policyCatalogue.LocationsCollection.Count); Assert.AreEqual(0, policyCatalogue.Locations.Count); channel = new PolicyChannel(new Guid("{0FE26539-7AAD-46DC-8D5B-9651CC00B9E4}"), new TranslateableLanguageItem("Test channel"), ChannelType.SMTP); policySetObserver.AddObject(channel); IRoutingItemCollection senders = new RoutingItemCollection(new Guid("{441FDCBF-B606-4325-8CD5-E829AD5303B9}"), "Test sources"); 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}"), "Test destinations"); recipients.Add(new RoutingItem(new Guid("{9E26C6A2-ABE2-427D-9D78-5B8547ADA8D2}"), "Jet Li", "*****@*****.**")); ActionMatrix actionMatrix = new ActionMatrix(); ActionMatrixCell actionMatrixCell = new ActionMatrixCell(senders, recipients); ConditionGroup conditionGroup = new ConditionGroup(new Guid("{9D065722-1106-4FC1-8D48-58733661B929}"), new TranslateableLanguageItem("Test condition group"), ConditionLogic.AND, false); ActionGroup actionGroup = new ActionGroup(new Guid("{E2A16C4D-E112-4249-92B9-612732117809}"), new TranslateableLanguageItem("Test action group"), 1); Action action = new Action(new Guid("{A5FAA63E-4F25-456F-92F9-9BB465C18F1F}"), "Test.dll", "Do.It", RunAt.Client, false, 1); //TODO JE ActionConditionGroup actionConditionGroup = new ActionConditionGroup(conditionGroup, actionGroup, false); actionMatrixCell.ActionConditionGroups.Add(actionConditionGroup); actionGroup.Actions.Add(action); actionMatrix[senders, recipients] = actionMatrixCell; channel.Actions = actionMatrix; }
public void TestAddActionPreAddToChannel() { IPolicyLanguage language = new PolicyLanguage(new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"), "en"); 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); PolicySetObserver policySetObserver = new PolicySetObserver(policyCatalogue); Assert.AreEqual(0, policyCatalogue.Channels.Count); Assert.AreEqual(0, policyCatalogue.ActionGroups.Count); Assert.AreEqual(0, policyCatalogue.Actions.Count); Assert.AreEqual(0, policyCatalogue.LocationsCollection.Count); Assert.AreEqual(0, policyCatalogue.Locations.Count); PolicyChannel channel = new PolicyChannel(new Guid("{0FE26539-7AAD-46DC-8D5B-9651CC00B9E4}"), new TranslateableLanguageItem("Test channel"), ChannelType.SMTP); policySetObserver.AddObject(channel); IRoutingItemCollection senders = new RoutingItemCollection(new Guid("{441FDCBF-B606-4325-8CD5-E829AD5303B9}"), "Test sources"); IRoutingItemCollection recipients = new RoutingItemCollection(new Guid("{29C44E5C-5405-409F-8513-A99AE246536F}"), "Test destinations"); ActionMatrix actionMatrix = new ActionMatrix(); channel.Actions = actionMatrix; ActionMatrixCell actionMatrixCell = new ActionMatrixCell(senders, recipients); actionMatrix[senders, recipients] = actionMatrixCell; ConditionGroup conditionGroup = new ConditionGroup(new Guid("{9D065722-1106-4FC1-8D48-58733661B929}"), new TranslateableLanguageItem("Test condition group"), ConditionLogic.AND, false); ActionGroup actionGroup = new ActionGroup(new Guid("{E2A16C4D-E112-4249-92B9-612732117809}"), new TranslateableLanguageItem("Test action group"), 1); Action action = new Action(new Guid("{A5FAA63E-4F25-456F-92F9-9BB465C18F1F}"), "Test.dll", "Do.It", RunAt.Client, false, 1); //TODO JE ActionConditionGroup actionConditionGroup = new ActionConditionGroup(conditionGroup, actionGroup, false); actionMatrixCell.ActionConditionGroups.Add(actionConditionGroup); actionGroup.Actions.Add(action); Assert.AreEqual(1, policyCatalogue.Channels.Count, "Expected one channel"); Assert.AreEqual(1, policyCatalogue.ActionGroups.Count, "Expected one action group"); Assert.AreEqual(1, policyCatalogue.Actions.Count, "Expected one action"); Assert.AreEqual(2, policyCatalogue.LocationsCollection.Count, "Expected two location groups"); Assert.AreEqual(0, policyCatalogue.Locations.Count, "Expected no locations"); }
public void TestAddDataElementPreAddToCondition() { IPolicyLanguage language = new PolicyLanguage(new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"), "en"); 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); PolicySetObserver policySetObserver = new PolicySetObserver(policyCatalogue); Assert.AreEqual(0, policyCatalogue.Conditions.Count); Assert.AreEqual(0, policyCatalogue.DataElements.Count); DataElement dataElementLeft = new DataElement(new Guid("{AC48B709-8DED-467D-8778-BB0A1520FDDC}"), new TranslateableLanguageItem("Data left test"), new TranslateableLanguageItem("This is the data to the left"), DataType.String, DataItem.CreateDataItem(new TranslateableLanguageItem("Test"), DataType.String, "This is some data")); DataElement dataElementRight = new DataElement(new Guid("{697DAD36-021C-451A-A67C-08D892CFC23A}"), new TranslateableLanguageItem("Data right test"), new TranslateableLanguageItem("This is the data to the right"), DataType.String, DataItem.CreateDataItem(new TranslateableLanguageItem("Test"), DataType.String, "This is some data")); Condition condition = new Condition(new Guid("{79F9C52C-8F04-473B-8487-8CB241DBED31}"), "Myclass", new TranslateableLanguageItem("Test condition"), OperatorType.Equals); condition.DataLeft = dataElementLeft; condition.DataRight = dataElementRight; policySetObserver.AddObject(condition); Assert.AreEqual(1, policyCatalogue.Conditions.Count, "Expected one condition"); Assert.AreEqual(2, policyCatalogue.DataElements.Count, "Expected two data elements"); }
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 TestAddRoutingPostAddToChannel() { IPolicyLanguage language = new PolicyLanguage(new Guid("{E8B22533-98EB-4D00-BDE4-406DC3E1858B}"), "en"); 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); PolicySetObserver policySetObserver = new PolicySetObserver(policyCatalogue); Assert.AreEqual(0, policyCatalogue.Channels.Count); Assert.AreEqual(0, policyCatalogue.RoutingTables.Count); Assert.AreEqual(0, policyCatalogue.LocationsCollection.Count); Assert.AreEqual(0, policyCatalogue.Locations.Count); PolicyChannel channel = new PolicyChannel(new Guid("{0FE26539-7AAD-46DC-8D5B-9651CC00B9E4}"), new TranslateableLanguageItem("Test channel"), ChannelType.SMTP); policySetObserver.AddObject(channel); IRoutingItemCollection senders = new RoutingItemCollection(new Guid("{441FDCBF-B606-4325-8CD5-E829AD5303B9}"), "Test sources"); 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}"), "Test destinations"); recipients.Add(new RoutingItem(new Guid("{9E26C6A2-ABE2-427D-9D78-5B8547ADA8D2}"), "Jet Li", "*****@*****.**")); RoutingTable routingTable = new RoutingTable(new Guid("{CDF0252C-3D5D-4AFB-98C2-89CF00FE2175}"), new TranslateableLanguageItem("Test routing table"), ChannelType.SMTP); routingTable.Sources.Add(senders); routingTable.Destinations.Add(recipients); channel.Routing = routingTable; IRoutingItemCollection recipients2 = new RoutingItemCollection(new Guid("{4E17A792-0CBC-4362-8A82-A1A7FF3C71B0}"), "More test destinations"); recipients2.Add(new RoutingItem(new Guid("{98CE8CF9-6CF1-4F32-BE4F-C2D381E6C972}"), "why you", "*****@*****.**")); routingTable.Destinations.Add(recipients2); Assert.AreEqual(1, policyCatalogue.Channels.Count, "Expected one channel"); Assert.AreEqual(1, policyCatalogue.RoutingTables.Count, "Expected one routing table"); Assert.AreEqual(3, policyCatalogue.LocationsCollection.Count, "Expected two location groups"); Assert.AreEqual(4, policyCatalogue.Locations.Count, "Expected three locations"); }
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); }