2 // ApplicationMembershipConditionTest.cs -
3 // NUnit Test Cases for ApplicationMembershipCondition
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using NUnit
.Framework
;
33 using System
.Reflection
;
34 using System
.Security
;
35 using System
.Security
.Policy
;
37 namespace MonoTests
.System
.Security
.Policy
{
40 public class ApplicationMembershipConditionTest
{
43 public void Constructor ()
45 ApplicationMembershipCondition app
= new ApplicationMembershipCondition ();
46 Assert
.IsNotNull (app
);
52 ApplicationMembershipCondition app
= new ApplicationMembershipCondition ();
54 Assert
.IsFalse (app
.Check (e
), "Check (null)");
56 Assert
.IsFalse (app
.Check (e
), "Check (empty)");
57 e
.AddHost (new Zone (SecurityZone
.MyComputer
));
58 Assert
.IsFalse (app
.Check (e
), "Check (zone)");
60 // TODO - more (non failing ;) tests
66 ApplicationMembershipCondition app
= new ApplicationMembershipCondition ();
67 ApplicationMembershipCondition copy
= (ApplicationMembershipCondition
)app
.Copy ();
68 Assert
.AreEqual (app
, copy
, "Equals");
69 Assert
.IsFalse (Object
.ReferenceEquals (app
, copy
), "ReferenceEquals");
75 ApplicationMembershipCondition app
= new ApplicationMembershipCondition ();
76 Assert
.IsFalse (app
.Equals (null), "Equals(null)");
77 ApplicationMembershipCondition g2
= new ApplicationMembershipCondition ();
78 Assert
.IsTrue (app
.Equals (g2
), "Equals(g2)");
79 Assert
.IsTrue (g2
.Equals (app
), "Equals(app)");
80 Assert
.IsFalse (app
.Equals (new object ()), "Equals (object)");
84 [ExpectedException (typeof (ArgumentNullException
))]
85 public void FromXml_Null ()
87 ApplicationMembershipCondition app
= new ApplicationMembershipCondition ();
92 public void FromXml ()
94 ApplicationMembershipCondition app
= new ApplicationMembershipCondition ();
95 SecurityElement se
= app
.ToXml ();
100 [ExpectedException (typeof (ArgumentException
))]
101 public void FromXml_InvalidTag ()
103 ApplicationMembershipCondition app
= new ApplicationMembershipCondition ();
104 SecurityElement se
= app
.ToXml ();
105 se
.Tag
= "IMonoship";
110 [ExpectedException (typeof (ArgumentException
))]
111 public void FromXml_WrongTagCase ()
113 ApplicationMembershipCondition app
= new ApplicationMembershipCondition ();
114 SecurityElement se
= app
.ToXml ();
115 se
.Tag
= "IMEMBERSHIPCONDITION"; // insteapp of IMembershipCondition
120 public void FromXml_InvalidClass ()
122 ApplicationMembershipCondition app
= new ApplicationMembershipCondition ();
123 SecurityElement se
= app
.ToXml ();
124 se
.Attributes
["class"] = "Hello world";
129 public void FromXml_NoClass ()
131 ApplicationMembershipCondition app
= new ApplicationMembershipCondition ();
132 SecurityElement se
= app
.ToXml ();
134 SecurityElement w
= new SecurityElement (se
.Tag
);
135 w
.AddAttribute ("version", se
.Attribute ("version"));
137 // doesn't even care of the class attribute presence
141 public void FromXml_InvalidVersion ()
143 ApplicationMembershipCondition app
= new ApplicationMembershipCondition ();
144 SecurityElement se
= app
.ToXml ();
146 SecurityElement w
= new SecurityElement (se
.Tag
);
147 w
.AddAttribute ("class", se
.Attribute ("class"));
148 w
.AddAttribute ("version", "2");
150 // doesn't seems to care about the version number!
154 public void FromXml_NoVersion ()
156 ApplicationMembershipCondition app
= new ApplicationMembershipCondition ();
157 SecurityElement se
= app
.ToXml ();
159 SecurityElement w
= new SecurityElement (se
.Tag
);
160 w
.AddAttribute ("class", se
.Attribute ("class"));
165 [ExpectedException (typeof (ArgumentNullException
))]
166 public void FromXml_SecurityElementNull ()
168 ApplicationMembershipCondition app
= new ApplicationMembershipCondition ();
169 app
.FromXml (null, PolicyLevel
.CreateAppDomainLevel ());
173 public void FromXml_NonBooleanLookAtDir ()
175 ApplicationMembershipCondition app
= new ApplicationMembershipCondition ();
176 SecurityElement se
= app
.ToXml ();
178 SecurityElement w
= new SecurityElement (se
.Tag
);
179 w
.AddAttribute ("class", se
.Attribute ("class"));
180 w
.AddAttribute ("version", se
.Attribute ("version"));
181 w
.AddAttribute ("LookAtDir", "Maybe"); // not (generally) a boolean ;)
183 ApplicationMembershipCondition app2
= new ApplicationMembershipCondition ();
187 Assert
.IsNull (se
.Attribute ("LookAtDir"), "LookAtDir");
188 // LookAtDir isn't part of the Equals computation
189 Assert
.IsTrue (app2
.Equals (app
), "Equals-1");
190 Assert
.IsTrue (app
.Equals (app2
), "Equals-2");
192 ApplicationMembershipCondition app3
= (ApplicationMembershipCondition
)app2
.Copy ();
194 // LookAtDir isn't copied either
195 Assert
.AreEqual ("true", se
.Attribute ("LookAtDir"), "Copy-LookAtDir");
199 public void FromXml_PolicyLevelNull ()
201 ApplicationMembershipCondition app
= new ApplicationMembershipCondition ();
202 SecurityElement se
= app
.ToXml ();
203 app
.FromXml (se
, null);
207 public void GetHashCode_ ()
209 ApplicationMembershipCondition app
= new ApplicationMembershipCondition ();
210 Assert
.AreEqual (-1, app
.GetHashCode ());
211 ApplicationMembershipCondition copy
= (ApplicationMembershipCondition
)app
.Copy ();
212 Assert
.AreEqual (app
.GetHashCode (), copy
.GetHashCode ());
216 public void ToString_ ()
218 ApplicationMembershipCondition app
= new ApplicationMembershipCondition ();
219 Assert
.AreEqual ("Application", app
.ToString ());
225 ApplicationMembershipCondition app
= new ApplicationMembershipCondition ();
226 SecurityElement se
= app
.ToXml ();
227 Assert
.AreEqual ("IMembershipCondition", se
.Tag
, "Tag");
228 Assert
.IsTrue (se
.Attribute ("class").StartsWith ("System.Security.Policy.ApplicationMembershipCondition"), "class");
229 Assert
.AreEqual ("1", se
.Attribute ("version"), "version");
230 Assert
.AreEqual ("true", se
.Attribute ("LookAtDir"), "LookAtDir");
231 Assert
.AreEqual (se
.ToString (), app
.ToXml (null).ToString (), "ToXml(null)");
232 Assert
.AreEqual (se
.ToString (), app
.ToXml (PolicyLevel
.CreateAppDomainLevel ()).ToString (), "ToXml(PolicyLevel)");