2010-04-15 Jb Evain <jbevain@novell.com>
[mcs.git] / class / corlib / Test / System.Security.Policy / AllMembershipConditionTest.cs
blob8f22813ef449376152afcdb5c7d65f972ab79cc3
1 //
2 // AllMembershipConditionTest.cs - NUnit Test Cases for AllMembershipCondition
3 //
4 // Author:
5 // Sebastien Pouliot <sebastien@ximian.com>
6 //
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
8 //
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:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
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;
30 using System;
31 using System.Security;
32 using System.Security.Policy;
34 namespace MonoTests.System.Security.Policy {
36 [TestFixture]
37 public class AllMembershipConditionTest {
39 [Test]
40 public void Constructor ()
42 AllMembershipCondition all = new AllMembershipCondition ();
43 Assert.IsNotNull (all);
46 [Test]
47 public void Check ()
49 AllMembershipCondition all = new AllMembershipCondition ();
50 Evidence e = null;
51 Assert.IsTrue (all.Check (e), "Check (null)");
52 e = new Evidence ();
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/");
57 e.AddAssembly (u);
58 Assert.IsTrue (all.Check (e), "Check (all-assembly)");
59 Site s = new Site ("www.go-mono.com");
60 e.AddHost (s);
61 Assert.IsTrue (all.Check (e), "Check (all-host)");
64 [Test]
65 public void Copy ()
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");
73 [Test]
74 public void Equals ()
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)");
84 [Test]
85 [ExpectedException (typeof (ArgumentNullException))]
86 public void FromXml_Null ()
88 AllMembershipCondition all = new AllMembershipCondition ();
89 all.FromXml (null);
92 [Test]
93 public void FromXml ()
95 AllMembershipCondition all = new AllMembershipCondition ();
96 SecurityElement se = all.ToXml ();
97 all.FromXml (se);
100 [Test]
101 [ExpectedException (typeof (ArgumentException))]
102 public void FromXml_InvalidTag ()
104 AllMembershipCondition all = new AllMembershipCondition ();
105 SecurityElement se = all.ToXml ();
106 se.Tag = "IMonoship";
107 all.FromXml (se);
110 [Test]
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
117 all.FromXml (se);
120 [Test]
121 public void FromXml_InvalidClass ()
123 AllMembershipCondition all = new AllMembershipCondition ();
124 SecurityElement se = all.ToXml ();
125 se.Attributes ["class"] = "Hello world";
126 all.FromXml (se);
129 [Test]
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"));
137 all.FromXml (w);
138 // doesn't even care of the class attribute presence
141 [Test]
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");
150 all.FromXml (w);
151 // doesn't seems to care about the version number!
154 [Test]
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"));
162 all.FromXml (w);
165 [Test]
166 [ExpectedException (typeof (ArgumentNullException))]
167 public void FromXml_SecurityElementNull ()
169 AllMembershipCondition all = new AllMembershipCondition ();
170 all.FromXml (null, PolicyLevel.CreateAppDomainLevel ());
173 [Test]
174 public void FromXml_PolicyLevelNull ()
176 AllMembershipCondition all = new AllMembershipCondition ();
177 SecurityElement se = all.ToXml ();
178 all.FromXml (se, null);
181 [Test]
182 public void GetHashCode_ ()
184 AllMembershipCondition all = new AllMembershipCondition ();
185 AllMembershipCondition copy = (AllMembershipCondition)all.Copy ();
186 Assert.AreEqual (all.GetHashCode (), copy.GetHashCode ());
189 [Test]
190 public void ToString_ ()
192 AllMembershipCondition all = new AllMembershipCondition ();
193 Assert.AreEqual ("All code", all.ToString ());
196 [Test]
197 public void ToXml ()
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)");