[bcl] Remove more NET_2_0 checks from class libs
[mono.git] / mcs / class / System.Data / Test / ProviderTests / System.Data.SqlClient / SqlConnectionStringBuilderTest.cs
1 // SqlConnectionStringBuilderTest.cs - NUnit Test Cases for Testing the 
2 // SqlConnectionStringBuilder class
3 //
4 // Author: 
5 //      Sureshkumar T (tsureshkumar@novell.com)
6 //
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.
28 //
29
30
31 #region Using directives
32
33 using System;
34 using System.Text;
35 using System.Collections;
36
37 using System.Data;
38 using System.Data.SqlClient;
39
40 using NUnit.Framework;
41
42 #endregion
43
44 namespace MonoTests.System.Data.Common
45 {
46
47         [TestFixture]
48         [Category ("sqlserver")]
49         public class SqlConnectionStringBuilderTest
50         {
51                 private SqlConnectionStringBuilder builder = null;
52                 
53                 [Test]
54                 public void DefaultValuestTest ()
55                 {
56                         builder = new SqlConnectionStringBuilder ();
57                         Assert.AreEqual ("", builder.ConnectionString, "#DV1 default values is wrong");
58                 }
59
60                 [Test]
61                 public void DefaultValuestTest2 ()
62                 {
63                         builder = new SqlConnectionStringBuilder ("SERVER=localhost;");
64                         Assert.AreEqual ("Data Source=localhost", builder.ConnectionString, "#DVT1 default values is wrong");
65                 }
66
67                 [Test]
68                 public void PropertiesTest ()
69                 {
70                         builder = new SqlConnectionStringBuilder ("SERVER=localhost;");
71                         builder.AsynchronousProcessing = true;
72                         builder.ApplicationName = "mono test";
73                         Assert.AreEqual (true, 
74                                          builder.ConnectionString.Contains ("Asynchronous Processing=True"),
75                                          "#PT1 boolean value must be true");
76                 }
77                 
78                 [Test]
79                 public void ItemTest ()
80                 {
81                         builder = new SqlConnectionStringBuilder ("SERVER=localhost;");
82                         builder ["Network Library"] = "DBMSSOCN";
83                         Assert.AreEqual (true, 
84                                          builder.ConnectionString.Contains ("Network Library=dbmssocn"),
85                                          "#PT1 network library should exist");
86                 }
87
88                 public void NullTest ()
89                 {
90                         builder = new SqlConnectionStringBuilder ("SERVER=localhost;Network=DBMSSOCN");
91                         builder ["Network Library"] = null;
92                         Assert.AreEqual ("Data Source=localhost", builder.ConnectionString,
93                                          "#NT1 should remove the key if set with null");
94                 }
95
96                 public void ContainsKeyTest ()
97                 {
98                         builder = new SqlConnectionStringBuilder ("SERVER=localhost;Network=DBMSSOCN");
99                         Assert.AreEqual (true, builder.ContainsKey ("NETWORK"),
100                                          "#CKT1 should say true");
101                         Assert.AreEqual (false, builder.ContainsKey ("ABCD"),
102                                          "#CKT2 should say false");
103                 }
104                 
105                 [Test, ExpectedException (typeof (ArgumentException))]
106                 public void InvalidKeyTest ()
107                 {
108                         builder = new SqlConnectionStringBuilder ("SERVER=localhost;Network=DBMSSOCN");
109                         int value = (int) builder ["ABCD"];
110                         value++; // to avoid warning
111                 }
112
113                 [Test]
114                 public void RemoveTest ()
115                 {
116                         builder = new SqlConnectionStringBuilder ("SERVER = localhost ;Network=DBMSSOCN");
117                         // non existing key
118                         Assert.AreEqual (false, builder.Remove ("ABCD"),
119                                          "#RT1 cannot remove non existant key");
120                         Assert.AreEqual (true, builder.Remove ("NETWORK library"),
121                                          "#RT2 should remove the key");
122                         Assert.AreEqual ("Data Source=localhost", builder.ConnectionString,
123                                          "#RT3 should have removed the key");
124                 }
125
126                 [Test]
127                 public void TrustServerCertificateTest ()
128                 {
129                         builder = new SqlConnectionStringBuilder ();
130                         Assert.AreEqual (false, builder.TrustServerCertificate, "#1 The default value should be false");
131                         builder.TrustServerCertificate = true;
132                         Assert.AreEqual (true, builder.TrustServerCertificate, "#2 The value returned should be true after setting the value of TrustServerCertificate to true");
133                         Assert.AreEqual ("Trust Server Certificate=True", builder.ConnectionString, "#3 The value of the key TrustServerCertificate should be added to the connection string");
134                 }
135                 
136                 [Test]
137                 public void TypeSystemVersionTest ()
138                 {
139                         builder = new SqlConnectionStringBuilder ();
140                         Assert.AreEqual ("Latest", builder.TypeSystemVersion, "#1 The default value for the property should be Latest");
141                         builder.TypeSystemVersion = "SQL Server 2005";
142                         Assert.AreEqual ("SQL Server 2005", builder.TypeSystemVersion, "#2 The value for the property should be SQL Server 2005 after setting this value");
143                         Assert.AreEqual ("Type System Version=SQL Server 2005", builder.ConnectionString, "#3 The value of the key Type System Version should be added to the connection string");
144                 }
145
146                 [Test]
147                 public void UserInstanceTest ()
148                 {
149                         builder = new SqlConnectionStringBuilder ();
150                         Assert.AreEqual (false, builder.UserInstance, "#1 The default value for the property should be false");
151                         builder.UserInstance = true;
152                         Assert.AreEqual (true, builder.UserInstance, "#2 The value for the property should be true after setting its value to true");
153                         Assert.AreEqual ("User Instance=True", builder.ConnectionString, "#3 The value of the key User Instance should be added to the connection string");
154                 }
155
156                 [Test]
157                 public void SettingUserInstanceTest ()
158                 {
159                         builder = new SqlConnectionStringBuilder ();
160                         builder["User Instance"] = true;
161                         Assert.AreEqual ("User Instance=True", builder.ConnectionString, "#1 The value of the key User Instance should be added to the connection string");                     
162                 }
163
164                 [Test]
165                 public void ContextConnectionTest ()
166                 {
167                         builder = new SqlConnectionStringBuilder ();
168                         Assert.AreEqual (false, builder.ContextConnection, "#1 The default value for the property should be false");
169                         builder.ContextConnection = true;
170                         Assert.AreEqual (true, builder.ContextConnection, "#2 The value for the property should be true after setting its value to true");                      
171                         Assert.AreEqual ("Context Connection=True", builder.ConnectionString, "#3 The value of the key Context Connection should be added to the connection string");
172                 }
173
174                 [Test]
175                 public void SettingContextConnectionTest ()
176                 {
177                         builder = new SqlConnectionStringBuilder ();
178                         builder["Context Connection"] = true;
179                         Assert.AreEqual ("Context Connection=True", builder.ConnectionString, "#1 The value of the key Context Connection should be added to the connection string");                   
180                 }
181         }
182 }
183