(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / corlib / Test / System.Security.Policy / FirstMatchCodeGroupTest.cs
bloba0e848a458b9f225740d2177ee9dfed7405d197c
1 //
2 // MonoTests.System.Security.Policy.FirstMatchCodeGroupTest
3 //
4 // Author:
5 // Sebastien Pouliot (spouliot@motus.com)
6 //
7 // (C) 2004 Motus Technologies Inc. (http://www.motus.com)
8 //
10 using NUnit.Framework;
11 using System;
12 using System.Collections;
13 using System.Security;
14 using System.Security.Policy;
15 using System.Security.Permissions;
17 namespace MonoTests.System.Security.Policy {
19 [TestFixture]
20 public class FirstMatchCodeGroupTest : Assertion {
22 [Test]
23 [ExpectedException (typeof (ArgumentNullException))]
24 public void Constructor_MembershipConditionNullPolicyStatement ()
26 FirstMatchCodeGroup cg = new FirstMatchCodeGroup (null, new PolicyStatement (new PermissionSet (PermissionState.None)));
29 [Test]
30 public void Constructor_MembershipConditionPolicyStatementNull ()
32 // legal
33 FirstMatchCodeGroup cg = new FirstMatchCodeGroup (new AllMembershipCondition (), null);
34 AssertNull ("PolicyStatement", cg.PolicyStatement);
37 [Test]
38 public void Constructor ()
40 FirstMatchCodeGroup cg = new FirstMatchCodeGroup (new AllMembershipCondition (), new PolicyStatement (new PermissionSet (PermissionState.None)));
41 AssertNotNull ("PolicyStatement", cg.PolicyStatement);
42 AssertNotNull ("MembershipCondition", cg.MembershipCondition);
45 [Test]
46 public void MergeLogic ()
48 FirstMatchCodeGroup cg = new FirstMatchCodeGroup (new AllMembershipCondition (), new PolicyStatement (new PermissionSet (PermissionState.None)));
49 AssertEquals ("MergeLogic", "First Match", cg.MergeLogic);
52 [Test]
53 public void Copy ()
55 FirstMatchCodeGroup cg = new FirstMatchCodeGroup (new AllMembershipCondition (), new PolicyStatement (new PermissionSet (PermissionState.None)));
56 FirstMatchCodeGroup cg2 = (FirstMatchCodeGroup) cg.Copy ();
57 AssertEquals ("AttributeString", cg.AttributeString, cg2.AttributeString);
58 AssertEquals ("Children", cg.Children.Count, cg2.Children.Count);
59 AssertEquals ("Description", cg.Description, cg2.Description);
60 AssertEquals ("MergeLogic", cg.MergeLogic, cg2.MergeLogic);
61 AssertEquals ("Name", cg.Name, cg2.Name);
62 AssertEquals ("PermissionSetName", cg.PermissionSetName, cg2.PermissionSetName);
63 AssertEquals ("ToXml", cg.ToXml ().ToString (), cg2.ToXml ().ToString ());
66 [Test]
67 public void CopyWithChildren ()
69 FirstMatchCodeGroup cgChild = new FirstMatchCodeGroup (new AllMembershipCondition (), new PolicyStatement (new PermissionSet (PermissionState.Unrestricted)));
70 FirstMatchCodeGroup cg = new FirstMatchCodeGroup (new AllMembershipCondition (), new PolicyStatement (new PermissionSet (PermissionState.None)));
71 cg.AddChild (cgChild);
72 FirstMatchCodeGroup cg2 = (FirstMatchCodeGroup) cg.Copy ();
73 AssertEquals ("Children", cg.Children.Count, cg2.Children.Count);
74 AssertEquals ("ToXml", cg.ToXml ().ToString (), cg2.ToXml ().ToString ());
77 [Test]
78 [ExpectedException (typeof (ArgumentNullException))]
79 public void Resolve_Null ()
81 FirstMatchCodeGroup cg = new FirstMatchCodeGroup (new AllMembershipCondition (), new PolicyStatement (new PermissionSet (PermissionState.None)));
82 cg.Resolve (null);
85 [Test]
86 [ExpectedException (typeof (ArgumentNullException))]
87 public void ResolveMatchingCodeGroups_Null ()
89 FirstMatchCodeGroup cg = new FirstMatchCodeGroup (new AllMembershipCondition (), new PolicyStatement (new PermissionSet (PermissionState.None)));
90 cg.ResolveMatchingCodeGroups (null);
93 [Test]
94 public void ToFromXmlRoundtrip ()
96 const string ps_Name = "TestName";
97 PolicyStatement ps = new PolicyStatement (new NamedPermissionSet (ps_Name));
98 FirstMatchCodeGroup cg = new FirstMatchCodeGroup (new AllMembershipCondition (), ps);
99 cg.Name = "SomeName";
100 cg.Description = "Some Description";
101 Assert ("Equals (itself)", cg.Equals (cg));
102 SecurityElement se = cg.ToXml ();
104 FirstMatchCodeGroup cg2 = new FirstMatchCodeGroup (new AllMembershipCondition(), ps);
105 cg2.Name = "SomeOtherName";
106 cg2.Description = "Some Other Description";
107 Assert ("Equals (another)", !cg.Equals (cg2));
109 cg2.FromXml (se);
110 Assert ("Equals (FromXml)", cg.Equals (cg2));