public void FromXml_WrongVersion()
        {
            PrintingPermission pp = new PrintingPermission(PermissionState.None);
            SecurityElement    se = pp.ToXml();

            se.Attributes.Remove("version");
            se.Attributes.Add("version", "2");
            pp.FromXml(se);
        }
        public void FromXml_NoVersion()
        {
            PrintingPermission pp = new PrintingPermission(PermissionState.None);
            SecurityElement    se = pp.ToXml();

            SecurityElement w = new SecurityElement(se.Tag);

            w.AddAttribute("class", se.Attribute("class"));
            pp.FromXml(w);
        }
        public void FromXml_WrongTagCase()
        {
            PrintingPermission pp = new PrintingPermission(PermissionState.None);
            SecurityElement    se = pp.ToXml();

            se.Tag = "IPERMISSION";             // instead of IPermission
            pp.FromXml(se);
            // note: normally IPermission classes (in corlib) DO care about the
            // IPermission tag
        }
 public void FromXml_WrongVersion()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         PrintingPermission pp = new PrintingPermission(PermissionState.None);
         SecurityElement se    = pp.ToXml();
         se.Attributes.Remove("version");
         se.Attributes.Add("version", "2");
         pp.FromXml(se);
     });
 }
        public void FromXml_NoClass()
        {
            PrintingPermission pp = new PrintingPermission(PermissionState.None);
            SecurityElement    se = pp.ToXml();

            SecurityElement w = new SecurityElement(se.Tag);

            w.AddAttribute("version", se.Attribute("version"));
            pp.FromXml(w);
            // note: normally IPermission classes (in corlib) DO NOT care about
            // attribute "class" name presence in the XML
        }
        public void FromXml_WrongClass()
        {
            PrintingPermission pp = new PrintingPermission(PermissionState.None);
            SecurityElement    se = pp.ToXml();

            SecurityElement w = new SecurityElement(se.Tag);

            w.AddAttribute("class", "Wrong" + se.Attribute("class"));
            w.AddAttribute("version", se.Attribute("version"));
            pp.FromXml(w);
            // doesn't care of the class name at that stage
            // anyway the class has already be created so...
        }
        public void PermissionState_Unrestricted()
        {
            PermissionState    ps = PermissionState.Unrestricted;
            PrintingPermission pp = new PrintingPermission(ps);

            Assert.AreEqual(PrintingPermissionLevel.AllPrinting, pp.Level, "Level");
            Assert.IsTrue(pp.IsUnrestricted(), "IsUnrestricted");

            SecurityElement se = pp.ToXml();

            // only class and version are present
            Assert.AreEqual("true", se.Attribute("Unrestricted"), "Xml-Unrestricted");
            Assert.IsNull(se.Children, "Xml-Children");

            PrintingPermission copy = (PrintingPermission)pp.Copy();

            Assert.IsFalse(Object.ReferenceEquals(pp, copy), "ReferenceEquals");
            Assert.AreEqual(pp.Level, copy.Level, "Level");
            Assert.AreEqual(pp.IsUnrestricted(), copy.IsUnrestricted(), "IsUnrestricted ()");
        }