2 // SqlClientPermissionTest.cs - NUnit Test Cases for SqlClientPermission
\r
5 // Sebastien Pouliot <sebastien@ximian.com>
\r
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
\r
9 // Permission is hereby granted, free of charge, to any person obtaining
\r
10 // a copy of this software and associated documentation files (the
\r
11 // "Software"), to deal in the Software without restriction, including
\r
12 // without limitation the rights to use, copy, modify, merge, publish,
\r
13 // distribute, sublicense, and/or sell copies of the Software, and to
\r
14 // permit persons to whom the Software is furnished to do so, subject to
\r
15 // the following conditions:
\r
17 // The above copyright notice and this permission notice shall be
\r
18 // included in all copies or substantial portions of the Software.
\r
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
29 using NUnit.Framework;
\r
32 using System.Data.Common;
\r
33 using System.Data.SqlClient;
\r
34 using System.Security;
\r
35 using System.Security.Permissions;
\r
37 namespace MonoTests.System.Data.SqlClient {
\r
39 // NOTE: Most tests are are located in the base class, DBDataPermission
\r
42 public class SqlClientPermissionTest {
\r
44 private void Check (string msg, DBDataPermission dbdp, bool blank, bool unrestricted, int count)
\r
46 Assert.AreEqual (blank, dbdp.AllowBlankPassword, msg + ".AllowBlankPassword");
\r
47 Assert.AreEqual (unrestricted, dbdp.IsUnrestricted (), msg + ".IsUnrestricted");
\r
49 Assert.IsNull (dbdp.ToXml ().Children, msg + ".Count != 0");
\r
51 Assert.AreEqual (count, dbdp.ToXml ().Children.Count, msg + ".Count");
\r
56 [ExpectedException (typeof (ArgumentOutOfRangeException))]
\r
58 [ExpectedException (typeof (ArgumentException))]
\r
60 public void PermissionState_Invalid ()
\r
62 PermissionState ps = (PermissionState)Int32.MinValue;
\r
63 SqlClientPermission perm = new SqlClientPermission (ps);
\r
69 SqlClientPermission perm = new SqlClientPermission (PermissionState.None);
\r
70 Check ("None-1", perm, false, false, 0);
\r
71 perm.AllowBlankPassword = true;
\r
72 Check ("None-2", perm, true, false, 0);
\r
74 SqlClientPermission copy = (SqlClientPermission)perm.Copy ();
\r
75 Check ("Copy_None-1", copy, true, false, 0);
\r
76 copy.AllowBlankPassword = false;
\r
77 Check ("Copy_None-2", copy, false, false, 0);
\r
81 public void None_Childs ()
\r
83 SqlClientPermission perm = new SqlClientPermission (PermissionState.None);
\r
84 perm.Add ("data source=localhost;", String.Empty, KeyRestrictionBehavior.AllowOnly);
\r
85 perm.Add ("data source=127.0.0.1;", "password=;", KeyRestrictionBehavior.PreventUsage);
\r
87 Check ("None-Childs-1", perm, false, false, 2);
\r
88 perm.AllowBlankPassword = true;
\r
89 Check ("None-Childs-2", perm, true, false, 2);
\r
91 SqlClientPermission copy = (SqlClientPermission)perm.Copy ();
\r
92 Check ("Copy_None-Childs-1", copy, true, false, 2);
\r
93 copy.AllowBlankPassword = false;
\r
94 Check ("Copy_None-Childs-2", copy, false, false, 2);
\r
98 public void Unrestricted ()
\r
100 SqlClientPermission perm = new SqlClientPermission (PermissionState.Unrestricted);
\r
101 Check ("Unrestricted-1", perm, false, true, 0);
\r
102 perm.AllowBlankPassword = true;
\r
103 Check ("Unrestricted-2", perm, true, true, 0);
\r
105 SqlClientPermission copy = (SqlClientPermission)perm.Copy ();
\r
106 // note: Unrestricted is always created with default values (so AllowBlankPassword is false)
\r
107 Check ("Copy_Unrestricted-1", copy, false, true, 0);
\r
108 copy.AllowBlankPassword = true;
\r
109 Check ("Copy_Unrestricted-2", copy, true, true, 0);
\r
113 public void Unrestricted_Add ()
\r
115 SqlClientPermission perm = new SqlClientPermission (PermissionState.Unrestricted);
\r
116 Check ("Unrestricted-NoChild", perm, false, true, 0);
\r
117 perm.Add ("data source=localhost;", String.Empty, KeyRestrictionBehavior.AllowOnly);
\r
118 // note: Lost unrestricted state when children was added
\r
119 Check ("Unrestricted-WithChild", perm, false, false, 1);
\r