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 {
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 Assert.IsNotNull (cg.MembershipCondition, "MembershipCondition");
54 Assert.IsNull (cg.PolicyStatement, "PolicyStatement");
55 // documented as always null
56 Assert.IsNull (cg.AttributeString, "AttributeString");
58 // seems it's easier to change code than to change code ;)
59 Assert.AreEqual ("Same site Web", cg.PermissionSetName, "PermissionSetName");
61 // documented as always "Same site Web" but it's "Same site Web." (missing .)
62 Assert.AreEqual ("Same site Web.", cg.PermissionSetName, "PermissionSetName");
67 public void MergeLogic ()
69 NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
70 Assert.AreEqual ("Union", cg.MergeLogic, "MergeLogic");
76 NetCodeGroup cg = new NetCodeGroup (new AllMembershipCondition ());
77 NetCodeGroup cg2 = (NetCodeGroup) cg.Copy ();
78 Assert.AreEqual (cg.AttributeString, cg2.AttributeString, "AttributeString");
79 Assert.AreEqual (cg.Children.Count, cg2.Children.Count, "Children");
80 Assert.AreEqual (cg.Description, cg2.Description, "Description");
81 Assert.AreEqual (cg.MergeLogic, cg2.MergeLogic, "MergeLogic");
82 Assert.AreEqual (cg.Name, cg2.Name, "Name");
83 Assert.AreEqual (cg.PermissionSetName, cg2.PermissionSetName, "PermissionSetName");
84 Assert.AreEqual (cg.ToXml ().ToString (), cg2.ToXml ().ToString (), "ToXml");
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 Assert.AreEqual (cg.Children.Count, cg2.Children.Count, "Children");
95 Assert.AreEqual (cg.ToXml ().ToString (), cg2.ToXml ().ToString (), "ToXml");
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.IsTrue (cg.Equals (cg), "Equals (itself)");
121 SecurityElement se = cg.ToXml ();
123 NetCodeGroup cg2 = new NetCodeGroup (new AllMembershipCondition());
124 cg2.Name = "SomeOtherName";
125 cg2.Description = "Some Other Description";
126 Assert.IsTrue (!cg.Equals (cg2), "Equals (another)");
129 Assert.IsTrue (cg.Equals (cg2), "Equals (FromXml)");