Exemplo n.º 1
0
        public void TestNoInternal()
        {
            PolicyTemplate template = new PolicyTemplate();
            template.Load(policyFile);

            Options options = new Options(pdfExternal);

            SortedList<int, IAction> internalActions = template[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.Internal];
            SortedList<int, IAction> externalActions = template[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.External];

            Assert.AreEqual(1, internalActions.Count);
            Assert.AreEqual(1, externalActions.Count);

            PdfPolicy pdfPolicy = new PdfPolicy(template, options);
            pdfPolicy.Apply();

            string runtimePolicy = System.IO.Path.GetTempFileName();
            string myPolicy = System.IO.Path.GetTempFileName();
            template.Save(myPolicy, runtimePolicy);

            PolicyTemplate modifedTemplate = new PolicyTemplate();
            modifedTemplate.Load(myPolicy);

            internalActions = modifedTemplate[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.Internal];
            externalActions = modifedTemplate[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.External];

            Assert.AreEqual(0, internalActions.Count);
            Assert.AreEqual(1, externalActions.Count);

            modifedTemplate.Close();

            System.IO.File.Delete(runtimePolicy);
            System.IO.File.Delete(myPolicy);
        }
Exemplo n.º 2
0
        public void TestNoInternalExternal()
        {
            PolicyTemplate template = new PolicyTemplate();
            template.Load(policyFile);

            Options options = new Options(noPdf);

            SortedList<int, IAction> internalActions = template[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.Internal];
            SortedList<int, IAction> externalActions = template[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.External];

            Assert.AreEqual(1, internalActions.Count);
            Assert.AreEqual(1, externalActions.Count);

            PdfPolicy pdfPolicy = new PdfPolicy(template, options);
            pdfPolicy.Apply();

            string runtimePolicy = System.IO.Path.GetTempFileName();
            string myPolicy = System.IO.Path.GetTempFileName();
            template.Save(myPolicy, runtimePolicy);

            PolicyTemplate modifedTemplate = new PolicyTemplate();
            modifedTemplate.Load(myPolicy);

            try
            {
                IPolicy policy = modifedTemplate[TemplatePolicy.PdfPolicy];
                Assert.IsTrue(false, "The policy should have been removed");
            }
            catch (System.IndexOutOfRangeException)
            {
            }


            modifedTemplate.Close();

            System.IO.File.Delete(myPolicy);
            System.IO.File.Delete(runtimePolicy);
        }
Exemplo n.º 3
0
        public void TestAllowOverride()
        {
            PolicyTemplate template = new PolicyTemplate();
            template.Load(policyFile);

            Options options = new Options(pdfInternalExternal);

            IAction internalAction = template[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.Internal].Values[0];
            IAction externalAction = template[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.External].Values[0];

            IPolicyObjectCollection<IDataElement> dataElements = internalAction.DataElements;
            int allowOverride = 0;
            int total = dataElements.Count;
            foreach (IDataElement dataElement in dataElements)
            {
                if (string.Compare(dataElement["allowoverride"].Value, "true", true) == 0)
                {
                    allowOverride++;
                }
            }

            Option allowPdfOverride = options.Find(Sections.GeneralPolicy, "{b22927e1-afce-4081-8ebf-3187ee1bfc15}");
            allowPdfOverride.Value = "0";

            PdfPolicy pdfPolicy = new PdfPolicy(template, options);
            pdfPolicy.Apply();

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

            internalAction = modifedTemplate[TemplatePolicy.PdfPolicy, ChannelType.SMTP, Routing.Internal].Values[0];
            dataElements = internalAction.DataElements;
            int modifedAllowOverride = 0;
            int modifiedTotal = dataElements.Count;
            foreach (IDataElement dataElement in dataElements)
            {
                if (string.Compare(dataElement["allowoverride"].Value, "true", false) == 0)
                {
                    modifedAllowOverride++;
                }
            }

            modifedTemplate.Close();
            System.IO.File.Delete(myPolicy);
            System.IO.File.Delete(runtimePolicy);

            Assert.AreEqual(total, modifiedTotal, "The number of DataElements are not the same");
            Assert.AreEqual(0, modifedAllowOverride, "All the DataElement's allowoverride attributes should have been set to false");
        }