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.
30 using NUnit.Framework;
32 using System.Security;
33 using System.Security.Policy;
35 namespace MonoTests.System.Security.Policy {
38 public class GacMembershipConditionTest {
41 public void Constructor ()
43 GacMembershipCondition gac = new GacMembershipCondition ();
44 Assert.IsNotNull (gac);
50 GacMembershipCondition gac = new GacMembershipCondition ();
52 Assert.IsFalse (gac.Check (e), "Check (null)");
54 Assert.IsFalse (gac.Check (e), "Check (empty)");
55 e.AddHost (new Zone (SecurityZone.MyComputer));
56 Assert.IsFalse (gac.Check (e), "Check (zone)");
57 GacInstalled g = new GacInstalled ();
59 Assert.IsFalse (gac.Check (e), "Check (gac-assembly)");
61 Assert.IsTrue (gac.Check (e), "Check (gac-host)");
67 GacMembershipCondition gac = new GacMembershipCondition ();
68 GacMembershipCondition copy = (GacMembershipCondition) gac.Copy ();
69 Assert.AreEqual (gac, copy, "Equals");
70 Assert.IsFalse (Object.ReferenceEquals (gac, copy), "ReferenceEquals");
76 GacMembershipCondition gac = new GacMembershipCondition ();
77 Assert.IsFalse (gac.Equals (null), "Equals(null)");
78 GacMembershipCondition g2 = new GacMembershipCondition ();
79 Assert.IsTrue (gac.Equals (g2), "Equals(g2)");
80 Assert.IsTrue (g2.Equals (gac), "Equals(gac)");
84 [ExpectedException (typeof (ArgumentNullException))]
85 public void FromXml_Null ()
87 GacMembershipCondition gac = new GacMembershipCondition ();
92 public void FromXml ()
94 GacMembershipCondition gac = new GacMembershipCondition ();
95 SecurityElement se = gac.ToXml ();
100 [ExpectedException (typeof (ArgumentException))]
101 public void FromXml_InvalidTag ()
103 GacMembershipCondition gac = new GacMembershipCondition ();
104 SecurityElement se = gac.ToXml ();
105 se.Tag = "IMonoship";
110 public void FromXml_InvalidClass ()
112 GacMembershipCondition gac = new GacMembershipCondition ();
113 SecurityElement se = gac.ToXml ();
114 se.Attributes ["class"] = "Hello world";
119 public void FromXml_NoClass ()
121 GacMembershipCondition gac = new GacMembershipCondition ();
122 SecurityElement se = gac.ToXml ();
124 SecurityElement w = new SecurityElement (se.Tag);
125 w.AddAttribute ("version", se.Attribute ("version"));
127 // doesn't even care of the class attribute presence
131 public void FromXml_InvalidVersion ()
133 GacMembershipCondition gac = new GacMembershipCondition ();
134 SecurityElement se = gac.ToXml ();
136 SecurityElement w = new SecurityElement (se.Tag);
137 w.AddAttribute ("class", se.Attribute ("class"));
138 w.AddAttribute ("version", "2");
143 public void FromXml_NoVersion ()
145 GacMembershipCondition gac = new GacMembershipCondition ();
146 SecurityElement se = gac.ToXml ();
148 SecurityElement w = new SecurityElement (se.Tag);
149 w.AddAttribute ("class", se.Attribute ("class"));
157 [ExpectedException (typeof (ArgumentNullException))]
158 public void FromXml_SecurityElementNull ()
160 GacMembershipCondition gac = new GacMembershipCondition ();
161 gac.FromXml (null, PolicyLevel.CreateAppDomainLevel ());
165 public void FromXml_PolicyLevelNull ()
167 GacMembershipCondition gac = new GacMembershipCondition ();
168 SecurityElement se = gac.ToXml ();
169 gac.FromXml (se, null);
173 public void GetHashCode_ ()
175 GacMembershipCondition gac = new GacMembershipCondition ();
176 Assert.AreEqual (0, gac.GetHashCode ());
180 public void ToString_ ()
182 GacMembershipCondition gac = new GacMembershipCondition ();
183 Assert.AreEqual ("GAC", gac.ToString ());
192 GacMembershipCondition gac = new GacMembershipCondition ();
193 SecurityElement se = gac.ToXml ();
194 Assert.AreEqual ("IMembershipCondition", se.Tag, "Tag");
195 Assert.IsTrue (se.Attribute ("class").StartsWith ("System.Security.Policy.GacMembershipCondition"), "class");
196 Assert.AreEqual ("1", se.Attribute ("version"), "version");
197 Assert.AreEqual (se.ToString (), gac.ToXml (null).ToString (), "ToXml(null)");
198 Assert.AreEqual (se.ToString (), gac.ToXml (PolicyLevel.CreateAppDomainLevel ()).ToString (), "ToXml(PolicyLevel)");