2005-09-22 Sureshkumar T <tsureshkumar@novell.com>
[mono.git] / mcs / class / System.Data / Test / System.Data.SqlClient / SqlConnectionTest.cs
1 //\r
2 // SqlConnectionTest.cs - NUnit Test Cases for testing the\r
3 //                        SqlConnection class\r
4 // Author:\r
5 //      Gert Driesen (drieseng@users.sourceforge.net)\r
6 //\r
7 // Copyright (c) 2004 Novell Inc., and the individuals listed\r
8 // on the ChangeLog entries.\r
9 //\r
10 // Permission is hereby granted, free of charge, to any person obtaining\r
11 // a copy of this software and associated documentation files (the\r
12 // "Software"), to deal in the Software without restriction, including\r
13 // without limitation the rights to use, copy, modify, merge, publish,\r
14 // distribute, sublicense, and/or sell copies of the Software, and to\r
15 // permit persons to whom the Software is furnished to do so, subject to\r
16 // the following conditions:\r
17 //\r
18 // The above copyright notice and this permission notice shall be\r
19 // included in all copies or substantial portions of the Software.\r
20 //\r
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
28 //\r
29 \r
30 using System;\r
31 using System.Data;\r
32 using System.Data.SqlClient;\r
33 \r
34 using NUnit.Framework;\r
35 \r
36 namespace MonoTests.System.Data.SqlClient\r
37 {\r
38         [TestFixture]\r
39         public class SqlConnectionTest\r
40         {\r
41                 [Test]\r
42                 public void DefaultConnectionValues()\r
43                 {\r
44                         SqlConnection cn = new SqlConnection ();\r
45 \r
46                         Assert.AreEqual (15, cn.ConnectionTimeout, \r
47                                 "Default connection timeout should be 15 seconds");\r
48                         Assert.AreEqual ("", cn.Database, \r
49                                 "Default database name should be empty string");\r
50                         Assert.AreEqual ("", cn.DataSource,\r
51                                 "Default data source should be empty string");\r
52                         Assert.AreEqual (8192, cn.PacketSize,\r
53                                 "Default packet size should be 8192 bytes");\r
54                         Assert.AreEqual (ConnectionState.Closed, cn.State,\r
55                                 "Default connection state should be closed");\r
56                 }\r
57 \r
58                 [Test]\r
59                 public void ConnectionTimeoutSynonyms()\r
60                 {\r
61                         SqlConnection cn = null;\r
62 \r
63                         cn = new SqlConnection ();\r
64                         cn.ConnectionString = "Connection Timeout=25";\r
65                         Assert.AreEqual (25, cn.ConnectionTimeout);\r
66 \r
67                         cn = new SqlConnection ();\r
68                         cn.ConnectionString = "Connect Timeout=25";\r
69                         Assert.AreEqual (25, cn.ConnectionTimeout);\r
70 \r
71                         cn = new SqlConnection ();\r
72                         cn.ConnectionString = "Timeout=25";\r
73                         Assert.AreEqual (25, cn.ConnectionTimeout);\r
74                 }\r
75 \r
76                 [Test]\r
77                 public void NetworkLibrarySynonyms()\r
78                 {\r
79                         SqlConnection cn = new SqlConnection ();\r
80                         cn.ConnectionString = "Net=DBMSSOCN";\r
81                         cn.ConnectionString = "Network=DBMSSOCN";\r
82                         cn.ConnectionString = "Network library=DBMSSOCN";\r
83                 }\r
84 \r
85                 [Test]\r
86                 public void DatabaseSynonyms()\r
87                 {\r
88                         SqlConnection cn = null;\r
89 \r
90                         cn = new SqlConnection ();\r
91                         cn.ConnectionString = "Initial Catalog=db";\r
92                         Assert.AreEqual ("db", cn.Database);\r
93 \r
94                         cn = new SqlConnection ();\r
95                         cn.ConnectionString = "Database=db";\r
96                         Assert.AreEqual ("db", cn.Database);\r
97                 }\r
98 \r
99                 [Test]\r
100                 public void DataSourceSynonyms()\r
101                 {\r
102                         SqlConnection cn = null;\r
103 \r
104                         cn = new SqlConnection ();\r
105                         cn.ConnectionString = "Data Source=server";\r
106                         Assert.AreEqual ("server", cn.DataSource);\r
107 \r
108                         cn = new SqlConnection ();\r
109                         cn.ConnectionString = "addr=server";\r
110                         Assert.AreEqual ("server", cn.DataSource);\r
111 \r
112                         cn = new SqlConnection ();\r
113                         cn.ConnectionString = "address=server";\r
114                         Assert.AreEqual ("server", cn.DataSource);\r
115 \r
116                         cn = new SqlConnection ();\r
117                         cn.ConnectionString = "network address=server";\r
118                         Assert.AreEqual ("server", cn.DataSource);\r
119 \r
120                         cn = new SqlConnection ();\r
121                         cn.ConnectionString = "server=server";\r
122                         Assert.AreEqual ("server", cn.DataSource);\r
123                 }\r
124 \r
125                 [Test]\r
126                 public void OtherConnectionStringKeywords()\r
127                 {\r
128                         SqlConnection cn = new SqlConnection ();\r
129                         cn.ConnectionString = "Application Name=test";\r
130                         cn.ConnectionString = "App=test";\r
131                         cn.ConnectionString = "Connection LifeTime=1000";\r
132                         cn.ConnectionString = "Connection Reset=true";\r
133                         cn.ConnectionString = "Current Language=test";\r
134                         cn.ConnectionString = "Language=test";\r
135                         cn.ConnectionString = "Encrypt=false";\r
136                         cn.ConnectionString = "Enlist=true";\r
137                         cn.ConnectionString = "Integrated Security=true";\r
138                         cn.ConnectionString = "Trusted_connection=true";\r
139                         cn.ConnectionString = "Max Pool Size=10";\r
140                         cn.ConnectionString = "Min Pool Size=10";\r
141                         cn.ConnectionString = "Password=scrambled";\r
142                         cn.ConnectionString = "Pwd=scrambled";\r
143                         cn.ConnectionString = "Pooling=true";\r
144                         cn.ConnectionString = "User Id=test";\r
145                         cn.ConnectionString = "User=test";\r
146                         cn.ConnectionString = "Uid=test";\r
147                         /*\r
148                          * NOT IMPLEMENTED YET\r
149                          */\r
150                         /*\r
151                         cn.ConnectionString = "Persist Security Info=true";\r
152                         cn.ConnectionString = "PersistSecurityInfo=true";\r
153                         cn.ConnectionString = "Encrypt=true";\r
154                         cn.ConnectionString = "Enlist=false";\r
155                         cn.ConnectionString = "attachdbfilename=dunno";\r
156                         cn.ConnectionString = "extended properties=dunno";\r
157                         cn.ConnectionString = "initial file name=dunno";\r
158                         */\r
159                 }\r
160         }\r
161 }\r