SqlConnectionTest.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404
  1. //
  2. // SqlConnectionTest.cs - NUnit Test Cases for testing the
  3. // SqlConnection class
  4. // Author:
  5. // Senganal T ([email protected])
  6. //
  7. // Copyright (c) 2004 Novell Inc., and the individuals listed
  8. // on the ChangeLog entries.
  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. using System;
  30. using System.Collections;
  31. using System.Data;
  32. using System.Data.SqlClient;
  33. using System.Net;
  34. using System.Threading;
  35. using NUnit.Framework;
  36. namespace MonoTests.System.Data
  37. {
  38. [TestFixture]
  39. [Category ("sqlserver")]
  40. public class SqlConnectionTest
  41. {
  42. SqlConnection conn;
  43. String connectionString;
  44. ArrayList events;
  45. [SetUp]
  46. public void SetUp ()
  47. {
  48. events = new ArrayList ();
  49. connectionString = ConnectionManager.Singleton.ConnectionString;
  50. }
  51. [TearDown]
  52. public void TearDown ()
  53. {
  54. if (conn != null)
  55. conn.Dispose ();
  56. #if NET_2_0
  57. SqlConnection.ClearAllPools ();
  58. #endif
  59. }
  60. [Test]
  61. public void OverloadedConstructorTest ()
  62. {
  63. //check synonyms.
  64. //do i need to check for all the synonyms..
  65. conn = new SqlConnection ("Timeout=10;Connect Timeout=20;Connection Timeout=30");
  66. Assert.AreEqual (30, conn.ConnectionTimeout, "#A1");
  67. conn = new SqlConnection ("Connect Timeout=100;Connection Timeout=200;Timeout=300");
  68. Assert.AreEqual (300, conn.ConnectionTimeout, "#A2");
  69. conn = new SqlConnection ("Connection Timeout=1000;Timeout=2000;Connect Timeout=3000");
  70. Assert.AreEqual (3000, conn.ConnectionTimeout, "#A3");
  71. //'==' doesent work correctly in both msdotnet and mono
  72. /*
  73. conn = new SqlConnection ("server=local==host;database=tmp;");
  74. Assert.AreEqual ("local==host", conn.DataSource,
  75. "# Datasource name is set incorrectly");
  76. */
  77. string connStr = "Server='loca\"lhost';Database='''Db'; packet Size=\"512\";"
  78. + "connect Timeout=20;Workstation Id=\"'\"\"desktop\";";
  79. conn = new SqlConnection (connStr);
  80. Assert.AreEqual (connStr , conn.ConnectionString , "#B1");
  81. Assert.AreEqual ("loca\"lhost" , conn.DataSource , "#B2");
  82. Assert.AreEqual ("'Db" , conn.Database , "#B3");
  83. Assert.AreEqual (512 , conn.PacketSize , "#B4");
  84. Assert.AreEqual (20 , conn.ConnectionTimeout , "#B5");
  85. Assert.AreEqual ("'\"desktop" , conn.WorkstationId , "#B6");
  86. }
  87. [Test]
  88. public void Open ()
  89. {
  90. conn = new SqlConnection (connectionString);
  91. conn.StateChange += new StateChangeEventHandler (Connection_StateChange);
  92. conn.Open ();
  93. Assert.AreEqual (ConnectionState.Open, conn.State, "#1");
  94. Assert.AreEqual (1, events.Count, "#2");
  95. StateChangeEventArgs args = events [0] as StateChangeEventArgs;
  96. Assert.IsNotNull (args, "#3");
  97. Assert.AreEqual (ConnectionState.Closed, args.OriginalState, "#4");
  98. Assert.AreEqual (ConnectionState.Open, args.CurrentState, "#5");
  99. conn.Close ();
  100. }
  101. [Test]
  102. public void Open_Connection_Open ()
  103. {
  104. conn = new SqlConnection (connectionString);
  105. conn.Open ();
  106. try {
  107. conn.Open ();
  108. Assert.Fail ("#1");
  109. } catch (InvalidOperationException ex) {
  110. // The connection was not closed. The connection's
  111. // current state is open
  112. Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
  113. Assert.IsNull (ex.InnerException, "#3");
  114. Assert.IsNotNull (ex.Message, "#4");
  115. } finally {
  116. conn.Close ();
  117. }
  118. }
  119. [Test]
  120. public void Open_ConnectionString_Incorrect ()
  121. {
  122. Assert.Ignore ("NotWorking");
  123. // login invalid
  124. conn = new SqlConnection (connectionString + "user id=invalidLogin");
  125. try {
  126. conn.Open ();
  127. Assert.Fail ("#A1");
  128. } catch (SqlException ex) {
  129. // Login failed for user 'invalidLogin'
  130. Assert.AreEqual (typeof (SqlException), ex.GetType (), "#A2");
  131. Assert.AreEqual ((byte) 14, ex.Class, "#A3");
  132. Assert.IsNull (ex.InnerException, "#A4");
  133. Assert.IsNotNull (ex.Message, "#A5");
  134. Assert.IsTrue (ex.Message.IndexOf ("'invalidLogin'") != -1, "#A6");
  135. Assert.AreEqual (18456, ex.Number, "#A7");
  136. Assert.AreEqual ((byte) 1, ex.State, "#A8");
  137. } finally {
  138. conn.Close ();
  139. }
  140. // database invalid
  141. conn = new SqlConnection (connectionString + "database=invalidDB");
  142. try {
  143. conn.Open ();
  144. Assert.Fail ("#B1");
  145. } catch (SqlException ex) {
  146. // Cannot open database "invalidDB" requested
  147. // by the login. The login failed
  148. Assert.AreEqual (typeof (SqlException), ex.GetType (), "#B2");
  149. Assert.AreEqual ((byte) 11, ex.Class, "#B3");
  150. Assert.IsNull (ex.InnerException, "#B4");
  151. Assert.IsNotNull (ex.Message, "#B5");
  152. Assert.IsTrue (ex.Message.IndexOf ("\"invalidDB\"") != -1, "#B6");
  153. Assert.AreEqual (4060, ex.Number, "#B7");
  154. Assert.AreEqual ((byte) 1, ex.State, "#B8");
  155. } finally {
  156. conn.Close ();
  157. }
  158. // password invalid
  159. conn = new SqlConnection (connectionString + ";password=invalidPassword");
  160. try {
  161. conn.Open ();
  162. Assert.Fail ("#C1");
  163. } catch (SqlException ex) {
  164. // Login failed for user '...'
  165. Assert.AreEqual (typeof (SqlException), ex.GetType (), "#C2");
  166. Assert.AreEqual ((byte) 14, ex.Class, "#C3");
  167. Assert.IsNull (ex.InnerException, "#C4");
  168. Assert.IsNotNull (ex.Message, "#C5");
  169. Assert.AreEqual (18456, ex.Number, "#C6");
  170. Assert.AreEqual ((byte) 1, ex.State, "#C7");
  171. } finally {
  172. conn.Close ();
  173. }
  174. // server invalid
  175. conn = new SqlConnection (connectionString + ";server=invalidServerName");
  176. try {
  177. conn.Open ();
  178. Assert.Fail ("#D1");
  179. } catch (SqlException ex) {
  180. // An error has occurred while establishing a
  181. // connection to the server...
  182. Assert.AreEqual (typeof (SqlException), ex.GetType (), "#D2");
  183. Assert.AreEqual ((byte) 20, ex.Class, "#D3");
  184. Assert.IsNull (ex.InnerException, "#D4");
  185. Assert.IsNotNull (ex.Message, "#D5");
  186. #if NET_2_0
  187. Assert.AreEqual (53, ex.Number, "#D6");
  188. #else
  189. Assert.AreEqual (17, ex.Number, "#D6");
  190. #endif
  191. Assert.AreEqual ((byte) 0, ex.State, "#D7");
  192. } finally {
  193. conn.Close ();
  194. }
  195. }
  196. [Test] // bug #383061
  197. public void Open_MaxPoolSize_Reached ()
  198. {
  199. connectionString += "Pooling=true;Connection Lifetime=6;"
  200. + "Connect Timeout=3;Max Pool Size=2";
  201. SqlConnection conn1 = new SqlConnection (connectionString);
  202. conn1.Open ();
  203. SqlConnection conn2 = new SqlConnection (connectionString);
  204. conn2.Open ();
  205. DateTime start = DateTime.Now;
  206. try {
  207. using (SqlConnection sqlConnection = new SqlConnection (connectionString)) {
  208. sqlConnection.Open ();
  209. }
  210. Assert.Fail ("#A1");
  211. } catch (InvalidOperationException ex) {
  212. // System.InvalidOperationException: Timeout expired.
  213. // The timeout period elapsed prior to obtaining a
  214. // connection from the pool. This may have occurred
  215. // because all pooled connections were in use and max
  216. // pool size was reached.
  217. Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
  218. Assert.IsNull (ex.InnerException, "#A3");
  219. Assert.IsNotNull (ex.Message, "#A4");
  220. }
  221. TimeSpan elapsed = DateTime.Now - start;
  222. Assert.IsTrue (elapsed.TotalSeconds >= 3, "#B1:" + elapsed.TotalSeconds);
  223. Assert.IsTrue (elapsed.TotalSeconds < 4, "#B2:" + elapsed.TotalSeconds);
  224. conn2.Close ();
  225. // as the second connection is closed, we should now be
  226. // able to open a new connection (which essentially
  227. // uses the pooled connection from conn2)
  228. SqlConnection conn3 = new SqlConnection (connectionString);
  229. conn3.Open ();
  230. conn3.Close ();
  231. conn1.Close ();
  232. }
  233. [Test] // bug #412574
  234. public void Close ()
  235. {
  236. conn = new SqlConnection (connectionString);
  237. conn.Open ();
  238. conn.StateChange += new StateChangeEventHandler (Connection_StateChange);
  239. conn.Close ();
  240. Assert.AreEqual (ConnectionState.Closed, conn.State, "#1");
  241. Assert.AreEqual (1, events.Count, "#2");
  242. StateChangeEventArgs args = events [0] as StateChangeEventArgs;
  243. Assert.IsNotNull (args, "#3");
  244. Assert.AreEqual (ConnectionState.Open, args.OriginalState, "#4");
  245. Assert.AreEqual (ConnectionState.Closed, args.CurrentState, "5");
  246. conn.Close ();
  247. Assert.AreEqual (1, events.Count, "#6");
  248. }
  249. [Test]
  250. public void ChangeDatabase ()
  251. {
  252. conn = new SqlConnection (connectionString);
  253. conn.Open ();
  254. conn.ChangeDatabase ("master");
  255. Assert.AreEqual ("master", conn.Database);
  256. }
  257. [Test]
  258. public void ChangeDatabase_DatabaseName_DoesNotExist ()
  259. {
  260. conn = new SqlConnection (connectionString);
  261. conn.Open ();
  262. String database = conn.Database;
  263. try {
  264. conn.ChangeDatabase ("doesnotexist");
  265. Assert.Fail ("#1");
  266. } catch (SqlException ex) {
  267. // Could not locate entry in sysdatabases for
  268. // database 'doesnotexist'. No entry found with
  269. // that name. Make sure that the name is entered
  270. // correctly.
  271. Assert.AreEqual (typeof (SqlException), ex.GetType (), "#2");
  272. Assert.AreEqual ((byte) 16, ex.Class, "#3");
  273. Assert.IsNull (ex.InnerException, "#4");
  274. Assert.IsNotNull (ex.Message, "#5");
  275. Assert.IsTrue (ex.Message.IndexOf ("'doesnotexist'") != -1, "#6");
  276. Assert.AreEqual (911, ex.Number, "#7");
  277. Assert.AreEqual ((byte) 1, ex.State, "#8");
  278. Assert.AreEqual (database, conn.Database, "#9");
  279. } finally {
  280. conn.Close ();
  281. }
  282. }
  283. [Test]
  284. public void ChangeDatabase_DatabaseName_Empty ()
  285. {
  286. conn = new SqlConnection (connectionString);
  287. conn.Open ();
  288. try {
  289. conn.ChangeDatabase (string.Empty);
  290. Assert.Fail ("#1");
  291. } catch (ArgumentException ex) {
  292. // Database cannot be null, the empty string,
  293. // or string of only whitespace
  294. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  295. Assert.IsNull (ex.InnerException, "#3");
  296. Assert.IsNotNull (ex.Message, "#4");
  297. Assert.IsNull (ex.ParamName);
  298. }
  299. }
  300. [Test]
  301. public void ChangeDatabase_DatabaseName_Null ()
  302. {
  303. conn = new SqlConnection (connectionString);
  304. conn.Open ();
  305. try {
  306. conn.ChangeDatabase ((string) null);
  307. Assert.Fail ("#1");
  308. } catch (ArgumentException ex) {
  309. // Database cannot be null, the empty string,
  310. // or string of only whitespace
  311. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  312. Assert.IsNull (ex.InnerException, "#3");
  313. Assert.IsNotNull (ex.Message, "#4");
  314. Assert.IsNull (ex.ParamName);
  315. }
  316. }
  317. [Test] // bug #412581
  318. public void ChangeDatabase_DatabaseName_Whitespace ()
  319. {
  320. #if NET_2_0
  321. Assert.Ignore ("bug #412581");
  322. #endif
  323. conn = new SqlConnection (connectionString);
  324. conn.Open ();
  325. try {
  326. conn.ChangeDatabase (" ");
  327. Assert.Fail ("#1");
  328. #if NET_2_0
  329. } catch (SqlException ex) {
  330. // Could not locate entry in sysdatabases for
  331. // database ' '. No entry found with that name.
  332. // Make sure that the name is entered correctly
  333. Assert.AreEqual (typeof (SqlException), ex.GetType (), "#2");
  334. Assert.AreEqual ((byte) 16, ex.Class, "#3");
  335. Assert.IsNull (ex.InnerException, "#4");
  336. Assert.IsNotNull (ex.Message, "#5");
  337. Assert.IsTrue (ex.Message.IndexOf ("' '") != -1, "#6");
  338. Assert.AreEqual (911, ex.Number, "#7");
  339. Assert.AreEqual ((byte) 1, ex.State, "#8");
  340. }
  341. #else
  342. } catch (ArgumentException ex) {
  343. // Database cannot be null, the empty string,
  344. // or string of only whitespace
  345. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  346. Assert.IsNull (ex.InnerException, "#3");
  347. Assert.IsNotNull (ex.Message, "#4");
  348. Assert.IsNull (ex.ParamName);
  349. }
  350. #endif
  351. }
  352. #if NET_2_0
  353. [Test]
  354. public void ClearAllPools ()
  355. {
  356. SqlConnection conn1 = new SqlConnection (connectionString + ";Pooling=false");
  357. conn1.Open ();
  358. int initial_connection_count = GetConnectionCount (conn1);
  359. SqlConnection conn2 = new SqlConnection (connectionString + ";App=A");
  360. conn2.Open ();
  361. conn2.Close ();
  362. SqlConnection conn3 = new SqlConnection (connectionString + ";App=B");
  363. conn3.Open ();
  364. conn3.Close ();
  365. Assert.AreEqual (initial_connection_count + 2, GetConnectionCount (conn1), "#1");
  366. SqlConnection.ClearAllPools ();
  367. Assert.AreEqual (initial_connection_count, GetConnectionCount (conn1), "#2");
  368. conn1.Close ();
  369. }
  370. [Test] // bug #443131
  371. public void ClearPool ()
  372. {
  373. SqlConnection conn1 = new SqlConnection (connectionString);
  374. conn1.Open ();
  375. int initial_connection_count = GetConnectionCount (conn1);
  376. SqlConnection conn2 = new SqlConnection (connectionString);
  377. conn2.Open ();
  378. SqlConnection conn3 = new SqlConnection (connectionString);
  379. conn3.Open ();
  380. conn3.Close ();
  381. Assert.AreEqual (initial_connection_count + 2, GetConnectionCount (conn1), "#1");
  382. SqlConnection.ClearPool (conn1);
  383. // check if pooled connections that were not in use are
  384. // actually closed
  385. Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn1), "#2");
  386. conn2.Close ();
  387. // check if connections that were in use when the pool
  388. // was cleared will not be returned to the pool when
  389. // closed (and are closed instead)
  390. Assert.AreEqual (initial_connection_count, GetConnectionCount (conn1), "#3");
  391. SqlConnection conn4 = new SqlConnection (connectionString);
  392. conn4.Open ();
  393. SqlConnection conn5 = new SqlConnection (connectionString);
  394. conn5.Open ();
  395. SqlConnection conn6 = new SqlConnection (connectionString);
  396. conn6.Open ();
  397. Assert.AreEqual (initial_connection_count + 3, GetConnectionCount (conn1), "#4");
  398. conn5.Close ();
  399. conn6.Close ();
  400. // check if new connections are stored in the pool again
  401. Assert.AreEqual (initial_connection_count + 3, GetConnectionCount (conn1), "#5");
  402. conn1.Close ();
  403. Assert.AreEqual (initial_connection_count + 2, GetConnectionCount (conn4), "#6");
  404. SqlConnection.ClearPool (conn3);
  405. // the connection passed to ClearPool does not have to
  406. // be open
  407. Assert.AreEqual (initial_connection_count, GetConnectionCount (conn4), "#7");
  408. SqlConnection conn7 = new SqlConnection (connectionString);
  409. conn7.Open ();
  410. conn7.Close ();
  411. Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn4), "#8");
  412. conn3.ConnectionString += ";App=B";
  413. SqlConnection.ClearPool (conn3);
  414. // check if a pool is identified by its connection string
  415. Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn4), "#9");
  416. SqlConnection conn8 = new SqlConnection (connectionString);
  417. SqlConnection.ClearPool (conn8);
  418. // connection should not have been opened before to
  419. // clear the corresponding pool
  420. Assert.AreEqual (initial_connection_count, GetConnectionCount (conn4), "#10");
  421. SqlConnection conn9 = new SqlConnection (connectionString);
  422. conn9.Open ();
  423. conn9.Close ();
  424. Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn4), "#11");
  425. conn3.ConnectionString = connectionString;
  426. SqlConnection.ClearPool (conn3);
  427. Assert.AreEqual (initial_connection_count, GetConnectionCount (conn4), "#12");
  428. SqlConnection conn10 = new SqlConnection (connectionString);
  429. conn10.Open ();
  430. SqlConnection conn11 = new SqlConnection (connectionString + ";App=B");
  431. conn11.Open ();
  432. SqlConnection conn12 = new SqlConnection (connectionString + ";App=B");
  433. conn12.Open ();
  434. SqlConnection conn13 = new SqlConnection (connectionString + ";App=B");
  435. conn13.Open ();
  436. conn10.Close ();
  437. conn11.Close ();
  438. conn12.Close ();
  439. conn13.Close ();
  440. Assert.AreEqual (initial_connection_count + 4, GetConnectionCount (conn4), "#13");
  441. // check that other connection pools are not affected
  442. SqlConnection.ClearPool (conn13);
  443. Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn4), "#14");
  444. SqlConnection conn14 = new SqlConnection (connectionString);
  445. conn14.Open ();
  446. conn14.Dispose ();
  447. // a disposed connection cannot be used to clear a pool
  448. SqlConnection.ClearPool (conn14);
  449. Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn4), "#15");
  450. SqlConnection.ClearPool (conn4);
  451. Assert.AreEqual (initial_connection_count, GetConnectionCount (conn4), "#16");
  452. conn4.Close ();
  453. }
  454. #endif
  455. [Test]
  456. public void InterfaceTransactionTest ()
  457. {
  458. conn = new SqlConnection (connectionString);
  459. conn.Open ();
  460. IDbCommand idbCommand = new SqlCommand ("use [mono-test]", conn);
  461. idbCommand.Connection = null;
  462. Assert.AreEqual (null, idbCommand.Connection, "Connection should be null");
  463. idbCommand.Transaction = null;
  464. Assert.AreEqual (null, idbCommand.Transaction, "Transaction should be null");
  465. conn.Close ();
  466. }
  467. [Test]
  468. public void BeginTransaction ()
  469. {
  470. conn = new SqlConnection (connectionString);
  471. conn.Open ();
  472. SqlTransaction trans = conn.BeginTransaction ();
  473. Assert.AreSame (conn, trans.Connection, "#A1");
  474. Assert.AreEqual (IsolationLevel.ReadCommitted, trans.IsolationLevel, "#A2");
  475. trans.Rollback ();
  476. trans = conn.BeginTransaction ();
  477. try {
  478. conn.BeginTransaction ();
  479. Assert.Fail ("#B1");
  480. } catch (InvalidOperationException ex) {
  481. // SqlConnection does not support parallel transactions
  482. Assert.AreEqual (typeof(InvalidOperationException), ex.GetType(), "#B2");
  483. Assert.IsNull (ex.InnerException, "#B3");
  484. Assert.IsNotNull (ex.Message, "#B4");
  485. } finally {
  486. trans.Rollback();
  487. }
  488. try {
  489. trans = conn.BeginTransaction ();
  490. trans.Rollback ();
  491. trans = conn.BeginTransaction ();
  492. trans.Commit ();
  493. trans = conn.BeginTransaction ();
  494. } finally {
  495. trans.Rollback ();
  496. }
  497. }
  498. [Test]
  499. public void ConnectionString ()
  500. {
  501. conn = new SqlConnection (connectionString);
  502. // Test Repeated Keyoword should take the latest value
  503. conn.ConnectionString = conn.ConnectionString + ";server=RepeatedServer;";
  504. Assert.AreEqual ("RepeatedServer", ((SqlConnection)conn).DataSource, "#A1");
  505. conn.ConnectionString += ";database=gen;Initial Catalog=gen1";
  506. Assert.AreEqual ("gen1", conn.Database, "#A2");
  507. // Test if properties are set correctly
  508. string str = "server=localhost1;database=db;user id=user;";
  509. str += "password=pwd;Workstation ID=workstation;Packet Size=512;";
  510. str += "Connect Timeout=10";
  511. conn.ConnectionString = str;
  512. Assert.AreEqual ("localhost1", conn.DataSource, "#B1");
  513. Assert.AreEqual ("db", conn.Database, "#B2");
  514. Assert.AreEqual (ConnectionState.Closed, conn.State, "#B3");
  515. Assert.AreEqual ("workstation", conn.WorkstationId, "#B4");
  516. Assert.AreEqual (512, conn.PacketSize, "#B5");
  517. Assert.AreEqual (10, conn.ConnectionTimeout, "#B6");
  518. // Test if any leftover values exist from previous invocation
  519. conn.ConnectionString = connectionString;
  520. conn.ConnectionString = string.Empty;
  521. Assert.AreEqual (string.Empty, conn.DataSource, "#C1");
  522. Assert.AreEqual ("", conn.Database, "#C2");
  523. #if NET_2_0
  524. Assert.AreEqual (8000, conn.PacketSize, "#C3");
  525. #else
  526. Assert.AreEqual (8192, conn.PacketSize, "#C3");
  527. #endif
  528. Assert.AreEqual (15, conn.ConnectionTimeout, "#C4");
  529. Assert.IsTrue (string.Compare (conn.WorkstationId, Environment.MachineName, true) == 0, "#C5");
  530. }
  531. [Test]
  532. public void ConnectionString_Connection_Open ()
  533. {
  534. conn = new SqlConnection (connectionString);
  535. conn.ConnectionString = connectionString;
  536. conn.Open ();
  537. try {
  538. conn.ConnectionString = "server=localhost;database=tmp;";
  539. Assert.Fail ("#1");
  540. } catch (InvalidOperationException ex) {
  541. // Not allowed to change the 'ConnectionString'
  542. // property. The connection's current state is open
  543. Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
  544. Assert.IsNull (ex.InnerException, "#3");
  545. Assert.IsNotNull (ex.Message, "#4");
  546. } finally {
  547. conn.Close ();
  548. }
  549. }
  550. [Test]
  551. public void ServerVersionTest ()
  552. {
  553. conn = new SqlConnection (connectionString);
  554. // Test InvalidOperation Exception is thrown if Connection is CLOSED
  555. try {
  556. string s = conn.ServerVersion;
  557. Assert.Fail ("#A1:" + s);
  558. } catch (InvalidOperationException ex) {
  559. Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
  560. Assert.IsNull (ex.InnerException, "#A3");
  561. Assert.IsNotNull (ex.Message, "#A4");
  562. }
  563. // Test if Release Version is as per specification.
  564. conn.Open ();
  565. String [] version = conn.ServerVersion.Split ('.');
  566. Assert.AreEqual (2, version[0].Length,
  567. "#B1 The Major release shud be exactly 2 characters");
  568. Assert.AreEqual (2, version[1].Length,
  569. "#B2 The Minor release shud be exactly 2 characters");
  570. Assert.AreEqual (4, version[2].Length,
  571. "#B3 The Release version should be exactly 4 digits");
  572. }
  573. [Test]
  574. public void Database ()
  575. {
  576. conn = new SqlConnection (connectionString);
  577. string database = conn.Database;
  578. // Test if database property is updated when a query changes database
  579. conn.Open ();
  580. SqlCommand cmd = new SqlCommand ("use [master]" , conn);
  581. cmd.ExecuteNonQuery ();
  582. Assert.AreEqual ("master", conn.Database, "#1");
  583. conn.Close ();
  584. Assert.AreEqual (database, conn.Database, "#2");
  585. // Test if the database property is reset on re-opening the connection
  586. conn.ConnectionString = connectionString;
  587. conn.Open ();
  588. Assert.AreEqual (database, conn.Database, "#3");
  589. conn.Close ();
  590. }
  591. [Test] // bug #412571
  592. public void Dispose ()
  593. {
  594. StateChangeEventArgs stateChangeArgs;
  595. EventArgs disposedArgs;
  596. conn = new SqlConnection (connectionString + ";Connection Timeout=30;Packet Size=512;Workstation Id=Desktop");
  597. conn.Disposed += new EventHandler (Connection_Disposed);
  598. conn.Open ();
  599. conn.StateChange += new StateChangeEventHandler (Connection_StateChange);
  600. Assert.AreEqual (0, events.Count, "#A1");
  601. conn.Dispose ();
  602. Assert.AreEqual (string.Empty, conn.ConnectionString, "#A2");
  603. Assert.AreEqual (15, conn.ConnectionTimeout, "#A3");
  604. Assert.AreEqual (string.Empty, conn.Database, "#A4");
  605. Assert.AreEqual (string.Empty, conn.DataSource, "#A5");
  606. #if NET_2_0
  607. Assert.AreEqual (8000, conn.PacketSize, "#A6");
  608. #else
  609. Assert.AreEqual (8192, conn.PacketSize, "#A6");
  610. #endif
  611. Assert.AreEqual (ConnectionState.Closed, conn.State, "#A7");
  612. Assert.IsTrue (string.Compare (conn.WorkstationId, Environment.MachineName, true) == 0, "#A8");
  613. Assert.AreEqual (2, events.Count, "#A9");
  614. stateChangeArgs = events [0] as StateChangeEventArgs;
  615. Assert.IsNotNull (stateChangeArgs, "#B1");
  616. Assert.AreEqual (typeof (StateChangeEventArgs), stateChangeArgs.GetType (), "#B2");
  617. Assert.AreEqual (ConnectionState.Open, stateChangeArgs.OriginalState, "#B3");
  618. Assert.AreEqual (ConnectionState.Closed, stateChangeArgs.CurrentState, "B4");
  619. disposedArgs = events [1] as EventArgs;
  620. Assert.IsNotNull (disposedArgs, "#C1");
  621. Assert.AreEqual (typeof (EventArgs), disposedArgs.GetType (), "#C2");
  622. conn.Dispose ();
  623. Assert.AreEqual (ConnectionState.Closed, conn.State, "#D1");
  624. Assert.AreEqual (3, events.Count, "#D2");
  625. disposedArgs = events [2] as EventArgs;
  626. Assert.IsNotNull (disposedArgs, "#E1");
  627. Assert.AreEqual (typeof (EventArgs), disposedArgs.GetType (), "#E2");
  628. }
  629. void Connection_StateChange (object sender , StateChangeEventArgs e)
  630. {
  631. events.Add (e);
  632. }
  633. void Connection_Disposed (object sender , EventArgs e)
  634. {
  635. events.Add (e);
  636. }
  637. #if NET_2_0
  638. [Test]
  639. public void FireInfoMessageEventOnUserErrorsTest ()
  640. {
  641. conn = new SqlConnection ();
  642. Assert.AreEqual(false, conn.FireInfoMessageEventOnUserErrors, "#1 The default value should be false");
  643. conn.FireInfoMessageEventOnUserErrors = true;
  644. Assert.AreEqual(true, conn.FireInfoMessageEventOnUserErrors, "#1 The value should be true after setting the property to true");
  645. }
  646. [Test]
  647. public void StatisticsEnabledTest ()
  648. {
  649. conn = new SqlConnection ();
  650. Assert.AreEqual(false, conn.StatisticsEnabled, "#1 The default value should be false");
  651. conn.StatisticsEnabled = true;
  652. Assert.AreEqual(true, conn.StatisticsEnabled, "#1 The value should be true after setting the property to true");
  653. }
  654. [Test]
  655. public void ChangePasswordTest ()
  656. {
  657. string tmpPassword = "modifiedbymonosqlclient";
  658. SqlConnection.ChangePassword (connectionString, tmpPassword);
  659. SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder (connectionString);
  660. string oldPassword = connBuilder.Password;
  661. connBuilder.Password = tmpPassword;
  662. SqlConnection.ChangePassword (connBuilder.ConnectionString, oldPassword); // Modify to the original password
  663. }
  664. static int GetConnectionCount (SqlConnection conn)
  665. {
  666. Thread.Sleep (200);
  667. SqlCommand cmd = conn.CreateCommand ();
  668. cmd.CommandText = "select count(*) from master..sysprocesses where db_name(dbid) = @dbname";
  669. cmd.Parameters.Add (new SqlParameter ("@dbname", conn.Database));
  670. int connection_count = (int) cmd.ExecuteScalar ();
  671. cmd.Dispose ();
  672. return connection_count;
  673. }
  674. #endif
  675. }
  676. #if NET_2_0
  677. [TestFixture]
  678. [Category ("sqlserver")]
  679. public class GetSchemaTest
  680. {
  681. SqlConnection conn = null;
  682. String connectionString = ConnectionManager.Singleton.ConnectionString;
  683. [SetUp]
  684. public void Setup()
  685. {
  686. conn = new SqlConnection(connectionString);
  687. conn.Open();
  688. }
  689. [TearDown]
  690. public void TearDown()
  691. {
  692. conn.Close();
  693. }
  694. [Test]
  695. public void GetSchemaTest1()
  696. {
  697. bool flag = false;
  698. DataTable tab1 = conn.GetSchema("databases");
  699. foreach (DataRow row in tab1.Rows)
  700. {
  701. foreach (DataColumn col in tab1.Columns)
  702. {
  703. if (col.ColumnName.ToString() == "database_name" && row[col].ToString() == "monotest")
  704. {
  705. flag = true;
  706. break;
  707. }
  708. }
  709. if (flag)
  710. break;
  711. }
  712. Assert.AreEqual(true, flag, "#GS1 failed");
  713. }
  714. [Test]
  715. [ExpectedException(typeof(ArgumentException))]
  716. public void GetSchemaTest2()
  717. {
  718. conn.GetSchema(null);
  719. }
  720. [Test]
  721. public void GetSchemaTest3 ()
  722. {
  723. Assert.Ignore ("We currently have no foreign keys defined in the test database");
  724. bool flag = false;
  725. DataTable tab1 = conn.GetSchema("ForeignKeys");
  726. foreach (DataRow row in tab1.Rows)
  727. {
  728. foreach (DataColumn col in tab1.Columns)
  729. {
  730. /*
  731. * We need to consider multiple values
  732. */
  733. if (col.ColumnName.ToString() == "TABLE_NAME" && row[col].ToString() == "tmptable1")
  734. {
  735. flag = true;
  736. break;
  737. }
  738. }
  739. if (flag)
  740. break;
  741. }
  742. Assert.AreEqual(true, flag, "#GS3 failed");
  743. }
  744. [Test]
  745. public void GetSchemaTest4()
  746. {
  747. bool flag = false;
  748. DataTable tab1 = conn.GetSchema("Indexes");
  749. foreach (DataRow row in tab1.Rows)
  750. {
  751. foreach (DataColumn col in tab1.Columns)
  752. {
  753. /*
  754. * We need to consider multiple values
  755. */
  756. if (col.ColumnName.ToString() == "table_name" && row[col].ToString() == "binary_family")
  757. {
  758. flag = true;
  759. break;
  760. }
  761. }
  762. if (flag)
  763. break;
  764. }
  765. Assert.AreEqual(true, flag, "#GS4 failed");
  766. }
  767. [Test]
  768. public void GetSchemaTest5()
  769. {
  770. bool flag = false;
  771. DataTable tab1 = conn.GetSchema("IndexColumns");
  772. foreach (DataRow row in tab1.Rows)
  773. {
  774. foreach (DataColumn col in tab1.Columns)
  775. {
  776. /*
  777. * We need to consider multiple values
  778. */
  779. if (col.ColumnName.ToString() == "table_name" && row[col].ToString() == "binary_family")
  780. {
  781. flag = true;
  782. break;
  783. }
  784. }
  785. if (flag)
  786. break;
  787. }
  788. Assert.AreEqual(true, flag, "#GS5 failed");
  789. }
  790. [Test]
  791. public void GetSchemaTest6()
  792. {
  793. bool flag = false;
  794. DataTable tab1 = conn.GetSchema("Procedures");
  795. foreach (DataRow row in tab1.Rows)
  796. {
  797. foreach (DataColumn col in tab1.Columns)
  798. {
  799. /*
  800. * We need to consider multiple values
  801. */
  802. if (col.ColumnName.ToString() == "SPECIFIC_NAME" && row[col].ToString() == "sp_get_age")
  803. {
  804. flag = true;
  805. break;
  806. }
  807. }
  808. if (flag)
  809. break;
  810. }
  811. Assert.AreEqual(true, flag, "#GS6 failed");
  812. }
  813. [Test]
  814. public void GetSchemaTest7()
  815. {
  816. bool flag = false;
  817. DataTable tab1 = conn.GetSchema("ProcedureParameters");
  818. foreach (DataRow row in tab1.Rows)
  819. {
  820. foreach (DataColumn col in tab1.Columns)
  821. {
  822. /*
  823. * We need to consider multiple values
  824. */
  825. if (col.ColumnName.ToString() == "SPECIFIC_NAME" && row[col].ToString() == "sp_get_age")
  826. {
  827. flag = true;
  828. break;
  829. }
  830. }
  831. if (flag)
  832. break;
  833. }
  834. Assert.AreEqual(true, flag, "#GS7 failed");
  835. }
  836. [Test]
  837. public void GetSchemaTest8()
  838. {
  839. bool flag = false;
  840. DataTable tab1 = conn.GetSchema("Tables");
  841. foreach (DataRow row in tab1.Rows)
  842. {
  843. foreach (DataColumn col in tab1.Columns)
  844. {
  845. /*
  846. * We need to consider multiple values
  847. */
  848. if (col.ColumnName.ToString() == "TABLE_NAME" && row[col].ToString() == "binary_family")
  849. {
  850. flag = true;
  851. break;
  852. }
  853. }
  854. if (flag)
  855. break;
  856. }
  857. Assert.AreEqual(true, flag, "#GS8 failed");
  858. }
  859. [Test]
  860. public void GetSchemaTest9()
  861. {
  862. bool flag = false;
  863. DataTable tab1 = conn.GetSchema("Columns");
  864. foreach (DataRow row in tab1.Rows)
  865. {
  866. foreach (DataColumn col in tab1.Columns)
  867. {
  868. /*
  869. * We need to consider multiple values
  870. */
  871. if (col.ColumnName.ToString() == "TABLE_NAME" && row[col].ToString() == "binary_family")
  872. {
  873. flag = true;
  874. break;
  875. }
  876. }
  877. if (flag)
  878. break;
  879. }
  880. Assert.AreEqual(true, flag, "#GS9 failed");
  881. }
  882. [Test]
  883. public void GetSchemaTest10()
  884. {
  885. bool flag = false;
  886. DataTable tab1 = conn.GetSchema("Users");
  887. foreach (DataRow row in tab1.Rows)
  888. {
  889. foreach (DataColumn col in tab1.Columns)
  890. {
  891. /*
  892. * We need to consider multiple values
  893. */
  894. if (col.ColumnName.ToString() == "user_name" && row[col].ToString() == "public")
  895. {
  896. flag = true;
  897. break;
  898. }
  899. }
  900. if (flag)
  901. break;
  902. }
  903. Assert.AreEqual(true, flag, "#GS10 failed");
  904. }
  905. [Test]
  906. public void GetSchemaTest11 ()
  907. {
  908. Assert.Ignore ("Incorrect syntax near 'TABLE_SCHEMA'");
  909. bool flag = false;
  910. DataTable tab1 = conn.GetSchema("Views");
  911. flag = true; // FIXME: Currently MS-SQL 2005 returns empty table. Remove this flag ASAP.
  912. foreach (DataRow row in tab1.Rows)
  913. {
  914. foreach (DataColumn col in tab1.Columns)
  915. {
  916. /*
  917. * We need to consider multiple values.
  918. */
  919. if (col.ColumnName.ToString() == "user_name" && row[col].ToString() == "public")
  920. {
  921. flag = true;
  922. break;
  923. }
  924. }
  925. if (flag)
  926. break;
  927. }
  928. Assert.AreEqual(true, flag, "#GS11 failed");
  929. }
  930. [Test]
  931. public void GetSchemaTest12 ()
  932. {
  933. Assert.Ignore ("Incorrect syntax near '('");
  934. bool flag = false;
  935. DataTable tab1 = conn.GetSchema("ViewColumns");
  936. flag = true; // FIXME: Currently MS-SQL 2005 returns empty table. Remove this flag ASAP.
  937. foreach (DataRow row in tab1.Rows)
  938. {
  939. foreach (DataColumn col in tab1.Columns)
  940. {
  941. /*
  942. * We need to consider multiple values.
  943. */
  944. if (col.ColumnName.ToString() == "user_name" && row[col].ToString() == "public")
  945. {
  946. flag = true;
  947. break;
  948. }
  949. }
  950. if (flag)
  951. break;
  952. }
  953. Assert.AreEqual(true, flag, "#GS12 failed");
  954. }
  955. [Test]
  956. public void GetSchemaTest13 ()
  957. {
  958. Assert.Ignore ("The multi-part identifier \"assportemblies.name\" could not be bound");
  959. bool flag = false;
  960. DataTable tab1 = conn.GetSchema("UserDefinedTypes");
  961. flag = true; // FIXME: Currently MS-SQL 2005 returns empty table. Remove this flag ASAP.
  962. foreach (DataRow row in tab1.Rows)
  963. {
  964. foreach (DataColumn col in tab1.Columns)
  965. {
  966. /*
  967. * We need to consider multiple values.
  968. */
  969. if (col.ColumnName.ToString() == "user_name" && row[col].ToString() == "public")
  970. {
  971. flag = true;
  972. break;
  973. }
  974. }
  975. if (flag)
  976. break;
  977. }
  978. Assert.AreEqual(true, flag, "#GS13 failed");
  979. }
  980. [Test]
  981. public void GetSchemaTest14()
  982. {
  983. bool flag = false;
  984. string [] restrictions = new string[4];
  985. restrictions[0] = "monotest";
  986. restrictions[1] = "dbo";
  987. restrictions[2] = null;
  988. restrictions[3] = "BASE TABLE";
  989. DataTable tab1 = conn.GetSchema("Tables", restrictions);
  990. foreach (DataRow row in tab1.Rows)
  991. {
  992. foreach (DataColumn col in tab1.Columns)
  993. {
  994. /*
  995. * We need to consider multiple values
  996. */
  997. if (col.ColumnName.ToString() == "TABLE_NAME" && row[col].ToString() == "binary_family")
  998. {
  999. flag = true;
  1000. break;
  1001. }
  1002. }
  1003. if (flag)
  1004. break;
  1005. }
  1006. Assert.AreEqual(true, flag, "#GS14 failed");
  1007. }
  1008. [Test]
  1009. public void GetSchemaTest15()
  1010. {
  1011. bool flag = false;
  1012. string [] restrictions = new string[4];
  1013. restrictions[0] = "monotest";
  1014. restrictions[1] = null;
  1015. restrictions[2] = "binary_family";
  1016. restrictions[3] = null;
  1017. DataTable tab1 = conn.GetSchema("IndexColumns", restrictions);
  1018. foreach (DataRow row in tab1.Rows)
  1019. {
  1020. foreach (DataColumn col in tab1.Columns)
  1021. {
  1022. /*
  1023. * We need to consider multiple values
  1024. */
  1025. if (col.ColumnName.ToString() == "table_name" && row[col].ToString() == "binary_family")
  1026. {
  1027. flag = true;
  1028. break;
  1029. }
  1030. }
  1031. if (flag)
  1032. break;
  1033. }
  1034. Assert.AreEqual(true, flag, "#GS15 failed");
  1035. }
  1036. [Test]
  1037. public void GetSchemaTest16()
  1038. {
  1039. bool flag = false;
  1040. string [] restrictions = new string[4];
  1041. restrictions[0] = "monotest";
  1042. restrictions[1] = null;
  1043. restrictions[2] = "sp_get_age";
  1044. restrictions[3] = null;
  1045. DataTable tab1 = conn.GetSchema("Procedures", restrictions);
  1046. foreach (DataRow row in tab1.Rows)
  1047. {
  1048. foreach (DataColumn col in tab1.Columns)
  1049. {
  1050. /*
  1051. * We need to consider multiple values
  1052. */
  1053. if (col.ColumnName.ToString() == "ROUTINE_NAME" && row[col].ToString() == "sp_get_age")
  1054. {
  1055. flag = true;
  1056. break;
  1057. }
  1058. }
  1059. if (flag)
  1060. break;
  1061. }
  1062. Assert.AreEqual(true, flag, "#GS16 failed");
  1063. }
  1064. [Test]
  1065. public void GetSchemaTest17()
  1066. {
  1067. bool flag = false;
  1068. DataTable tab1 = conn.GetSchema();
  1069. foreach (DataRow row in tab1.Rows)
  1070. {
  1071. foreach (DataColumn col in tab1.Columns)
  1072. {
  1073. /*
  1074. * We need to consider multiple values
  1075. */
  1076. if (col.ColumnName.ToString() == "CollectionName" && row[col].ToString() == "UserDefinedTypes")
  1077. {
  1078. flag = true;
  1079. break;
  1080. }
  1081. }
  1082. if (flag)
  1083. break;
  1084. }
  1085. Assert.AreEqual(true, flag, "#GS17 failed");
  1086. }
  1087. [Test]
  1088. public void GetSchemaTest18()
  1089. {
  1090. bool flag = false;
  1091. DataTable tab1 = conn.GetSchema("RESTRICTIONS");
  1092. foreach (DataRow row in tab1.Rows)
  1093. {
  1094. foreach (DataColumn col in tab1.Columns)
  1095. {
  1096. /*
  1097. * We need to consider multiple values
  1098. */
  1099. if (col.ColumnName.ToString() == "RestrictionDefault" && row[col].ToString() == "CONSTRAINT_NAME")
  1100. {
  1101. flag = true;
  1102. break;
  1103. }
  1104. }
  1105. if (flag)
  1106. break;
  1107. }
  1108. Assert.AreEqual(true, flag, "#GS18 failed");
  1109. }
  1110. [Test]
  1111. [ExpectedException (typeof (ArgumentException))]
  1112. public void GetSchemaTest19 ()
  1113. {
  1114. String [] restrictions = new String[1];
  1115. conn.GetSchema("RESTRICTIONS", restrictions);
  1116. }
  1117. [Test]
  1118. public void GetSchemaTest20 ()
  1119. {
  1120. bool flag = false;
  1121. DataTable tab1 = conn.GetSchema("DataTypes");
  1122. foreach (DataRow row in tab1.Rows)
  1123. {
  1124. foreach (DataColumn col in tab1.Columns)
  1125. {
  1126. /*
  1127. * We need to consider multiple values
  1128. */
  1129. if (col.ColumnName.ToString() == "TypeName" && row[col].ToString() == "uniqueidentifier")
  1130. {
  1131. flag = true;
  1132. break;
  1133. }
  1134. }
  1135. if (flag)
  1136. break;
  1137. }
  1138. Assert.AreEqual(true, flag, "#GS20 failed");
  1139. }
  1140. [Test]
  1141. public void GetSchemaTest21()
  1142. {
  1143. bool flag = false;
  1144. DataTable tab1 = conn.GetSchema();
  1145. foreach (DataRow row in tab1.Rows)
  1146. {
  1147. foreach (DataColumn col in tab1.Columns)
  1148. {
  1149. /*
  1150. * We need to consider multiple values
  1151. */
  1152. if (col.ColumnName.ToString() == "CollectionName" && row[col].ToString() == "UserDefinedTypes")
  1153. {
  1154. flag = true;
  1155. break;
  1156. }
  1157. }
  1158. if (flag)
  1159. break;
  1160. }
  1161. Assert.AreEqual(true, flag, "#GS21 failed");
  1162. }
  1163. [Test]
  1164. public void GetSchemaTest22()
  1165. {
  1166. bool flag = false;
  1167. DataTable tab1 = conn.GetSchema("ReservedWords");
  1168. foreach (DataRow row in tab1.Rows)
  1169. {
  1170. foreach (DataColumn col in tab1.Columns)
  1171. {
  1172. /*
  1173. * We need to consider multiple values
  1174. */
  1175. if (col.ColumnName.ToString() == "ReservedWord" && row[col].ToString() == "UPPER")
  1176. {
  1177. flag = true;
  1178. break;
  1179. }
  1180. }
  1181. if (flag)
  1182. break;
  1183. }
  1184. Assert.AreEqual(true, flag, "#GS22 failed");
  1185. }
  1186. [Test]
  1187. public void GetSchemaTest23()
  1188. {
  1189. bool flag = false;
  1190. DataTable tab1 = conn.GetSchema("ReservedWords");
  1191. foreach (DataRow row in tab1.Rows)
  1192. {
  1193. foreach (DataColumn col in tab1.Columns)
  1194. {
  1195. /*
  1196. * We need to consider multiple values
  1197. */
  1198. if (col.ColumnName.ToString() == "ReservedWord" && row[col].ToString() == "upper")
  1199. {
  1200. flag = true;
  1201. break;
  1202. }
  1203. }
  1204. if (flag)
  1205. break;
  1206. }
  1207. Assert.AreEqual(false, flag, "#GS23 failed");
  1208. }
  1209. [Test]
  1210. public void GetSchemaTest24()
  1211. {
  1212. bool flag = false;
  1213. string [] restrictions = new string[4];
  1214. restrictions[0] = "monotest";
  1215. restrictions[1] = null;
  1216. restrictions[2] = "sp_get_age";
  1217. restrictions[3] = null;
  1218. DataTable tab1 = conn.GetSchema("Procedures", restrictions);
  1219. foreach (DataRow row in tab1.Rows)
  1220. {
  1221. foreach (DataColumn col in tab1.Columns)
  1222. {
  1223. /*
  1224. * We need to consider multiple values
  1225. */
  1226. if (col.ColumnName.ToString() == "ROUTINE_NAME" && row[col].ToString() == "mono")
  1227. {
  1228. flag = true;
  1229. break;
  1230. }
  1231. }
  1232. if (flag)
  1233. break;
  1234. }
  1235. Assert.AreEqual(false, flag, "#GS24 failed");
  1236. }
  1237. [Test]
  1238. [ExpectedException (typeof (ArgumentException))]
  1239. public void GetSchemaTest25 ()
  1240. {
  1241. String [] restrictions = new String [1];
  1242. conn.GetSchema ("Mono", restrictions);
  1243. }
  1244. }
  1245. #endif
  1246. }