2 // DnsPermissionAttributeTest.cs - NUnit Test Cases for DnsPermissionAttribute
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using NUnit
.Framework
;
32 using System
.Security
;
33 using System
.Security
.Permissions
;
35 namespace MonoTests
.System
.Net
{
38 public class DnsPermissionAttributeTest
{
41 public void Default ()
43 DnsPermissionAttribute a
= new DnsPermissionAttribute (SecurityAction
.Assert
);
44 Assert
.AreEqual (a
.ToString (), a
.TypeId
.ToString (), "TypeId");
45 Assert
.IsFalse (a
.Unrestricted
, "Unrestricted");
47 DnsPermission perm
= (DnsPermission
)a
.CreatePermission ();
48 Assert
.IsFalse (a
.Unrestricted
, "Unrestricted");
54 DnsPermissionAttribute a
= new DnsPermissionAttribute (SecurityAction
.Assert
);
55 Assert
.AreEqual (SecurityAction
.Assert
, a
.Action
, "Action=Assert");
56 a
.Action
= SecurityAction
.Demand
;
57 Assert
.AreEqual (SecurityAction
.Demand
, a
.Action
, "Action=Demand");
58 a
.Action
= SecurityAction
.Deny
;
59 Assert
.AreEqual (SecurityAction
.Deny
, a
.Action
, "Action=Deny");
60 a
.Action
= SecurityAction
.InheritanceDemand
;
61 Assert
.AreEqual (SecurityAction
.InheritanceDemand
, a
.Action
, "Action=InheritanceDemand");
62 a
.Action
= SecurityAction
.LinkDemand
;
63 Assert
.AreEqual (SecurityAction
.LinkDemand
, a
.Action
, "Action=LinkDemand");
64 a
.Action
= SecurityAction
.PermitOnly
;
65 Assert
.AreEqual (SecurityAction
.PermitOnly
, a
.Action
, "Action=PermitOnly");
66 a
.Action
= SecurityAction
.RequestMinimum
;
67 Assert
.AreEqual (SecurityAction
.RequestMinimum
, a
.Action
, "Action=RequestMinimum");
68 a
.Action
= SecurityAction
.RequestOptional
;
69 Assert
.AreEqual (SecurityAction
.RequestOptional
, a
.Action
, "Action=RequestOptional");
70 a
.Action
= SecurityAction
.RequestRefuse
;
71 Assert
.AreEqual (SecurityAction
.RequestRefuse
, a
.Action
, "Action=RequestRefuse");
73 a
.Action
= SecurityAction
.DemandChoice
;
74 Assert
.AreEqual (SecurityAction
.DemandChoice
, a
.Action
, "Action=DemandChoice");
75 a
.Action
= SecurityAction
.InheritanceDemandChoice
;
76 Assert
.AreEqual (SecurityAction
.InheritanceDemandChoice
, a
.Action
, "Action=InheritanceDemandChoice");
77 a
.Action
= SecurityAction
.LinkDemandChoice
;
78 Assert
.AreEqual (SecurityAction
.LinkDemandChoice
, a
.Action
, "Action=LinkDemandChoice");
83 public void Action_Invalid ()
85 DnsPermissionAttribute a
= new DnsPermissionAttribute ((SecurityAction
)Int32
.MinValue
);
86 // no validation in attribute
90 public void Unrestricted ()
92 DnsPermissionAttribute a
= new DnsPermissionAttribute (SecurityAction
.Assert
);
93 a
.Unrestricted
= true;
94 DnsPermission dp
= (DnsPermission
) a
.CreatePermission ();
95 Assert
.IsTrue (dp
.IsUnrestricted (), "IsUnrestricted");
97 a
.Unrestricted
= false;
98 dp
= (DnsPermission
)a
.CreatePermission ();
99 Assert
.IsFalse (dp
.IsUnrestricted (), "!IsUnrestricted");
103 public void Attributes ()
105 Type t
= typeof (DnsPermissionAttribute
);
106 Assert
.IsTrue (t
.IsSerializable
, "IsSerializable");
108 object [] attrs
= t
.GetCustomAttributes (typeof (AttributeUsageAttribute
), false);
109 Assert
.AreEqual (1, attrs
.Length
, "AttributeUsage");
110 AttributeUsageAttribute aua
= (AttributeUsageAttribute
)attrs
[0];
111 Assert
.IsTrue (aua
.AllowMultiple
, "AllowMultiple");
112 Assert
.IsFalse (aua
.Inherited
, "Inherited");
113 AttributeTargets at
= (AttributeTargets
.Assembly
| AttributeTargets
.Class
| AttributeTargets
.Struct
| AttributeTargets
.Constructor
| AttributeTargets
.Method
);
114 Assert
.AreEqual (at
, aua
.ValidOn
, "ValidOn");