SqlConnectionTest.cs 38 KB

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