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