2 // AllMembershipConditionTest.cs - NUnit Test Cases for AllMembershipCondition
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.
29 using NUnit
.Framework
;
31 using System
.Security
;
32 using System
.Security
.Policy
;
34 namespace MonoTests
.System
.Security
.Policy
{
37 public class AllMembershipConditionTest
{
40 public void Constructor ()
42 AllMembershipCondition all
= new AllMembershipCondition ();
43 Assert
.IsNotNull (all
);
49 AllMembershipCondition all
= new AllMembershipCondition ();
51 Assert
.IsTrue (all
.Check (e
), "Check (null)");
53 Assert
.IsTrue (all
.Check (e
), "Check (empty)");
54 e
.AddHost (new Zone (SecurityZone
.MyComputer
));
55 Assert
.IsTrue (all
.Check (e
), "Check (zone)");
56 Url u
= new Url ("http://www.go-mono.com/");
58 Assert
.IsTrue (all
.Check (e
), "Check (all-assembly)");
59 Site s
= new Site ("www.go-mono.com");
61 Assert
.IsTrue (all
.Check (e
), "Check (all-host)");
67 AllMembershipCondition all
= new AllMembershipCondition ();
68 AllMembershipCondition copy
= (AllMembershipCondition
)all
.Copy ();
69 Assert
.AreEqual (all
, copy
, "Equals");
70 Assert
.IsFalse (Object
.ReferenceEquals (all
, copy
), "ReferenceEquals");
76 AllMembershipCondition all
= new AllMembershipCondition ();
77 Assert
.IsFalse (all
.Equals (null), "Equals(null)");
78 AllMembershipCondition g2
= new AllMembershipCondition ();
79 Assert
.IsTrue (all
.Equals (g2
), "Equals(g2)");
80 Assert
.IsTrue (g2
.Equals (all
), "Equals(all)");
81 Assert
.IsFalse (all
.Equals (new object ()), "Equals (object)");
85 [ExpectedException (typeof (ArgumentNullException
))]
86 public void FromXml_Null ()
88 AllMembershipCondition all
= new AllMembershipCondition ();
93 public void FromXml ()
95 AllMembershipCondition all
= new AllMembershipCondition ();
96 SecurityElement se
= all
.ToXml ();
101 [ExpectedException (typeof (ArgumentException
))]
102 public void FromXml_InvalidTag ()
104 AllMembershipCondition all
= new AllMembershipCondition ();
105 SecurityElement se
= all
.ToXml ();
106 se
.Tag
= "IMonoship";
111 [ExpectedException (typeof (ArgumentException
))]
112 public void FromXml_WrongTagCase ()
114 AllMembershipCondition all
= new AllMembershipCondition ();
115 SecurityElement se
= all
.ToXml ();
116 se
.Tag
= "IMEMBERSHIPCONDITION"; // instead of IMembershipCondition
121 public void FromXml_InvalidClass ()
123 AllMembershipCondition all
= new AllMembershipCondition ();
124 SecurityElement se
= all
.ToXml ();
125 se
.Attributes
["class"] = "Hello world";
130 public void FromXml_NoClass ()
132 AllMembershipCondition all
= new AllMembershipCondition ();
133 SecurityElement se
= all
.ToXml ();
135 SecurityElement w
= new SecurityElement (se
.Tag
);
136 w
.AddAttribute ("version", se
.Attribute ("version"));
138 // doesn't even care of the class attribute presence
142 public void FromXml_InvalidVersion ()
144 AllMembershipCondition all
= new AllMembershipCondition ();
145 SecurityElement se
= all
.ToXml ();
147 SecurityElement w
= new SecurityElement (se
.Tag
);
148 w
.AddAttribute ("class", se
.Attribute ("class"));
149 w
.AddAttribute ("version", "2");
151 // doesn't seems to care about the version number!
155 public void FromXml_NoVersion ()
157 AllMembershipCondition all
= new AllMembershipCondition ();
158 SecurityElement se
= all
.ToXml ();
160 SecurityElement w
= new SecurityElement (se
.Tag
);
161 w
.AddAttribute ("class", se
.Attribute ("class"));
166 [ExpectedException (typeof (ArgumentNullException
))]
167 public void FromXml_SecurityElementNull ()
169 AllMembershipCondition all
= new AllMembershipCondition ();
170 all
.FromXml (null, PolicyLevel
.CreateAppDomainLevel ());
174 public void FromXml_PolicyLevelNull ()
176 AllMembershipCondition all
= new AllMembershipCondition ();
177 SecurityElement se
= all
.ToXml ();
178 all
.FromXml (se
, null);
182 public void GetHashCode_ ()
184 AllMembershipCondition all
= new AllMembershipCondition ();
185 AllMembershipCondition copy
= (AllMembershipCondition
)all
.Copy ();
186 Assert
.AreEqual (all
.GetHashCode (), copy
.GetHashCode ());
190 public void ToString_ ()
192 AllMembershipCondition all
= new AllMembershipCondition ();
193 Assert
.AreEqual ("All code", all
.ToString ());
199 AllMembershipCondition all
= new AllMembershipCondition ();
200 SecurityElement se
= all
.ToXml ();
201 Assert
.AreEqual ("IMembershipCondition", se
.Tag
, "Tag");
202 Assert
.IsTrue (se
.Attribute ("class").StartsWith ("System.Security.Policy.AllMembershipCondition"), "class");
203 Assert
.AreEqual ("1", se
.Attribute ("version"), "version");
204 Assert
.AreEqual (se
.ToString (), all
.ToXml (null).ToString (), "ToXml(null)");
205 Assert
.AreEqual (se
.ToString (), all
.ToXml (PolicyLevel
.CreateAppDomainLevel ()).ToString (), "ToXml(PolicyLevel)");