public void Unrestricted() { SmtpPermissionAttribute a = new SmtpPermissionAttribute(SecurityAction.Assert); a.Unrestricted = true; SmtpPermission dp = (SmtpPermission)a.CreatePermission(); Assert.IsTrue(dp.IsUnrestricted(), "IsUnrestricted"); a.Unrestricted = false; dp = (SmtpPermission)a.CreatePermission(); Assert.IsFalse(dp.IsUnrestricted(), "!IsUnrestricted"); }
//</snippet3> // <snippet4> public static SmtpPermission CreateUnrestrictedPermission2() { SmtpPermission allAccess = new SmtpPermission(true); Console.WriteLine("Is unrestricted? {0}", allAccess.IsUnrestricted()); return(allAccess); }
// </snippet1> // <snippet2> public static SmtpPermission CreateUnrestrictedPermission() { SmtpPermission allAccess = new SmtpPermission(System.Security.Permissions.PermissionState.Unrestricted); Console.WriteLine("Is unrestricted? {0}", allAccess.IsUnrestricted()); return(allAccess); }
public void PermissionState_Bad() { PermissionState ps = (PermissionState)Int32.MinValue; SmtpPermission sp = new SmtpPermission(ps); // no ArgumentException here Assert.IsFalse(sp.IsUnrestricted()); Assert.AreEqual(SmtpAccess.None, sp.Access, "Access"); }
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"); }
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"); }
public void Ctor_Boolean_True() { SmtpPermission sp = new SmtpPermission(true); 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"); }
public void Ctor_SmtpAccess_None() { SmtpPermission sp = new SmtpPermission(SmtpAccess.None); 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"); }
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"); }
public void Intersect() { SmtpPermission spn = new SmtpPermission(PermissionState.None); Assert.IsNull(spn.Intersect(null), "None N null"); SmtpPermission inter = (SmtpPermission)spn.Intersect(spn); Assert.AreEqual(SmtpAccess.None, inter.Access, "None N None"); SmtpPermission spu = new SmtpPermission(PermissionState.Unrestricted); Assert.IsNull(spu.Intersect(null), "Unrestricted N null"); SmtpPermission result = (SmtpPermission)spu.Intersect(spu); Assert.IsTrue(result.IsUnrestricted(), "Unrestricted N Unrestricted"); inter = (SmtpPermission)spn.Intersect(spu); Assert.AreEqual(SmtpAccess.None, inter.Access, "None N Unrestricted"); inter = (SmtpPermission)spu.Intersect(spn); Assert.AreEqual(SmtpAccess.None, inter.Access, "Unrestricted N None"); }
public void Union() { SmtpPermission spn = new SmtpPermission(PermissionState.None); SmtpPermission spu = new SmtpPermission(PermissionState.Unrestricted); SmtpPermission result = (SmtpPermission)spn.Union(null); Assert.IsFalse(result.IsUnrestricted(), "None U null"); result = (SmtpPermission)spu.Union(null); Assert.IsTrue(result.IsUnrestricted(), "Unrestricted U null"); result = (SmtpPermission)spn.Union(spn); Assert.IsFalse(result.IsUnrestricted(), "None U None"); result = (SmtpPermission)spu.Union(spu); Assert.IsTrue(result.IsUnrestricted(), "Unrestricted U Unrestricted"); result = (SmtpPermission)spn.Union(spu); Assert.IsTrue(result.IsUnrestricted(), "None U Unrestricted"); result = (SmtpPermission)spu.Union(spn); Assert.IsTrue(result.IsUnrestricted(), "Unrestricted U None"); }