public void SiteMembershipCondition_GoMonoWebSite () 
		{
			SiteMembershipCondition smc = new SiteMembershipCondition ("www.go-mono.com");
			Assert.AreEqual ("www.go-mono.com", smc.Site, "Site");
			Assert.AreEqual ("Site - www.go-mono.com", smc.ToString (), "ToString");

			SiteMembershipCondition smc2 = (SiteMembershipCondition) smc.Copy ();
			Assert.AreEqual (smc.Site, smc2.Site, "Copy.Site");
			Assert.AreEqual (smc.GetHashCode (), smc2.GetHashCode (), "Copy.GetHashCode");

			SecurityElement se = smc2.ToXml ();
			SiteMembershipCondition smc3 = new SiteMembershipCondition ("*");
			smc3.FromXml (se);
			Assert.AreEqual (smc.Site, smc3.Site, "ToXml/FromXml");

			Assert.IsTrue (smc.Equals (smc2), "Equals");
			SiteMembershipCondition smc4 = new SiteMembershipCondition ("go-mono.com");
			Assert.IsFalse (smc.Equals (smc4), "!Equals");
		}
		public void SiteMembershipCondition_FileUrl () 
		{
			SiteMembershipCondition smc = new SiteMembershipCondition ("file://mono/index.html");
		}
		public void SiteMembershipCondition_Empty () 
		{
			SiteMembershipCondition smc = new SiteMembershipCondition (String.Empty);
		}
		public void SiteMembershipCondition_Null () 
		{
			SiteMembershipCondition smc = new SiteMembershipCondition (null);
		}
		public void ToFromXmlRoundTrip () 
		{
			SiteMembershipCondition smc1 = new SiteMembershipCondition ("*.go-mono.com");
			SecurityElement se = smc1.ToXml ();

			SiteMembershipCondition smc2 = new SiteMembershipCondition ("*");
			smc2.FromXml (se);

			Assert.AreEqual (smc1.GetHashCode (), smc2.GetHashCode (), "ToFromXmlRoundTrip");
		}
		public void ToXml_PolicyLevel () 
		{
			SiteMembershipCondition smc = new SiteMembershipCondition ("*.go-mono.com");
			SecurityElement se = smc.ToXml ();
			string s = smc.ToXml ().ToString ();
			// is it accepted for all policy levels ?
			IEnumerator e = SecurityManager.PolicyHierarchy ();
			while (e.MoveNext ()) {
				PolicyLevel pl = e.Current as PolicyLevel;
				SiteMembershipCondition spl = new SiteMembershipCondition ("*");
				spl.FromXml (se, pl);
				Assert.AreEqual (s, spl.ToXml (pl).ToString (), "ToXml(PolicyLevel='" + pl.Label + "')");
			}
			// yes!
		}
		public void ToXml_Null () 
		{
			SiteMembershipCondition smc = new SiteMembershipCondition ("*.go-mono.com");
			// no ArgumentNullException here
			SecurityElement se = smc.ToXml (null);
			Assert.IsNotNull (se, "ToXml(null)");
		}
		public void Check () 
		{
			SiteMembershipCondition smc = new SiteMembershipCondition ("*.go-mono.com");

			Evidence e = null;
			Assert.IsFalse (smc.Check (e), "Check(null)");
			e = new Evidence ();
			Assert.IsFalse (smc.Check (e), "Check (empty)");
			e.AddHost (new Zone (SecurityZone.MyComputer));
			Assert.IsFalse (smc.Check (e), "Check (zone)");
			
			Site s = new Site ("*.go-mono.com");
			e.AddAssembly (s);
			Assert.IsFalse (smc.Check (e), "Check (site-assembly)");
			e.AddHost (s);
			Assert.IsTrue (smc.Check (e), "Check (site-host)");

			e = new Evidence ();
			e.AddHost (new Site ("www.go-mono.com"));
			Assert.IsTrue (smc.Check (e), "Check(+-)");

			e = new Evidence ();
			e.AddHost (new Site ("*.go-mono.org"));
			Assert.IsFalse (smc.Check (e), "Check(-)");
		}
		public void FromXml_InvalidVersion ()
		{
			SiteMembershipCondition smc = new SiteMembershipCondition ("*.go-mono.com");
			SecurityElement se = smc.ToXml ();
			se.Attributes ["version"] = "2";
			smc.FromXml (se);
		}
		public void FromXml_NoClass ()
		{
			SiteMembershipCondition smc = new SiteMembershipCondition ("*.go-mono.com");
			SecurityElement se = smc.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("version", se.Attribute ("version"));
			smc.FromXml (w);
			// doesn't even care of the class attribute presence
		}
		public void FromXml_InvalidClass ()
		{
			SiteMembershipCondition smc = new SiteMembershipCondition ("*.go-mono.com");
			SecurityElement se = smc.ToXml ();
			se.Attributes ["class"] = "Hello world";
			smc.FromXml (se);
		}
		public void FromXml_InvalidTag () 
		{
			SiteMembershipCondition smc = new SiteMembershipCondition ("*.go-mono.com");
			SecurityElement se = smc.ToXml ();
			se.Tag = "IMonoship";
			smc.FromXml (se);
		}
		public void FromXml_Null () 
		{
			SiteMembershipCondition smc = new SiteMembershipCondition ("*.go-mono.com");
			smc.FromXml (null);
		}
		public void Equals () 
		{
			SiteMembershipCondition smc1 = new SiteMembershipCondition ("*.go-mono.com");
			Assert.IsFalse (smc1.Equals (null), "Null");
			SiteMembershipCondition smc2 = new SiteMembershipCondition ("*.Go-Mono.com");
			Assert.IsTrue (smc1.Equals (smc2), "CaseSensitive");
		}
		public void SiteMembershipCondition_FullUrlWithPort () 
		{
			SiteMembershipCondition smc = new SiteMembershipCondition ("http://www.go-mono.com:8080/index.html");
		}
		public void FromXml_NoVersion ()
		{
			SiteMembershipCondition smc = new SiteMembershipCondition ("*.go-mono.com");
			SecurityElement se = smc.ToXml ();

			SecurityElement w = new SecurityElement (se.Tag);
			w.AddAttribute ("class", se.Attribute ("class"));
			smc.FromXml (w);
		}
Esempio n. 17
0
 public static void SiteMembershipConditionCallMethods()
 {
     SiteMembershipCondition smc = new SiteMembershipCondition("test");
     bool check = smc.Check(new Evidence());
     IMembershipCondition obj = smc.Copy();
     check = smc.Equals(new object());
     int hash = smc.GetHashCode();
     string str = smc.ToString();
     SecurityElement se = new SecurityElement("");
     PolicyLevel pl = (PolicyLevel)Activator.CreateInstance(typeof(PolicyLevel), true);
     smc.FromXml(se);
     smc.FromXml(se, pl);
     se = smc.ToXml();
     se = smc.ToXml(pl);
 }