1 // SqlConnectionStringBuilderTest.cs - NUnit Test Cases for Testing the
2 // SqlConnectionStringBuilder class
5 // Sureshkumar T (tsureshkumar@novell.com)
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
32 #region Using directives
36 using System.Collections;
39 using System.Data.SqlClient;
41 using NUnit.Framework;
45 namespace MonoTests.System.Data.Common
49 public class SqlConnectionStringBuilderTest
51 private SqlConnectionStringBuilder builder = null;
54 public void DefaultValuestTest ()
56 builder = new SqlConnectionStringBuilder ();
57 Assert.AreEqual ("", builder.ConnectionString, "#DV1 default values is wrong");
61 public void DefaultValuestTest2 ()
63 builder = new SqlConnectionStringBuilder ("SERVER=localhost;");
64 Assert.AreEqual ("Data Source=localhost", builder.ConnectionString, "#DVT1 default values is wrong");
68 public void PropertiesTest ()
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");
79 public void ItemTest ()
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");
88 public void NullTest ()
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");
96 public void ContainsKeyTest ()
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");
105 [Test, ExpectedException (typeof (ArgumentException))]
106 public void InvalidKeyTest ()
108 builder = new SqlConnectionStringBuilder ("SERVER=localhost;Network=DBMSSOCN");
109 int value = (int) builder ["ABCD"];
110 value++; // to avoid warning
114 public void RemoveTest ()
116 builder = new SqlConnectionStringBuilder ("SERVER = localhost ;Network=DBMSSOCN");
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");