2009-06-12 Bill Holmes <billholmes54@gmail.com>
[mono.git] / mcs / class / corlib / Test / System.Security.Policy / NetCodeGroupTest.cs
1 //
2 // MonoTests.System.Security.Policy.NetCodeGroupTest
3 //
4 // Author:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // (C) 2004 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
9 //
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:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
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.
28 //
29
30 using NUnit.Framework;
31 using System;
32 using System.Collections;
33 using System.Security;
34 using System.Security.Policy;
35 using System.Security.Permissions;
36
37 namespace MonoTests.System.Security.Policy {
38
39         [TestFixture]
40         public class NetCodeGroupTest : Assertion {
41
42                 [Test]
43                 [ExpectedException (typeof (ArgumentNullException))]
44                 public void Constructor_Null () 
45                 {
46                         NetCodeGroup cg = new NetCodeGroup ((IMembershipCondition)null);
47                 }
48
49                 [Test]
50                 public void Constructor () 
51                 {
52                         NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
53                         AssertNotNull ("MembershipCondition", cg.MembershipCondition);
54                         AssertNull ("PolicyStatement", cg.PolicyStatement);
55                         // documented as always null
56                         AssertNull ("AttributeString", cg.AttributeString);
57 #if NET_2_0
58                         // seems it's easier to change code than to change code ;)
59                         AssertEquals ("PermissionSetName", "Same site Web", cg.PermissionSetName);
60 #else
61                         // documented as always "Same site Web" but it's "Same site Web." (missing .)
62                         AssertEquals ("PermissionSetName", "Same site Web.", cg.PermissionSetName);
63 #endif
64                 }
65
66                 [Test]
67                 public void MergeLogic () 
68                 {
69                         NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
70                         AssertEquals ("MergeLogic", "Union", cg.MergeLogic);
71                 }
72
73                 [Test]
74                 public void Copy () 
75                 {
76                         NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
77                         NetCodeGroup cg2 = (NetCodeGroup) cg.Copy ();
78                         AssertEquals ("AttributeString", cg.AttributeString, cg2.AttributeString);
79                         AssertEquals ("Children", cg.Children.Count, cg2.Children.Count);
80                         AssertEquals ("Description", cg.Description, cg2.Description);
81                         AssertEquals ("MergeLogic", cg.MergeLogic, cg2.MergeLogic);
82                         AssertEquals ("Name", cg.Name, cg2.Name);
83                         AssertEquals ("PermissionSetName", cg.PermissionSetName, cg2.PermissionSetName);
84                         AssertEquals ("ToXml", cg.ToXml ().ToString (), cg2.ToXml ().ToString ());
85                 }
86
87                 [Test]
88                 public void CopyWithChildren () 
89                 {
90                         NetCodeGroup cgChild = new NetCodeGroup (new AllMembershipCondition ());
91                         NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
92                         cg.AddChild (cgChild);
93                         NetCodeGroup cg2 = (NetCodeGroup) cg.Copy ();
94                         AssertEquals ("Children", cg.Children.Count, cg2.Children.Count);
95                         AssertEquals ("ToXml", cg.ToXml ().ToString (), cg2.ToXml ().ToString ());
96                 }
97
98                 [Test]
99                 [ExpectedException (typeof (ArgumentNullException))]
100                 public void Resolve_Null () 
101                 {
102                         NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
103                         cg.Resolve (null);
104                 }
105
106                 [Test]
107                 [ExpectedException (typeof (ArgumentNullException))]
108                 public void ResolveMatchingCodeGroups_Null () 
109                 {
110                         NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
111                         cg.ResolveMatchingCodeGroups (null);
112                 }
113
114                 [Test]
115                 public void ToFromXmlRoundtrip () 
116                 {
117                         NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
118                         cg.Name = "SomeName";
119                         cg.Description = "Some Description";
120                         Assert ("Equals (itself)", cg.Equals (cg));
121                         SecurityElement se = cg.ToXml ();
122
123                         NetCodeGroup cg2 = new NetCodeGroup (new AllMembershipCondition());
124                         cg2.Name = "SomeOtherName";
125                         cg2.Description = "Some Other Description";
126                         Assert ("Equals (another)", !cg.Equals (cg2));
127
128                         cg2.FromXml (se);
129                         Assert ("Equals (FromXml)", cg.Equals (cg2));
130                 }
131         }
132 }