**** Merged from MCS ****
[mono-project.git] / mcs / class / System.Data.OracleClient / Test / System.Data.OracleClient / OraclePermissionAttributeTest.cs
blobec8a4aa26a732889b1bfc40f9b0cb19dc252bad2
1 //
2 // OraclePermissionAttributeTest.cs -
3 // NUnit Test Cases for OraclePermissionAttribute
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.Data;
33 using System.Data.OracleClient;
34 using System.Security;
35 using System.Security.Permissions;
37 namespace MonoTests.System.Data.OracleClient {
39 [TestFixture]
40 public class OraclePermissionAttributeTest {
42 [Test]
43 public void Default ()
45 OraclePermissionAttribute a = new OraclePermissionAttribute (SecurityAction.Assert);
46 Assert.AreEqual (a.ToString (), a.TypeId.ToString (), "TypeId");
47 Assert.IsFalse (a.Unrestricted, "Unrestricted");
48 Assert.IsFalse (a.AllowBlankPassword, "AllowBlankPassword");
49 #if NET_2_0
50 Assert.AreEqual (String.Empty, a.ConnectionString, "ConnectionString");
51 Assert.AreEqual (KeyRestrictionBehavior.AllowOnly, a.KeyRestrictionBehavior, "KeyRestrictionBehavior");
52 Assert.AreEqual (String.Empty, a.KeyRestrictions, "KeyRestrictions");
53 Assert.IsFalse (a.ShouldSerializeConnectionString (), "ShouldSerializeConnectionString");
54 Assert.IsFalse (a.ShouldSerializeKeyRestrictions (), "ShouldSerializeConnectionString");
55 #endif
56 OraclePermission ocp = (OraclePermission)a.CreatePermission ();
57 Assert.IsFalse (ocp.IsUnrestricted (), "IsUnrestricted");
60 [Test]
61 public void Action ()
63 OraclePermissionAttribute a = new OraclePermissionAttribute (SecurityAction.Assert);
64 Assert.AreEqual (SecurityAction.Assert, a.Action, "Action=Assert");
65 a.Action = SecurityAction.Demand;
66 Assert.AreEqual (SecurityAction.Demand, a.Action, "Action=Demand");
67 a.Action = SecurityAction.Deny;
68 Assert.AreEqual (SecurityAction.Deny, a.Action, "Action=Deny");
69 a.Action = SecurityAction.InheritanceDemand;
70 Assert.AreEqual (SecurityAction.InheritanceDemand, a.Action, "Action=InheritanceDemand");
71 a.Action = SecurityAction.LinkDemand;
72 Assert.AreEqual (SecurityAction.LinkDemand, a.Action, "Action=LinkDemand");
73 a.Action = SecurityAction.PermitOnly;
74 Assert.AreEqual (SecurityAction.PermitOnly, a.Action, "Action=PermitOnly");
75 a.Action = SecurityAction.RequestMinimum;
76 Assert.AreEqual (SecurityAction.RequestMinimum, a.Action, "Action=RequestMinimum");
77 a.Action = SecurityAction.RequestOptional;
78 Assert.AreEqual (SecurityAction.RequestOptional, a.Action, "Action=RequestOptional");
79 a.Action = SecurityAction.RequestRefuse;
80 Assert.AreEqual (SecurityAction.RequestRefuse, a.Action, "Action=RequestRefuse");
81 #if NET_2_0
82 a.Action = SecurityAction.DemandChoice;
83 Assert.AreEqual (SecurityAction.DemandChoice, a.Action, "Action=DemandChoice");
84 a.Action = SecurityAction.InheritanceDemandChoice;
85 Assert.AreEqual (SecurityAction.InheritanceDemandChoice, a.Action, "Action=InheritanceDemandChoice");
86 a.Action = SecurityAction.LinkDemandChoice;
87 Assert.AreEqual (SecurityAction.LinkDemandChoice, a.Action, "Action=LinkDemandChoice");
88 #endif
91 [Test]
92 public void Action_Invalid ()
94 OraclePermissionAttribute a = new OraclePermissionAttribute ((SecurityAction)Int32.MinValue);
95 // no validation in attribute
98 [Test]
99 public void Unrestricted ()
101 OraclePermissionAttribute a = new OraclePermissionAttribute (SecurityAction.Assert);
102 a.Unrestricted = true;
103 OraclePermission ocp = (OraclePermission)a.CreatePermission ();
104 Assert.IsTrue (ocp.IsUnrestricted (), "IsUnrestricted");
105 Assert.IsFalse (a.AllowBlankPassword, "AllowBlankPassword");
106 #if NET_2_0
107 Assert.AreEqual (String.Empty, a.ConnectionString, "ConnectionString");
108 Assert.AreEqual (KeyRestrictionBehavior.AllowOnly, a.KeyRestrictionBehavior, "KeyRestrictionBehavior");
109 Assert.AreEqual (String.Empty, a.KeyRestrictions, "KeyRestrictions");
110 #endif
111 a.Unrestricted = false;
112 ocp = (OraclePermission)a.CreatePermission ();
113 Assert.IsFalse (ocp.IsUnrestricted (), "!IsUnrestricted");
116 [Test]
117 public void AllowBlankPassword ()
119 OraclePermissionAttribute a = new OraclePermissionAttribute (SecurityAction.Assert);
120 Assert.IsFalse (a.AllowBlankPassword, "Default");
121 a.AllowBlankPassword = true;
122 Assert.IsTrue (a.AllowBlankPassword, "True");
123 a.AllowBlankPassword = false;
124 Assert.IsFalse (a.AllowBlankPassword, "False");
127 #if NET_2_0
128 [Test]
129 public void ConnectionString ()
131 OraclePermissionAttribute a = new OraclePermissionAttribute (SecurityAction.Assert);
132 a.ConnectionString = String.Empty;
133 Assert.AreEqual (String.Empty, a.ConnectionString, "Empty");
134 a.ConnectionString = "Mono";
135 Assert.AreEqual ("Mono", a.ConnectionString, "Mono");
136 a.ConnectionString = null;
137 Assert.AreEqual (String.Empty, a.ConnectionString, "Empty(null)");
140 [Test]
141 public void KeyRestrictionBehavior_All ()
143 OraclePermissionAttribute a = new OraclePermissionAttribute (SecurityAction.Assert);
144 a.KeyRestrictionBehavior = KeyRestrictionBehavior.AllowOnly;
145 Assert.AreEqual (KeyRestrictionBehavior.AllowOnly, a.KeyRestrictionBehavior, "AllowOnly");
146 a.KeyRestrictionBehavior = KeyRestrictionBehavior.PreventUsage;
147 Assert.AreEqual (KeyRestrictionBehavior.PreventUsage, a.KeyRestrictionBehavior, "PreventUsage");
150 [Test]
151 [ExpectedException (typeof (ArgumentOutOfRangeException))]
152 public void KeyRestrictionBehavior_Invalid ()
154 OraclePermissionAttribute a = new OraclePermissionAttribute (SecurityAction.Assert);
155 a.KeyRestrictionBehavior = (KeyRestrictionBehavior)Int32.MinValue;
158 [Test]
159 public void KeyRestriction ()
161 OraclePermissionAttribute a = new OraclePermissionAttribute (SecurityAction.Assert);
162 a.KeyRestrictions = String.Empty;
163 Assert.AreEqual (String.Empty, a.KeyRestrictions, "Empty");
164 a.KeyRestrictions = "Mono";
165 Assert.AreEqual ("Mono", a.KeyRestrictions, "Mono");
166 a.KeyRestrictions = null;
167 Assert.AreEqual (String.Empty, a.KeyRestrictions, "Empty(null)");
169 #endif
170 [Test]
171 public void Attributes ()
173 Type t = typeof (OraclePermissionAttribute);
174 Assert.IsTrue (t.IsSerializable, "IsSerializable");
176 object [] attrs = t.GetCustomAttributes (typeof (AttributeUsageAttribute), false);
177 Assert.AreEqual (1, attrs.Length, "AttributeUsage");
178 AttributeUsageAttribute aua = (AttributeUsageAttribute)attrs [0];
179 Assert.IsTrue (aua.AllowMultiple, "AllowMultiple");
180 Assert.IsFalse (aua.Inherited, "Inherited");
181 AttributeTargets at = AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method;
182 Assert.AreEqual (at, aua.ValidOn, "ValidOn");