示例#1
0
        private void ReadChannelActions(PolicyChannel policyChannel, string channelId)
        {
            string xpath = string.Format(CultureInfo.InvariantCulture, @"{0}/Channel[@id='{1}']/ActionMatrix",
                m_xpath.Substring(0, m_xpath.LastIndexOf("/")), channelId);

            XmlActionsReader xmlActionsReader = new XmlActionsReader(m_reader, policyChannel, m_policy, xpath);
            xmlActionsReader.Read();
        }
        public void TestReadActions()
        {
            string policyCatalogueFilename = m_testPath + "SamplePolicyCatalogue.xml";
            string policyLanguageFilename = m_testPath + "SampleLanguageBase.xml";
            string policyFilename = m_testPath + "SamplePolicy.xml";

            XmlPolicyLanguageStore languageStore = XmlPolicyLanguageStore.Instance;
            languageStore.AddLanguage(System.IO.File.ReadAllText(policyLanguageFilename));
            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            catalogueStore.Reset();
            catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(policyCatalogueFilename));

            XmlStore store = new XmlStore(System.IO.File.ReadAllText(policyFilename));

            XmlPolicyReader xmlPolicyReader = store.Reader as XmlPolicyReader;
            string policySetId = "{8FC9EB93-C376-4E96-B22E-71FAA848393D}";
            string policyId = "{C7D62E10-D889-4EF5-AF3D-823C82C230CA}";
            string channelId = "{EB97BB54-CB76-46EE-B024-3F747ED4424F}";
            string xpath = string.Format(@"/PolicySetStore/PolicySets/PolicySet[@id='{0}']/Policies/Policy[@id='{1}']/Channels/Channel[@id='{2}']/ActionMatrix",
                policySetId, policyId, channelId);

            Assert.AreEqual(1, xmlPolicyReader.PolicySets.Count);
            IPolicySet policySet = xmlPolicyReader.PolicySets[0];
            Assert.IsNotNull(policySet);

            IPolicy policy = policySet.Policies[new Guid(policyId)];
            Assert.IsNotNull(policy);

            PolicyChannel policyChannel = new PolicyChannel(new Guid(channelId), new TranslateableLanguageItem("TestChannel"), ChannelType.SMTP);
            XmlActionsReader reader = new XmlActionsReader(xmlPolicyReader, policyChannel, policy, xpath);
            reader.Read();

            Assert.IsNotNull(policyChannel.Actions, "Expected a valid actions object");

            IActionMatrix actionMatrix = policyChannel.Actions;
            Assert.IsNotNull(actionMatrix, "Expected a valid action matrix");
            Assert.AreEqual("", actionMatrix.Name.Value);
            Assert.AreEqual(3, actionMatrix.CellCount, "Expected four action matrix cells");

            Dictionary<KeyValuePair<Guid, Guid>, IActionMatrixCell>.Enumerator enumerator = actionMatrix.GetEnumerator();
            Assert.IsTrue(enumerator.MoveNext(), "Expectd the enumerator to move to the first item");
            IActionMatrixCell actionMatrixCell = enumerator.Current.Value;
            Assert.IsNotNull(actionMatrixCell, "Expected a valid action matrix cell");
            IPolicyObjectCollection<IActionConditionGroup> actionConditiongroups = actionMatrixCell.ActionConditionGroups;
            Assert.IsNotNull(actionConditiongroups, "Expected a valid action condition group collection");
            Assert.AreEqual(1, actionConditiongroups.Count, "Expected one action condition group collection");
            IActionConditionGroup actionConditionGroup = actionConditiongroups[0];
            Assert.IsNotNull(actionConditionGroup, "Expected a valid action condition group");

            IActionGroup actionGroup = actionConditionGroup.ActionGroup;
            Assert.IsNotNull(actionGroup, "Expected a valid action group");
            Assert.AreEqual(new Guid("{987B7C8B-5ADD-4696-8456-DDE11D95CE0B}"), actionGroup.Identifier);
            Assert.AreEqual("Protect us please", actionGroup.Name.Value);
            Assert.IsNotNull(actionGroup.ActionGroups);
            Assert.AreEqual(1, actionGroup.ActionGroups.Count, "Expected one action group");
            IActionGroup childActionGroup = actionGroup.ActionGroups[0];
            Assert.IsNotNull(childActionGroup);
            Assert.AreEqual(new Guid("{BBEF6879-6D10-455d-A5D9-86D9B8B725A6}"), childActionGroup.Identifier);
            Assert.IsNotNull(childActionGroup.ActionGroups);
            Assert.AreEqual(0, childActionGroup.ActionGroups.Count);
            Assert.IsNotNull(childActionGroup.Actions);
            Assert.AreEqual(1, childActionGroup.Actions.Count, "Expected the child action group to have one action");
            IAction childActionGroupChildAction = childActionGroup.Actions[0];
            Assert.IsNotNull(childActionGroupChildAction);
            Assert.AreEqual(new Guid("{72551FD1-D46D-4AF6-8DA3-76B5BCE01FD8}"), childActionGroupChildAction.Identifier);

            Assert.IsNotNull(actionGroup.Actions);
            Assert.AreEqual(1, actionGroup.Actions.Count, "Expected one action");
            IAction childAction = actionGroup.Actions[0];
            Assert.IsNotNull(childAction);
            Assert.AreEqual(new Guid("{26BCFA7E-3605-4EE7-ACC6-0AFB4D5EBB71}"), childAction.Identifier);
        }