ToXml() public method

public ToXml ( ) : SecurityElement
return System.Security.SecurityElement
Exemplo n.º 1
0
		public void PermissionStateUnrestricted ()
		{
			// In 2.0 Unrestricted are permitted for identity permissions
			ZoneIdentityPermission zip = new ZoneIdentityPermission (PermissionState.Unrestricted);
			Assert.AreEqual (SecurityZone.NoZone, zip.SecurityZone);
			SecurityElement se = zip.ToXml ();
			Assert.AreEqual (5, se.Children.Count, "Count");
			// and they aren't equals to None
			Assert.IsFalse (zip.Equals (new ZoneIdentityPermission (PermissionState.None)));
		}
Exemplo n.º 2
0
		private ZoneIdentityPermission BasicTestZone (SecurityZone zone, bool special)
		{
			ZoneIdentityPermission zip = new ZoneIdentityPermission (zone);
			Assert.AreEqual (zone, zip.SecurityZone, "SecurityZone");
			
			ZoneIdentityPermission copy = (ZoneIdentityPermission) zip.Copy ();
			Assert.IsTrue (Same (zip, copy), "Equals-Copy");
			Assert.IsTrue (zip.IsSubsetOf (copy), "IsSubset-1");
			Assert.IsTrue (copy.IsSubsetOf (zip), "IsSubset-2");
			if (special) {
				Assert.IsFalse (zip.IsSubsetOf (null), "IsSubset-Null");
			}
			
			IPermission intersect = zip.Intersect (copy);
			if (special) {
				Assert.IsTrue (intersect.IsSubsetOf (zip), "IsSubset-3");
				Assert.IsFalse (Object.ReferenceEquals (zip, intersect), "!ReferenceEquals1");
				Assert.IsTrue (intersect.IsSubsetOf (copy), "IsSubset-4");
				Assert.IsFalse (Object.ReferenceEquals (copy, intersect), "!ReferenceEquals2");
			}

			Assert.IsNull (zip.Intersect (null), "Intersect with null");

			intersect = zip.Intersect (new ZoneIdentityPermission (PermissionState.None));
			Assert.IsNull (intersect, "Intersect with PS.None");

			// note: can't be tested with PermissionState.Unrestricted

			// XML roundtrip
			SecurityElement se = zip.ToXml ();
			copy.FromXml (se);
			Assert.IsTrue (Same (zip, copy), "Equals-Xml");

			return zip;
		}
Exemplo n.º 3
0
		public void FromXml_NoVersion ()
		{
			ZoneIdentityPermission zip = new ZoneIdentityPermission (PermissionState.None);
			SecurityElement se = zip.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("class", se.Attribute ("class"));
			zip.FromXml (w);
		}
Exemplo n.º 4
0
		public void FromXml_NoClass ()
		{
			ZoneIdentityPermission zip = new ZoneIdentityPermission (PermissionState.None);
			SecurityElement se = zip.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("version", se.Attribute ("version"));
			zip.FromXml (w);
			// doesn't even care of the class attribute presence
		}
Exemplo n.º 5
0
		public void FromXml_WrongClass ()
		{
			ZoneIdentityPermission zip = new ZoneIdentityPermission (PermissionState.None);
			SecurityElement se = zip.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("class", "Wrong" + se.Attribute ("class"));
			w.AddAttribute ("version", se.Attribute ("version"));
			zip.FromXml (w);
			// doesn't care of the class name at that stage
			// anyway the class has already be created so...
		}
Exemplo n.º 6
0
		public void FromXml_WrongTagCase ()
		{
			ZoneIdentityPermission zip = new ZoneIdentityPermission (PermissionState.None);
			SecurityElement se = zip.ToXml ();
			se.Tag = "IPERMISSION"; // instead of IPermission
			zip.FromXml (se);
		}