ToXml() public method

public ToXml ( ) : SecurityElement
return System.Security.SecurityElement
		public void PermissionState_Unrestricted ()
		{
			PermissionState ps = PermissionState.Unrestricted;
			DnsPermission dp = new DnsPermission (ps);
			Assert.IsTrue (dp.IsUnrestricted (), "IsUnrestricted");

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

			DnsPermission copy = (DnsPermission)dp.Copy ();
			Assert.IsFalse (Object.ReferenceEquals (dp, copy), "ReferenceEquals");
			Assert.AreEqual (dp.IsUnrestricted (), copy.IsUnrestricted (), "IsUnrestricted ()");
		}
		public void PermissionState_None ()
		{
			PermissionState ps = PermissionState.None;
			DnsPermission dp = new DnsPermission (ps);
			Assert.IsFalse (dp.IsUnrestricted (), "IsUnrestricted");

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

			DnsPermission copy = (DnsPermission)dp.Copy ();
			Assert.IsFalse (Object.ReferenceEquals (dp, copy), "ReferenceEquals");
			Assert.AreEqual (dp.IsUnrestricted (), copy.IsUnrestricted (), "IsUnrestricted ()");
		}
		public void FromXml_NoVersion ()
		{
			DnsPermission dp = new DnsPermission (PermissionState.None);
			SecurityElement se = dp.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("class", se.Attribute ("class"));
			dp.FromXml (w);
		}
		public void FromXml_WrongVersion ()
		{
			DnsPermission dp = new DnsPermission (PermissionState.None);
			SecurityElement se = dp.ToXml ();
			se.Attributes.Remove ("version");
			se.Attributes.Add ("version", "2");
			dp.FromXml (se);
		}
		public void FromXml_NoClass ()
		{
			DnsPermission dp = new DnsPermission (PermissionState.None);
			SecurityElement se = dp.ToXml ();

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

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("class", "Wrong" + se.Attribute ("class"));
			w.AddAttribute ("version", se.Attribute ("version"));
			dp.FromXml (w);
			// doesn't care of the class name at that stage
			// anyway the class has already be created so...
		}
		public void FromXml_WrongTagCase ()
		{
			DnsPermission dp = new DnsPermission (PermissionState.None);
			SecurityElement se = dp.ToXml ();
			se.Tag = "IPERMISSION"; // instead of IPermission
			dp.FromXml (se);
			// note: normally IPermission classes (in corlib) DO care about the
			// IPermission tag
		}
		public void FromXml_WrongTag ()
		{
			DnsPermission dp = new DnsPermission (PermissionState.None);
			SecurityElement se = dp.ToXml ();
			se.Tag = "IMono";
			dp.FromXml (se);
			// note: normally IPermission classes (in corlib) DO care about the
			// IPermission tag
		}