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");
57 // seems it's easier to change code than to change code ;)
58 Assert
.AreEqual ("Same site Web", cg
.PermissionSetName
, "PermissionSetName");
62 public void MergeLogic ()
64 NetCodeGroup cg
= new NetCodeGroup (new AllMembershipCondition ());
65 Assert
.AreEqual ("Union", cg
.MergeLogic
, "MergeLogic");
71 NetCodeGroup cg
= new NetCodeGroup (new AllMembershipCondition ());
72 NetCodeGroup cg2
= (NetCodeGroup
) cg
.Copy ();
73 Assert
.AreEqual (cg
.AttributeString
, cg2
.AttributeString
, "AttributeString");
74 Assert
.AreEqual (cg
.Children
.Count
, cg2
.Children
.Count
, "Children");
75 Assert
.AreEqual (cg
.Description
, cg2
.Description
, "Description");
76 Assert
.AreEqual (cg
.MergeLogic
, cg2
.MergeLogic
, "MergeLogic");
77 Assert
.AreEqual (cg
.Name
, cg2
.Name
, "Name");
78 Assert
.AreEqual (cg
.PermissionSetName
, cg2
.PermissionSetName
, "PermissionSetName");
79 Assert
.AreEqual (cg
.ToXml ().ToString (), cg2
.ToXml ().ToString (), "ToXml");
83 public void CopyWithChildren ()
85 NetCodeGroup cgChild
= new NetCodeGroup (new AllMembershipCondition ());
86 NetCodeGroup cg
= new NetCodeGroup (new AllMembershipCondition ());
87 cg
.AddChild (cgChild
);
88 NetCodeGroup cg2
= (NetCodeGroup
) cg
.Copy ();
89 Assert
.AreEqual (cg
.Children
.Count
, cg2
.Children
.Count
, "Children");
90 Assert
.AreEqual (cg
.ToXml ().ToString (), cg2
.ToXml ().ToString (), "ToXml");
94 [ExpectedException (typeof (ArgumentNullException
))]
95 public void Resolve_Null ()
97 NetCodeGroup cg
= new NetCodeGroup (new AllMembershipCondition ());
102 [ExpectedException (typeof (ArgumentNullException
))]
103 public void ResolveMatchingCodeGroups_Null ()
105 NetCodeGroup cg
= new NetCodeGroup (new AllMembershipCondition ());
106 cg
.ResolveMatchingCodeGroups (null);
110 public void ToFromXmlRoundtrip ()
112 NetCodeGroup cg
= new NetCodeGroup (new AllMembershipCondition ());
113 cg
.Name
= "SomeName";
114 cg
.Description
= "Some Description";
115 Assert
.IsTrue (cg
.Equals (cg
), "Equals (itself)");
116 SecurityElement se
= cg
.ToXml ();
118 NetCodeGroup cg2
= new NetCodeGroup (new AllMembershipCondition());
119 cg2
.Name
= "SomeOtherName";
120 cg2
.Description
= "Some Other Description";
121 Assert
.IsTrue (!cg
.Equals (cg2
), "Equals (another)");
124 Assert
.IsTrue (cg
.Equals (cg2
), "Equals (FromXml)");