ToXml() public method

public ToXml ( ) : SecurityElement
return SecurityElement
Esempio n. 1
0
		public void AddToPermissionSet ()
		{
			PolicyStatement ps = new PolicyStatement (null);
			Assert.AreEqual (Empty.ToString (), ps.PermissionSet.ToString (), "Empty");

			SecurityPermission sp = new SecurityPermission (SecurityPermissionFlag.Execution);
			IPermission p = ps.PermissionSet.AddPermission (sp);
			Assert.AreEqual (sp.ToXml ().ToString (), p.ToXml ().ToString (), "AddPermission");

			// but nothing was added
			Assert.AreEqual (Empty.ToString (), ps.PermissionSet.ToString (), "Still Empty");
			// and (strangely) it's not considered a read-only permission set 
			// as this property is always false for PermissionSet
			Assert.IsFalse (ps.PermissionSet.IsReadOnly, "IsReadOnly");
		}
		public void FromXml_WrongVersion ()
		{
			SecurityPermission sp = new SecurityPermission (PermissionState.None);
			SecurityElement se = sp.ToXml ();
			se.Attributes.Remove ("version");
			se.Attributes.Add ("version", "2");
			sp.FromXml (se);
		}
		public void FromXml_NoVersion ()
		{
			SecurityPermission sp = new SecurityPermission (PermissionState.None);
			SecurityElement se = sp.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("class", se.Attribute ("class"));
			sp.FromXml (w);
		}
		public void FromXml_NoClass ()
		{
			SecurityPermission sp = new SecurityPermission (PermissionState.None);
			SecurityElement se = sp.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("version", se.Attribute ("version"));
			sp.FromXml (w);
			// doesn't even care of the class attribute presence
		}
		public void FromXml_WrongClass ()
		{
			SecurityPermission sp = new SecurityPermission (PermissionState.None);
			SecurityElement se = sp.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("class", "Wrong" + se.Attribute ("class"));
			w.AddAttribute ("version", se.Attribute ("version"));
			sp.FromXml (w);
			// doesn't care of the class name at that stage
			// anyway the class has already be created so...
		}
		public void FromXml_WrongTagCase ()
		{
			SecurityPermission sp = new SecurityPermission (PermissionState.None);
			SecurityElement se = sp.ToXml ();
			se.Tag = "IPERMISSION"; // instead of IPermission
			sp.FromXml (se);
		}
		public void FromXml_WrongTag ()
		{
			SecurityPermission sp = new SecurityPermission (PermissionState.None);
			SecurityElement se = sp.ToXml ();
			se.Tag = "IMono";
			sp.FromXml (se);
		}
		public void PermissionState_Unrestricted ()
		{
			PermissionState ps = PermissionState.Unrestricted;
			SecurityPermission sp = new SecurityPermission (ps);
			Assert.AreEqual (SecurityPermissionFlag.AllFlags, sp.Flags, "Flags");
			Assert.IsTrue (sp.IsUnrestricted (), "IsUnrestricted");

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

			SecurityPermission copy = (SecurityPermission)sp.Copy ();
			Assert.IsFalse (Object.ReferenceEquals (sp, copy), "ReferenceEquals");
			Assert.AreEqual (sp.Flags, copy.Flags, "Flags");
			Assert.AreEqual (sp.IsUnrestricted (), copy.IsUnrestricted (), "IsUnrestricted ()");
		}