Пример #1
0
        public void TestReadConditionsSecondLevel()
        {
            string policyCatalogueFilename = m_testPath + "SamplePolicyCatalogue.xml";
            string policyLanguageFilename = m_testPath + "SampleLanguageBase.xml";
            string policyFilename = m_testPath + "SamplePolicy.xml";

            XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(policyLanguageFilename));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(policyCatalogueFilename));

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

            XmlPolicyReader xmlPolicyReader = store.Reader as XmlPolicyReader;
            string policyId = "{8FC9EB93-C376-4E96-B22E-71FAA848393D}";
            string ruleId = "{56C991B8-953D-46AD-B9E9-0CFB08F52C23}";
            string conditionGroupId = "{D64056E5-A19D-4B29-8F4A-A70337B42A19}";
            string childConditionGroupId = "{661EDD6F-D750-493A-9932-E56C8C22E2CF}";
            string conditionsXpath = string.Format(@"/PolicySetStore/PolicySets/PolicySet[@id='{0}']/Policies/Policy[@id='{1}']/Conditions/ConditionGroup[@id='{2}']/ConditionGroup[@id='{3}']",
                policyId, ruleId, conditionGroupId, childConditionGroupId);

            PolicyObjectCollection<IPolicyObject> conditions = new PolicyObjectCollection<IPolicyObject>();

            XmlConditionGroupReader conditionReader = new XmlConditionGroupReader(xmlPolicyReader, conditions, conditionsXpath);
            conditionReader.Read();

            Assert.AreEqual(1, conditions.Count);

            ICondition condition = conditions[0] as ICondition;
            Assert.IsNotNull(condition);
            Assert.AreEqual(new Guid("{6B7F6B0C-747A-4BD0-A65D-A1FB9E44FE7C}"), condition.Identifier);
            Assert.AreEqual("IDataComparer", condition.Class);
            Assert.AreEqual(OperatorType.GreaterThan, condition.Operator);
        }
Пример #2
0
        public void TestReadConditionGroups()
        {
            string policyCatalogueFilename = m_testPath + "SamplePolicyCatalogue.xml";
            string policyLanguageFilename = m_testPath + "SampleLanguageBase.xml";
            string policyFilename = m_testPath + "SamplePolicy.xml";

            XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(policyLanguageFilename));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(policyCatalogueFilename));

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

            XmlPolicyReader xmlPolicyReader = store.Reader as XmlPolicyReader;
            string policyId = "{8FC9EB93-C376-4E96-B22E-71FAA848393D}";
            string ruleId = "{56C991B8-953D-46AD-B9E9-0CFB08F52C23}";
            string conditionGroupId = "{D64056E5-A19D-4B29-8F4A-A70337B42A19}";
            string conditionsXpath = string.Format(@"/PolicySetStore/PolicySets/PolicySet[@id='{0}']/Policies/Policy[@id='{1}']/Conditions/ConditionGroup[@id='{2}']",
                policyId, ruleId, conditionGroupId);

            PolicyObjectCollection<IPolicyObject> conditions = new PolicyObjectCollection<IPolicyObject>();

            XmlConditionGroupReader XmlConditionGroupReader = new XmlConditionGroupReader(xmlPolicyReader, conditions, conditionsXpath);
            XmlConditionGroupReader.Read();

            Assert.AreEqual(2, conditions.Count);

            IConditionGroup conditionGroup = conditions[0] as IConditionGroup;
            Assert.IsNotNull(conditionGroup);
            Assert.AreEqual(new Guid("{661EDD6F-D750-493A-9932-E56C8C22E2CF}"), conditionGroup.Identifier);
            Assert.AreEqual("Profanity", conditionGroup.Name.Value);
            Assert.AreEqual(1, conditionGroup.Conditions.Count);

            ICondition conditionGroupCondition = conditionGroup.Conditions[0] as ICondition;
            Assert.IsNotNull(conditionGroupCondition);
            Assert.AreEqual(new Guid("{6B7F6B0C-747A-4BD0-A65D-A1FB9E44FE7C}"), conditionGroupCondition.Identifier);
            Assert.AreEqual(OperatorType.GreaterThan, conditionGroupCondition.Operator);
            Assert.AreEqual(new Guid("{4E2F50C5-D310-47A1-AE3A-621F5C77FA68}"), conditionGroupCondition.DataLeft.Identifier);
            IDataSource dataSource = conditionGroupCondition.DataLeft.Data as IDataSource;
            Assert.IsNotNull(dataSource, "Expected a valid data source");
            IDataItem data = conditionGroupCondition.DataRight.Data as IDataItem;
            Assert.IsNotNull(data);
            Assert.AreEqual(10, data.Value);

            ICondition condition = conditions[1] as ICondition;
            Assert.IsNotNull(condition);
            Assert.AreEqual(new Guid("{A6F876B6-AD6D-4842-BC0D-4635D1EEE916}"), condition.Identifier);
            Assert.AreEqual("IDataComparer", condition.Class);
            Assert.AreEqual(OperatorType.GreaterThanOrEqualTo, condition.Operator);
            Assert.AreEqual(new Guid("{7CED5561-FD8C-423C-838F-9440EDFE6758}"), condition.DataLeft.Identifier);
            dataSource = condition.DataLeft.Data as IDataSource;
            Assert.IsNotNull(dataSource, "Expected a valid data source");
            data = condition.DataRight.Data as IDataItem;
            Assert.IsNotNull(data);
            Assert.AreEqual(2, data.Value);
        }
