2 // GacIdentityPermissionTest.cs - NUnit Test Cases for GacIdentityPermission
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
.Permissions
;
36 namespace MonoTests
.System
.Security
.Permissions
{
39 public class GacIdentityPermissionTest
{
42 public void PermissionStateNone ()
44 GacIdentityPermission gip
= new GacIdentityPermission (PermissionState
.None
);
46 SecurityElement se
= gip
.ToXml ();
47 // only class and version are present
48 Assert
.AreEqual (2, se
.Attributes
.Count
, "Xml-Attributes");
49 Assert
.IsNull (se
.Children
, "Xml-Children");
51 GacIdentityPermission copy
= (GacIdentityPermission
)gip
.Copy ();
52 Assert
.IsFalse (Object
.ReferenceEquals (gip
, copy
), "ReferenceEquals");
56 [ExpectedException (typeof (ArgumentException
))]
57 public void PermissionStateUnrestricted ()
59 GacIdentityPermission gip
= new GacIdentityPermission (PermissionState
.Unrestricted
);
63 [ExpectedException (typeof (ArgumentException
))]
64 public void PermissionStateInvalid ()
66 GacIdentityPermission gip
= new GacIdentityPermission ((PermissionState
)2);
70 public void GacIdentityPermission_Empty ()
72 GacIdentityPermission gip
= new GacIdentityPermission ();
73 Assert
.IsNotNull (gip
);
77 public void Intersect ()
79 GacIdentityPermission gip
= new GacIdentityPermission ();
81 GacIdentityPermission intersect
= (GacIdentityPermission
)gip
.Intersect (null);
82 Assert
.IsNull (intersect
, "gip N null");
84 GacIdentityPermission empty
= new GacIdentityPermission (PermissionState
.None
);
85 intersect
= (GacIdentityPermission
)gip
.Intersect (empty
);
86 Assert
.IsNotNull (intersect
, "gip N null");
88 intersect
= (GacIdentityPermission
)gip
.Intersect (gip
);
89 Assert
.IsNotNull (intersect
, "gip N gip");
93 [ExpectedException (typeof (ArgumentException
))]
94 public void Intersect_DifferentPermissions ()
96 GacIdentityPermission a
= new GacIdentityPermission (PermissionState
.None
);
97 SecurityPermission b
= new SecurityPermission (PermissionState
.None
);
102 public void IsSubsetOf ()
104 GacIdentityPermission gip
= new GacIdentityPermission ();
105 Assert
.IsFalse (gip
.IsSubsetOf (null), "gip.IsSubsetOf (null)");
107 GacIdentityPermission empty
= new GacIdentityPermission (PermissionState
.None
);
108 Assert
.IsFalse (empty
.IsSubsetOf (null), "empty.IsSubsetOf (null)");
112 [ExpectedException (typeof (ArgumentException
))]
113 public void IsSubsetOf_DifferentPermissions ()
115 GacIdentityPermission a
= new GacIdentityPermission (PermissionState
.None
);
116 SecurityPermission b
= new SecurityPermission (PermissionState
.None
);
123 GacIdentityPermission gip
= new GacIdentityPermission ();
125 GacIdentityPermission union
= (GacIdentityPermission
)gip
.Union (null);
126 Assert
.IsNotNull (union
, "gip U null");
128 GacIdentityPermission empty
= new GacIdentityPermission (PermissionState
.None
);
129 union
= (GacIdentityPermission
)gip
.Union (empty
);
130 Assert
.IsNotNull (union
, "gip U empty");
132 union
= (GacIdentityPermission
)gip
.Union (gip
);
133 Assert
.IsNotNull (union
, "gip U gip");
135 // note: can't be tested with PermissionState.Unrestricted
139 [ExpectedException (typeof (ArgumentException
))]
140 public void Union_DifferentPermissions ()
142 GacIdentityPermission a
= new GacIdentityPermission (PermissionState
.None
);
143 SecurityPermission b
= new SecurityPermission (PermissionState
.None
);
148 [ExpectedException (typeof (ArgumentNullException
))]
149 public void FromXml_Null ()
151 GacIdentityPermission gip
= new GacIdentityPermission ();
156 [ExpectedException (typeof (ArgumentException
))]
157 public void FromXml_WrongTag ()
159 GacIdentityPermission gip
= new GacIdentityPermission ();
160 SecurityElement se
= gip
.ToXml ();
166 [ExpectedException (typeof (ArgumentException
))]
167 public void FromXml_WrongTagCase ()
169 GacIdentityPermission gip
= new GacIdentityPermission ();
170 SecurityElement se
= gip
.ToXml ();
171 se
.Tag
= "IPERMISSION"; // instead of IPermission
176 public void FromXml_WrongClass ()
178 GacIdentityPermission gip
= new GacIdentityPermission ();
179 SecurityElement se
= gip
.ToXml ();
181 SecurityElement w
= new SecurityElement (se
.Tag
);
182 w
.AddAttribute ("class", "Wrong" + se
.Attribute ("class"));
183 w
.AddAttribute ("version", se
.Attribute ("version"));
185 // doesn't care of the class name at that stage
186 // anyway the class has already be created so...
190 public void FromXml_NoClass ()
192 GacIdentityPermission gip
= new GacIdentityPermission ();
193 SecurityElement se
= gip
.ToXml ();
195 SecurityElement w
= new SecurityElement (se
.Tag
);
196 w
.AddAttribute ("version", se
.Attribute ("version"));
198 // doesn't even care of the class attribute presence
202 [ExpectedException (typeof (ArgumentException
))]
203 public void FromXml_WrongVersion ()
205 GacIdentityPermission gip
= new GacIdentityPermission ();
206 SecurityElement se
= gip
.ToXml ();
207 se
.Attributes
.Remove ("version");
208 se
.Attributes
.Add ("version", "2");
213 public void FromXml_NoVersion ()
215 GacIdentityPermission gip
= new GacIdentityPermission ();
216 SecurityElement se
= gip
.ToXml ();
218 SecurityElement w
= new SecurityElement (se
.Tag
);
219 w
.AddAttribute ("class", se
.Attribute ("class"));