ToXml() public method

public ToXml ( ) : SecurityElement
return System.Security.SecurityElement
Exemplo n.º 1
0
		private void CommonTests (AspNetHostingPermission p)
		{
			Assert.IsNotNull (p.Copy (), "Copy");
			SecurityElement se = p.ToXml ();
			Assert.IsNotNull (se, "ToXml");
			p.FromXml (se);
			Assert.IsNotNull (p.Intersect (p), "Intersect");
			Assert.IsTrue (p.IsSubsetOf (p), "IsSubsetOf");
			Assert.IsNotNull (p.Union (p), "Union");
		}
		public void PermissionState_None ()
		{
			PermissionState ps = PermissionState.None;
			AspNetHostingPermission anhp = new AspNetHostingPermission (ps);
			Assert.AreEqual (AspNetHostingPermissionLevel.None, anhp.Level, "Level");
			Assert.IsFalse (anhp.IsUnrestricted (), "IsUnrestricted");

			SecurityElement se = anhp.ToXml ();
			// only class and version are present
			Assert.AreEqual ("None", se.Attribute ("Level"), "Xml-Level");
			Assert.IsNull (se.Children, "Xml-Children");

			AspNetHostingPermission copy = (AspNetHostingPermission)anhp.Copy ();
			Assert.IsFalse (Object.ReferenceEquals (anhp, copy), "ReferenceEquals");
			Assert.AreEqual (anhp.Level, copy.Level, "Level");
			Assert.AreEqual (anhp.IsUnrestricted (), copy.IsUnrestricted (), "IsUnrestricted ()");
		}
		public void PermissionState_Unrestricted ()
		{
			PermissionState ps = PermissionState.Unrestricted;
			AspNetHostingPermission anhp = new AspNetHostingPermission (ps);
			Assert.AreEqual (AspNetHostingPermissionLevel.Unrestricted, anhp.Level, "Level");
			Assert.IsTrue (anhp.IsUnrestricted (), "IsUnrestricted");

			SecurityElement se = anhp.ToXml ();
			// fixed in 2.0 RC
			Assert.IsNotNull (se.Attribute ("Unrestricted"), "Xml-Unrestricted");
			Assert.AreEqual ("Unrestricted", se.Attribute ("Level"), "Xml-Level");
			Assert.IsNull (se.Children, "Xml-Children");

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

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

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

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