2 // GacMembershipConditionTest.cs - NUnit Test Cases for GacMembershipCondition
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using NUnit.Framework;
33 using System.Security;
34 using System.Security.Policy;
36 namespace MonoTests.System.Security.Policy {
39 public class GacMembershipConditionTest {
42 public void Constructor ()
44 GacMembershipCondition gac = new GacMembershipCondition ();
45 Assert.IsNotNull (gac);
51 GacMembershipCondition gac = new GacMembershipCondition ();
53 Assert.IsFalse (gac.Check (e), "Check (null)");
55 Assert.IsFalse (gac.Check (e), "Check (empty)");
56 e.AddHost (new Zone (SecurityZone.MyComputer));
57 Assert.IsFalse (gac.Check (e), "Check (zone)");
60 Assert.IsFalse (gac.Check (e), "Check (gac-assembly)");
62 Assert.IsTrue (gac.Check (e), "Check (gac-host)");
68 GacMembershipCondition gac = new GacMembershipCondition ();
69 GacMembershipCondition copy = (GacMembershipCondition) gac.Copy ();
70 Assert.AreEqual (gac, copy, "Equals");
71 Assert.IsFalse (Object.ReferenceEquals (gac, copy), "ReferenceEquals");
77 GacMembershipCondition gac = new GacMembershipCondition ();
78 Assert.IsFalse (gac.Equals (null), "Equals(null)");
79 GacMembershipCondition g2 = new GacMembershipCondition ();
80 Assert.IsTrue (gac.Equals (g2), "Equals(g2)");
81 Assert.IsTrue (g2.Equals (gac), "Equals(gac)");
85 [ExpectedException (typeof (ArgumentNullException))]
86 public void FromXml_Null ()
88 GacMembershipCondition gac = new GacMembershipCondition ();
93 public void FromXml ()
95 GacMembershipCondition gac = new GacMembershipCondition ();
96 SecurityElement se = gac.ToXml ();
101 [ExpectedException (typeof (ArgumentException))]
102 public void FromXml_InvalidTag ()
104 GacMembershipCondition gac = new GacMembershipCondition ();
105 SecurityElement se = gac.ToXml ();
106 se.Tag = "IMonoship";
111 public void FromXml_InvalidClass ()
113 GacMembershipCondition gac = new GacMembershipCondition ();
114 SecurityElement se = gac.ToXml ();
115 se.Attributes ["class"] = "Hello world";
120 public void FromXml_NoClass ()
122 GacMembershipCondition gac = new GacMembershipCondition ();
123 SecurityElement se = gac.ToXml ();
125 SecurityElement w = new SecurityElement (se.Tag);
126 w.AddAttribute ("version", se.Attribute ("version"));
128 // doesn't even care of the class attribute presence
132 public void FromXml_InvalidVersion ()
134 GacMembershipCondition gac = new GacMembershipCondition ();
135 SecurityElement se = gac.ToXml ();
137 SecurityElement w = new SecurityElement (se.Tag);
138 w.AddAttribute ("class", se.Attribute ("class"));
139 w.AddAttribute ("version", "2");
144 public void FromXml_NoVersion ()
146 GacMembershipCondition gac = new GacMembershipCondition ();
147 SecurityElement se = gac.ToXml ();
149 SecurityElement w = new SecurityElement (se.Tag);
150 w.AddAttribute ("class", se.Attribute ("class"));
155 [ExpectedException (typeof (ArgumentNullException))]
156 public void FromXml_SecurityElementNull ()
158 GacMembershipCondition gac = new GacMembershipCondition ();
159 gac.FromXml (null, PolicyLevel.CreateAppDomainLevel ());
163 public void FromXml_PolicyLevelNull ()
165 GacMembershipCondition gac = new GacMembershipCondition ();
166 SecurityElement se = gac.ToXml ();
167 gac.FromXml (se, null);
171 public void GetHashCode_ ()
173 GacMembershipCondition gac = new GacMembershipCondition ();
174 Assert.AreEqual (0, gac.GetHashCode ());
178 public void ToString_ ()
180 GacMembershipCondition gac = new GacMembershipCondition ();
181 Assert.AreEqual ("GAC", gac.ToString ());
187 GacMembershipCondition gac = new GacMembershipCondition ();
188 SecurityElement se = gac.ToXml ();
189 Assert.AreEqual ("IMembershipCondition", se.Tag, "Tag");
190 Assert.IsTrue (se.Attribute ("class").StartsWith ("System.Security.Policy.GacMembershipCondition"), "class");
191 Assert.AreEqual ("1", se.Attribute ("version"), "version");
192 Assert.AreEqual (se.ToString (), gac.ToXml (null).ToString (), "ToXml(null)");
193 Assert.AreEqual (se.ToString (), gac.ToXml (PolicyLevel.CreateAppDomainLevel ()).ToString (), "ToXml(PolicyLevel)");