Ejemplo n.º 1
0
        public void PermissionState_None()
        {
            PermissionState ps = PermissionState.None;
            SmtpPermission  sp = new SmtpPermission(ps);

            Assert.IsFalse(sp.IsUnrestricted(), "IsUnrestricted");
            Assert.AreEqual(SmtpAccess.None, sp.Access, "Access");

            SecurityElement se = sp.ToXml();

            // only class and version are present
            Assert.AreEqual(2, se.Attributes.Count, "Xml-Attributes#");
            Assert.IsNull(se.Children, "Xml-Children");

            SmtpPermission copy = (SmtpPermission)sp.Copy();

            Assert.IsFalse(Object.ReferenceEquals(sp, copy), "ReferenceEquals");
            Assert.AreEqual(sp.IsUnrestricted(), copy.IsUnrestricted(), "IsUnrestricted ()");
            Assert.AreEqual(sp.Access, copy.Access, "copy.Access");
        }
Ejemplo n.º 2
0
        public void PermissionState_Unrestricted()
        {
            PermissionState ps = PermissionState.Unrestricted;
            SmtpPermission  sp = new SmtpPermission(ps);

            Assert.IsTrue(sp.IsUnrestricted(), "IsUnrestricted");
            Assert.AreEqual(SmtpAccess.ConnectToUnrestrictedPort, sp.Access, "Access");

            SecurityElement se = sp.ToXml();

            Assert.AreEqual("true", se.Attribute("Unrestricted"), "Xml-Unrestricted");
            Assert.AreEqual(3, se.Attributes.Count, "Xml-Attributes#");
            Assert.IsNull(se.Children, "Xml-Children");

            SmtpPermission copy = (SmtpPermission)sp.Copy();

            Assert.IsFalse(Object.ReferenceEquals(sp, copy), "ReferenceEquals");
            Assert.AreEqual(sp.IsUnrestricted(), copy.IsUnrestricted(), "IsUnrestricted ()");
            Assert.AreEqual(sp.Access, copy.Access, "copy.Access");
        }
Ejemplo n.º 3
0
        public void Ctor_SmtpAccess_Invalid()
        {
            SmtpAccess     sa = (SmtpAccess)Int32.MinValue;
            SmtpPermission sp = new SmtpPermission(sa);

            // no exception
            Assert.IsFalse(sp.IsUnrestricted(), "IsUnrestricted");
            Assert.AreEqual(sa, sp.Access, "Access");

            // invalid access doesn't get serialized to XML
            SecurityElement se = sp.ToXml();

            Assert.AreEqual(2, se.Attributes.Count, "Xml-Attributes#");
            Assert.IsNull(se.Children, "Xml-Children");

            // but it doesn't roundtrip
            SmtpPermission copy = (SmtpPermission)sp.Copy();

            Assert.AreEqual(sp.Access, copy.Access, "copy.Access");
        }
Ejemplo n.º 4
0
// </snippet2>

//<snippet3>
        public static SmtpPermission CreatePermissionCopy(SmtpPermission p)
        {
            SmtpPermission copy = (SmtpPermission)p.Copy();

            return(copy);
        }