(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / corlib / Test / System.Security.Permissions / CodeAccessSecurityAttributeTest.cs
blob8f1857d8303bfaf49f4ac2aaf44251d0e774def0
1 //
2 // CodeAccessSecurityAttributeTest.cs -
3 // NUnit Test Cases for CodeAccessSecurityAttribute
4 //
5 // Author:
6 // Sebastien Pouliot <sebastien@ximian.com>
7 //
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.
30 using NUnit.Framework;
31 using System;
32 using System.Security;
33 using System.Security.Permissions;
35 namespace MonoTests.System.Security.Permissions {
37 // note: CodeAccessSecurityAttribute is abstract so we define our own to test
38 // no [Serialize] or [AttributeUsage] here to test their inheritance
39 public class NonAbstractCodeAccessSecurityAttribute : CodeAccessSecurityAttribute {
41 public NonAbstractCodeAccessSecurityAttribute (SecurityAction action)
42 : base (action)
46 public override IPermission CreatePermission ()
48 return null;
52 [TestFixture]
53 public class CodeAccessSecurityAttributeTest {
55 [Test]
56 public void Action ()
58 NonAbstractCodeAccessSecurityAttribute a = new NonAbstractCodeAccessSecurityAttribute (SecurityAction.Assert);
59 Assert.AreEqual (SecurityAction.Assert, a.Action, "Action=Assert");
60 a.Action = SecurityAction.Demand;
61 Assert.AreEqual (SecurityAction.Demand, a.Action, "Action=Demand");
62 a.Action = SecurityAction.Deny;
63 Assert.AreEqual (SecurityAction.Deny, a.Action, "Action=Deny");
64 a.Action = SecurityAction.InheritanceDemand;
65 Assert.AreEqual (SecurityAction.InheritanceDemand, a.Action, "Action=InheritanceDemand");
66 a.Action = SecurityAction.LinkDemand;
67 Assert.AreEqual (SecurityAction.LinkDemand, a.Action, "Action=LinkDemand");
68 a.Action = SecurityAction.PermitOnly;
69 Assert.AreEqual (SecurityAction.PermitOnly, a.Action, "Action=PermitOnly");
70 a.Action = SecurityAction.RequestMinimum;
71 Assert.AreEqual (SecurityAction.RequestMinimum, a.Action, "Action=RequestMinimum");
72 a.Action = SecurityAction.RequestOptional;
73 Assert.AreEqual (SecurityAction.RequestOptional, a.Action, "Action=RequestOptional");
74 a.Action = SecurityAction.RequestRefuse;
75 Assert.AreEqual (SecurityAction.RequestRefuse, a.Action, "Action=RequestRefuse");
76 #if NET_2_0
77 a.Action = SecurityAction.DemandChoice;
78 Assert.AreEqual (SecurityAction.DemandChoice, a.Action, "Action=DemandChoice");
79 a.Action = SecurityAction.InheritanceDemandChoice;
80 Assert.AreEqual (SecurityAction.InheritanceDemandChoice, a.Action, "Action=InheritanceDemandChoice");
81 a.Action = SecurityAction.LinkDemandChoice;
82 Assert.AreEqual (SecurityAction.LinkDemandChoice, a.Action, "Action=LinkDemandChoice");
83 #endif
86 [Test]
87 public void Action_Invalid ()
89 NonAbstractCodeAccessSecurityAttribute a = new NonAbstractCodeAccessSecurityAttribute ((SecurityAction)Int32.MinValue);
90 // no validation in attribute
93 [Test]
94 public void Unrestricted ()
96 NonAbstractCodeAccessSecurityAttribute a = new NonAbstractCodeAccessSecurityAttribute (SecurityAction.Assert);
97 Assert.IsFalse (a.Unrestricted, "Unrestricted (default)");
98 a.Unrestricted = true;
99 Assert.IsTrue (a.Unrestricted, "Unrestricted (true)");
100 a.Unrestricted = false;
101 Assert.IsFalse (a.Unrestricted, "Unrestricted (false)");
104 [Test]
105 public void Attributes ()
107 Type t = typeof (NonAbstractCodeAccessSecurityAttribute);
108 Assert.IsFalse (t.IsSerializable, "IsSerializable");
110 object[] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false);
111 Assert.AreEqual (0, attrs.Length, "AttributeUsage-false");
113 attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), true);
114 Assert.AreEqual (1, attrs.Length, "AttributeUsage-true");
115 AttributeUsageAttribute aua = (AttributeUsageAttribute)attrs [0];
116 Assert.IsTrue (aua.AllowMultiple, "AllowMultiple");
117 Assert.IsFalse (aua.Inherited, "Inherited");
118 AttributeTargets at = (AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method);
119 Assert.AreEqual (at, aua.ValidOn, "ValidOn");