2 // MonoTests.System.Security.Policy.NetCodeGroupTest
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2004 Motus Technologies Inc. (http://www.motus.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.
30 using NUnit.Framework;
32 using System.Collections;
33 using System.Security;
34 using System.Security.Policy;
35 using System.Security.Permissions;
37 namespace MonoTests.System.Security.Policy {
40 public class NetCodeGroupTest : Assertion {
43 [ExpectedException (typeof (ArgumentNullException))]
44 public void Constructor_Null ()
46 NetCodeGroup cg = new NetCodeGroup ((IMembershipCondition)null);
50 public void Constructor ()
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);
58 // seems it's easier to change code than to change code ;)
59 AssertEquals ("PermissionSetName", "Same site Web", cg.PermissionSetName);
61 // documented as always "Same site Web" but it's "Same site Web." (missing .)
62 AssertEquals ("PermissionSetName", "Same site Web.", cg.PermissionSetName);
67 public void MergeLogic ()
69 NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
70 AssertEquals ("MergeLogic", "Union", cg.MergeLogic);
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 ());
88 public void CopyWithChildren ()
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 ());
99 [ExpectedException (typeof (ArgumentNullException))]
100 public void Resolve_Null ()
102 NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
107 [ExpectedException (typeof (ArgumentNullException))]
108 public void ResolveMatchingCodeGroups_Null ()
110 NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
111 cg.ResolveMatchingCodeGroups (null);
115 public void ToFromXmlRoundtrip ()
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 ();
123 NetCodeGroup cg2 = new NetCodeGroup (new AllMembershipCondition());
124 cg2.Name = "SomeOtherName";
125 cg2.Description = "Some Other Description";
126 Assert ("Equals (another)", !cg.Equals (cg2));
129 Assert ("Equals (FromXml)", cg.Equals (cg2));