ToXml() public method

public ToXml ( ) : SecurityElement
return System.Security.SecurityElement
		public void PermissionStateNone () 
		{
			PublisherIdentityPermission p = new PublisherIdentityPermission (PermissionState.None);
			Assert.IsNotNull (p, "PublisherIdentityPermission(PermissionState.None)");
			PublisherIdentityPermission copy = (PublisherIdentityPermission) p.Copy ();
			SecurityElement se = p.ToXml ();
			Assert.IsTrue (se.Attribute ("class").StartsWith (className), "ToXml-class");
			Assert.AreEqual ("1", se.Attribute("version"), "ToXml-version");
			Assert.IsNull (se.Attribute("Unrestricted"), "ToXml-Unrestricted");
			Assert.IsNull (p.Certificate, "Certificate==null");
		}
		public void Union () 
		{
			// with no certificates
			PublisherIdentityPermission p1 = new PublisherIdentityPermission (PermissionState.None);
			PublisherIdentityPermission p2 = new PublisherIdentityPermission (PermissionState.None);
			PublisherIdentityPermission p3 = (PublisherIdentityPermission) p1.Union (p2);
			Assert.IsNull (p3, "None U None == null");
			// with 1 certificate
			p1 = new PublisherIdentityPermission (x509);
			p2 = new PublisherIdentityPermission (PermissionState.None);
			p3 = (PublisherIdentityPermission) p1.Union (p2);
			Assert.AreEqual (p3.ToXml ().ToString (), p1.ToXml ().ToString (), "cert U None == cert");
			X509Certificate x2 = new X509Certificate (cert2);
			// 2 certificates (same)
			x2 = new X509Certificate (cert);
			p2 = new PublisherIdentityPermission (x2);
			p3 = (PublisherIdentityPermission) p1.Union (p2);
			Assert.AreEqual (p3.ToString (), p1.ToString (), "cert1 U cert1 == cert1");
		}
		public void Union_DifferentCertificates ()
		{
			PublisherIdentityPermission p1 = new PublisherIdentityPermission (x509);
			X509Certificate x2 = new X509Certificate (cert2);
			PublisherIdentityPermission p2 = new PublisherIdentityPermission (x2);
			IPermission p = p1.Union (p2);
			// new XML format is used to contain more than one X.509 certificate
			SecurityElement se = p.ToXml ();
			Assert.AreEqual (2, se.Children.Count, "Childs");
			Assert.AreEqual ((se.Children [0] as SecurityElement).Attribute ("X509v3Certificate"), p1.ToXml ().Attribute ("X509v3Certificate"), "Cert#1");
			Assert.AreEqual ((se.Children [1] as SecurityElement).Attribute ("X509v3Certificate"), p2.ToXml ().Attribute ("X509v3Certificate"), "Cert#2");
			// strangely it is still versioned as 'version="1"'.
			Assert.AreEqual ("1", se.Attribute ("version"), "Version");
		}
		public void FromXml () 
		{
			PublisherIdentityPermission p = new PublisherIdentityPermission (PermissionState.None);
			SecurityElement se = p.ToXml ();
			Assert.IsNotNull (se, "ToXml()");
			p.FromXml (se);

			se.AddAttribute ("X509v3Certificate", x509.GetRawCertDataString ());
			p.FromXml (se);
			Assert.AreEqual (x509.GetCertHashString (), p.Certificate.GetCertHashString (), "CertificateHash");
		}
		public void UnionWithNull () 
		{
			PublisherIdentityPermission p1 = new PublisherIdentityPermission (x509);
			PublisherIdentityPermission p2 = null;
			PublisherIdentityPermission p3 = (PublisherIdentityPermission) p1.Union (p2);
			Assert.AreEqual (p1.ToXml ().ToString (), p3.ToXml ().ToString (), "P1 U null == P1");
		}
		public void FromXmlWrongVersion () 
		{
			PublisherIdentityPermission p = new PublisherIdentityPermission (PermissionState.None);
			SecurityElement se = p.ToXml ();
			// can't modify - so we create our own
			SecurityElement se2 = new SecurityElement (se.Tag, se.Text);
			se2.AddAttribute ("class", se.Attribute ("class"));
			se2.AddAttribute ("version", "2");
			p.FromXml (se2);
		}
		public void Certificate () 
		{
			PublisherIdentityPermission p1 = new PublisherIdentityPermission (x509);

			PublisherIdentityPermission p2 = new PublisherIdentityPermission (PermissionState.None);
			p2.Certificate = x509;

			Assert.AreEqual (p1.ToXml ().ToString (), p2.ToXml ().ToString (), "Certificate");
		}
		public void PermissionStateUnrestricted ()
		{
			// In 2.0 Unrestricted are permitted for identity permissions
			PublisherIdentityPermission p = new PublisherIdentityPermission (PermissionState.Unrestricted);
			Assert.IsNotNull (p, "PublisherIdentityPermission(PermissionState.None)");
			PublisherIdentityPermission copy = (PublisherIdentityPermission)p.Copy ();
			SecurityElement se = p.ToXml ();
			Assert.IsTrue (se.Attribute ("class").StartsWith (className), "ToXml-class");
			Assert.AreEqual ("1", se.Attribute("version"), "ToXml-version");
			Assert.AreEqual ("true", se.Attribute("Unrestricted"), "ToXml-Unrestricted");
			Assert.IsNull (p.Certificate, "Certificate==null");
			// and they aren't equals to None
			Assert.IsTrue (!p.Equals (new PublisherIdentityPermission (PermissionState.None)));
		}
		public void PermissionStateNone () 
		{
			PublisherIdentityPermission p = new PublisherIdentityPermission (PermissionState.None);
			AssertNotNull ("PublisherIdentityPermission(PermissionState.None)", p);
			PublisherIdentityPermission copy = (PublisherIdentityPermission) p.Copy ();
			SecurityElement se = p.ToXml ();
			Assert ("ToXml-class", se.Attribute ("class").StartsWith (className));
			AssertEquals ("ToXml-version", "1", se.Attribute("version"));
			AssertNull ("ToXml-Unrestricted", se.Attribute("Unrestricted"));
			AssertNull ("Certificate==null", p.Certificate);
		}
		public void Union_DifferentCertificates ()
		{
			PublisherIdentityPermission p1 = new PublisherIdentityPermission (x509);
			X509Certificate x2 = new X509Certificate (cert2);
			PublisherIdentityPermission p2 = new PublisherIdentityPermission (x2);
			IPermission p = p1.Union (p2);
#if NET_2_0
			// new XML format is used to contain more than one X.509 certificate
			SecurityElement se = p.ToXml ();
			AssertEquals ("Childs", 2, se.Children.Count);
			AssertEquals ("Cert#1", (se.Children [0] as SecurityElement).Attribute ("X509v3Certificate"), p1.ToXml ().Attribute ("X509v3Certificate"));
			AssertEquals ("Cert#2", (se.Children [1] as SecurityElement).Attribute ("X509v3Certificate"), p2.ToXml ().Attribute ("X509v3Certificate"));
			// strangely it is still versioned as 'version="1"'.
			AssertEquals ("Version", "1", se.Attribute ("version"));
#else
			AssertNull ("cert1 U cert2 == null", p);
#endif
		}