Пример #3
0
        public void TestReadMultiplePoliciesConditionGroups()
        {
            string policyCatalogueFilename = m_testPath + "ExpectedMultiplePoliciesCatalogue.xml";
            string policyLanguageFilename = m_testPath + "ExpectedMultiplePoliciesLanguage.xml";
            string policyFilename = m_testPath + "ExpectedWriteMultiplePolicies.xml";

            XmlPolicyLanguageStore.Instance.AddLanguage(System.IO.File.ReadAllText(policyLanguageFilename));

            XMLPolicyCatalogueStore catalogueStore = XMLPolicyCatalogueStore.Instance;
            catalogueStore.AddPolicyCatalogue(System.IO.File.ReadAllText(policyCatalogueFilename));

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

            XmlPolicyReader xmlPolicyReader = store.Reader as XmlPolicyReader;
            string policyId = "{8FC9EB93-C376-4E96-B22E-71FAA848393D}";
            string ruleId = "{C0F6D4BB-CBF1-41FC-8A28-616D6FC1DC73}";
            string conditionGroupId = "{D64056E5-A19D-4B29-8F4A-A70337B42A19}";
            string conditionsXpath = string.Format(@"/PolicySetStore/PolicySets/PolicySet[@id='{0}']/Policies/Policy[@id='{1}']/Conditions/ConditionGroup[@id='{2}']",
                policyId, ruleId, conditionGroupId);

            IPolicyObjectCollection<IPolicyObject> conditions = new PolicyObjectCollection<IPolicyObject>();
            XmlConditionGroupReader conditionReader = new XmlConditionGroupReader(xmlPolicyReader, conditions, conditionsXpath);
            conditionReader.Read();

            Assert.AreEqual(1, conditions.Count);
            IConditionGroup conditionGroup = conditions[0] as IConditionGroup;
            Assert.IsNotNull(conditionGroup);
            Assert.AreEqual(new Guid("{661EDD6F-D750-493A-9932-E56C8C22E2CF}"), conditionGroup.Identifier);
            Assert.AreEqual(1, conditionGroup.Conditions.Count);
            Assert.AreEqual(new Guid("{6B7F6B0C-747A-4BD0-A65D-A1FB9E44FE7C}"), conditionGroup.Conditions[0].Identifier);
        }