Пример #1
0
        public void TestLoadTemplate()
        {
            PolicyTemplate template = new PolicyTemplate();
            template.Load(policy_file);
            PolicySetItem psi = template.PolicySet;

            IPolicySet policyset = psi.Data;
            IPolicyObjectCollection<IPolicy> policies = policyset.Policies;

            Assert.AreEqual(10, policies.Count);

            Assert.AreEqual(TemplatePolicy.PdfPolicy, policies[0].Name.Value);
            Assert.AreEqual(TemplatePolicy.InternalZipPolicy, policies[1].Name.Value);
            Assert.AreEqual(TemplatePolicy.AlertPolicy, policies[2].Name.Value);
            Assert.AreEqual(TemplatePolicy.ExternalZipPolicy, policies[3].Name.Value);
            
            IPolicy internalZipPolicy = policies[1];

            List<IPolicyObject> conditions = template.GetConditions(internalZipPolicy);
            Assert.IsTrue(conditions.Count == 1);
            Assert.IsTrue(conditions[0] is IConditionGroup);
        }
Пример #2
0
        public void TestCleanConditions()
        {
            PolicyTemplate template = new PolicyTemplate();
            template.Load(policyFile);
            Options options = new Options(optionsxml);

            MetadataSecurityRatings msr = new MetadataSecurityRatings();

            Dictionary<RiskRating, List<string>> riskRatings = msr.Read(riskRatingsPath);
            List<IPolicyAction> policyActions = new List<IPolicyAction>();
            policyActions.Add(new CleanPolicy(template, options, riskRatings));

            foreach (IPolicyAction policyAction in policyActions)
            {
                policyAction.Apply();
            }

            string runtimePolicy = System.IO.Path.GetTempFileName();
            string myPolicy = System.IO.Path.GetTempFileName();
            template.Save(myPolicy, runtimePolicy);
    
            PolicyTemplate pt = new PolicyTemplate();
            pt.Load(myPolicy);

            IPolicy cleanPolicy = pt[TemplatePolicy.CleaningPolicy];
            List<IPolicyObject> conditionGroups =  pt.GetConditions(cleanPolicy);

            IConditionGroup conditionGroup = conditionGroups[0] as IConditionGroup;
            foreach (ICondition condition in conditionGroup.Conditions)
            {
                string name = condition.Name.Value;

                IDataSource ds = condition.DataLeft.Data as IDataSource;
                IDataMethod dm = ds.Method;
                IPolicyObjectCollection<IParameter> parameters = dm.Parameters;

                if (parameters.Count != 4)
                    throw new System.IndexOutOfRangeException("Unexpected number of parameters for condition");

                PolicyObjectCollection<IDataItem> items = parameters[3].Value.Data as PolicyObjectCollection<IDataItem>;

                foreach (IDataItem di in items)
                {
                    string diItem = di.Value as string;
                    if (string.Compare(diItem, "Footnote", false) == 0)
                    {
                        System.IO.File.Delete(myPolicy);
                        System.IO.File.Delete(runtimePolicy);
                        return;
                    }
                }
            }
            
            System.IO.File.Delete(myPolicy);
            System.IO.File.Delete(runtimePolicy);
            Assert.Fail("Should have found Footnote in the condition parameter list");

        }