SqlConnectionTest.cs 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414
  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.Connected.SqlClient
  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.Instance.Sql.ConnectionString;
  51. engine = ConnectionManager.Instance.Sql.EngineConfig;
  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.AreEqual (18456, ex.Number, "#7");
  134. Assert.AreEqual ((byte) 1, ex.State, "#8");
  135. } finally {
  136. conn.Close ();
  137. }
  138. }
  139. [Test]
  140. public void Open_ConnectionString_DatabaseInvalid ()
  141. {
  142. conn = new SqlConnection (connectionString + "database=invalidDB");
  143. try {
  144. conn.Open ();
  145. Assert.Fail ("#1");
  146. } catch (SqlException ex) {
  147. // Cannot open database "invalidDB" requested
  148. // by the login. The login failed
  149. Assert.AreEqual (typeof (SqlException), ex.GetType (), "#2");
  150. Assert.AreEqual ((byte) 14, ex.Class, "#3");
  151. Assert.IsNull (ex.InnerException, "#4");
  152. Assert.IsNotNull (ex.Message, "#5");
  153. Assert.AreEqual (18456, ex.Number, "#7");
  154. Assert.AreEqual ((byte) 1, ex.State, "#8");
  155. } finally {
  156. conn.Close ();
  157. }
  158. }
  159. [Test]
  160. public void Open_ConnectionString_PasswordInvalid ()
  161. {
  162. // password invalid
  163. conn = new SqlConnection (connectionString + ";password=invalidPassword");
  164. try {
  165. conn.Open ();
  166. Assert.Fail ("#1");
  167. } catch (SqlException ex) {
  168. // Login failed for user '...'
  169. Assert.AreEqual (typeof (SqlException), ex.GetType (), "#2");
  170. Assert.AreEqual ((byte) 14, ex.Class, "#3");
  171. Assert.IsNull (ex.InnerException, "#4");
  172. Assert.IsNotNull (ex.Message, "#5");
  173. Assert.AreEqual (18456, ex.Number, "#6");
  174. Assert.AreEqual ((byte) 1, ex.State, "#7");
  175. } finally {
  176. conn.Close ();
  177. }
  178. }
  179. [Test]
  180. public void Open_ConnectionString_ServerInvalid ()
  181. {
  182. Assert.Ignore ("Long running");
  183. // server invalid
  184. conn = new SqlConnection (connectionString + ";server=invalidServerName");
  185. try {
  186. conn.Open ();
  187. Assert.Fail ("#1");
  188. } catch (SqlException ex) {
  189. // An error has occurred while establishing a
  190. // connection to the server...
  191. Assert.AreEqual (typeof (SqlException), ex.GetType (), "#2");
  192. Assert.AreEqual ((byte) 20, ex.Class, "#3");
  193. Assert.IsNull (ex.InnerException, "#4");
  194. Assert.IsNotNull (ex.Message, "#5");
  195. Assert.AreEqual (53, ex.Number, "#6");
  196. Assert.AreEqual ((byte) 0, ex.State, "#7");
  197. } finally {
  198. conn.Close ();
  199. }
  200. }
  201. [Test] // bug #383061
  202. [Category("NotWorking")]
  203. public void Open_MaxPoolSize_Reached ()
  204. {
  205. connectionString += ";Pooling=true;Connection Lifetime=6;Connect Timeout=3;Max Pool Size=2";
  206. SqlConnection conn1 = new SqlConnection (connectionString);
  207. conn1.Open ();
  208. SqlConnection conn2 = new SqlConnection (connectionString);
  209. conn2.Open ();
  210. DateTime start = DateTime.Now;
  211. try {
  212. using (SqlConnection sqlConnection = new SqlConnection (connectionString)) {
  213. sqlConnection.Open ();
  214. }
  215. Assert.Fail ("#A1");
  216. } catch (InvalidOperationException ex) {
  217. // System.InvalidOperationException: Timeout expired.
  218. // The timeout period elapsed prior to obtaining a
  219. // connection from the pool. This may have occurred
  220. // because all pooled connections were in use and max
  221. // pool size was reached.
  222. Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
  223. Assert.IsNull (ex.InnerException, "#A3");
  224. Assert.IsNotNull (ex.Message, "#A4");
  225. }
  226. TimeSpan elapsed = DateTime.Now - start;
  227. Assert.IsTrue (elapsed.TotalSeconds >= 3, "#B1:" + elapsed.TotalSeconds);
  228. Assert.IsTrue (elapsed.TotalSeconds < 4, "#B2:" + elapsed.TotalSeconds);
  229. conn2.Close ();
  230. // as the second connection is closed, we should now be
  231. // able to open a new connection (which essentially
  232. // uses the pooled connection from conn2)
  233. SqlConnection conn3 = new SqlConnection (connectionString);
  234. conn3.Open ();
  235. conn3.Close ();
  236. conn1.Close ();
  237. }
  238. [Test] // bug #412574
  239. public void Close ()
  240. {
  241. conn = new SqlConnection (connectionString);
  242. conn.Open ();
  243. conn.StateChange += new StateChangeEventHandler (Connection_StateChange);
  244. conn.Close ();
  245. Assert.AreEqual (ConnectionState.Closed, conn.State, "#1");
  246. Assert.AreEqual (1, events.Count, "#2");
  247. StateChangeEventArgs args = events [0] as StateChangeEventArgs;
  248. Assert.IsNotNull (args, "#3");
  249. Assert.AreEqual (ConnectionState.Open, args.OriginalState, "#4");
  250. Assert.AreEqual (ConnectionState.Closed, args.CurrentState, "5");
  251. conn.Close ();
  252. Assert.AreEqual (1, events.Count, "#6");
  253. }
  254. [Test]
  255. public void ChangeDatabase ()
  256. {
  257. conn = new SqlConnection (connectionString);
  258. conn.Open ();
  259. conn.ChangeDatabase ("master");
  260. Assert.AreEqual ("master", conn.Database);
  261. }
  262. [Test]
  263. public void ChangeDatabase_DatabaseName_DoesNotExist ()
  264. {
  265. conn = new SqlConnection (connectionString);
  266. conn.Open ();
  267. String database = conn.Database;
  268. try {
  269. conn.ChangeDatabase ("doesnotexist");
  270. Assert.Fail ("#1");
  271. } catch (SqlException ex) {
  272. // Could not locate entry in sysdatabases for
  273. // database 'doesnotexist'. No entry found with
  274. // that name. Make sure that the name is entered
  275. // correctly.
  276. Assert.AreEqual (typeof (SqlException), ex.GetType (), "#2");
  277. Assert.AreEqual ((byte) 16, ex.Class, "#3");
  278. Assert.IsNull (ex.InnerException, "#4");
  279. Assert.IsNotNull (ex.Message, "#5");
  280. Assert.IsTrue (ex.Message.IndexOf ("'doesnotexist'") != -1, "#6");
  281. Assert.AreEqual (911, ex.Number, "#7");
  282. Assert.AreEqual ((byte) 1, ex.State, "#8");
  283. Assert.AreEqual (database, conn.Database, "#9");
  284. } finally {
  285. conn.Close ();
  286. }
  287. }
  288. [Test]
  289. public void ChangeDatabase_DatabaseName_Empty ()
  290. {
  291. conn = new SqlConnection (connectionString);
  292. conn.Open ();
  293. try {
  294. conn.ChangeDatabase (string.Empty);
  295. Assert.Fail ("#1");
  296. } catch (ArgumentException ex) {
  297. // Database cannot be null, the empty string,
  298. // or string of only whitespace
  299. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  300. Assert.IsNull (ex.InnerException, "#3");
  301. Assert.IsNotNull (ex.Message, "#4");
  302. Assert.IsNull (ex.ParamName);
  303. }
  304. }
  305. [Test]
  306. public void ChangeDatabase_DatabaseName_Null ()
  307. {
  308. conn = new SqlConnection (connectionString);
  309. conn.Open ();
  310. try {
  311. conn.ChangeDatabase ((string) null);
  312. Assert.Fail ("#1");
  313. } catch (ArgumentException ex) {
  314. // Database cannot be null, the empty string,
  315. // or string of only whitespace
  316. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  317. Assert.IsNull (ex.InnerException, "#3");
  318. Assert.IsNotNull (ex.Message, "#4");
  319. Assert.IsNull (ex.ParamName);
  320. }
  321. }
  322. [Test] // bug #412581
  323. public void ChangeDatabase_DatabaseName_Whitespace ()
  324. {
  325. Assert.Ignore ("bug #412581");
  326. conn = new SqlConnection (connectionString);
  327. conn.Open ();
  328. try {
  329. conn.ChangeDatabase (" ");
  330. Assert.Fail ("#1");
  331. } catch (SqlException ex) {
  332. // Could not locate entry in sysdatabases for
  333. // database ' '. No entry found with that name.
  334. // Make sure that the name is entered correctly
  335. Assert.AreEqual (typeof (SqlException), ex.GetType (), "#2");
  336. Assert.AreEqual ((byte) 16, ex.Class, "#3");
  337. Assert.IsNull (ex.InnerException, "#4");
  338. Assert.IsNotNull (ex.Message, "#5");
  339. Assert.IsTrue (ex.Message.IndexOf ("' '") != -1, "#6");
  340. Assert.AreEqual (911, ex.Number, "#7");
  341. Assert.AreEqual ((byte) 1, ex.State, "#8");
  342. }
  343. }
  344. [Test]
  345. public void ClearAllPools ()
  346. {
  347. SqlConnection conn1 = new SqlConnection (connectionString + ";Pooling=false");
  348. conn1.Open ();
  349. int initial_connection_count = GetConnectionCount (conn1);
  350. SqlConnection conn2 = new SqlConnection (connectionString + ";App=A");
  351. conn2.Open ();
  352. conn2.Close ();
  353. SqlConnection conn3 = new SqlConnection (connectionString + ";App=B");
  354. conn3.Open ();
  355. conn3.Close ();
  356. Assert.AreEqual (initial_connection_count + 2, GetConnectionCount (conn1), "#1");
  357. SqlConnection.ClearAllPools ();
  358. Assert.AreEqual (initial_connection_count, GetConnectionCount (conn1), "#2");
  359. conn1.Close ();
  360. }
  361. [Test] // bug #443131
  362. [Category("NotWorking")]
  363. public void ClearPool ()
  364. {
  365. SqlConnection conn1 = new SqlConnection (connectionString);
  366. conn1.Open ();
  367. int initial_connection_count = GetConnectionCount (conn1);
  368. SqlConnection conn2 = new SqlConnection (connectionString);
  369. conn2.Open ();
  370. SqlConnection conn3 = new SqlConnection (connectionString);
  371. conn3.Open ();
  372. conn3.Close ();
  373. Assert.AreEqual (initial_connection_count + 2, GetConnectionCount (conn1), "#1");
  374. SqlConnection.ClearPool (conn1);
  375. // check if pooled connections that were not in use are
  376. // actually closed
  377. Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn1), "#2");
  378. conn2.Close ();
  379. // check if connections that were in use when the pool
  380. // was cleared will not be returned to the pool when
  381. // closed (and are closed instead)
  382. Assert.AreEqual (initial_connection_count, GetConnectionCount (conn1), "#3");
  383. SqlConnection conn4 = new SqlConnection (connectionString);
  384. conn4.Open ();
  385. SqlConnection conn5 = new SqlConnection (connectionString);
  386. conn5.Open ();
  387. SqlConnection conn6 = new SqlConnection (connectionString);
  388. conn6.Open ();
  389. Assert.AreEqual (initial_connection_count + 3, GetConnectionCount (conn1), "#4");
  390. conn5.Close ();
  391. conn6.Close ();
  392. // check if new connections are stored in the pool again
  393. Assert.AreEqual (initial_connection_count + 3, GetConnectionCount (conn1), "#5");
  394. conn1.Close ();
  395. Assert.AreEqual (initial_connection_count + 2, GetConnectionCount (conn4), "#6");
  396. SqlConnection.ClearPool (conn3);
  397. // the connection passed to ClearPool does not have to
  398. // be open
  399. Assert.AreEqual (initial_connection_count, GetConnectionCount (conn4), "#7");
  400. SqlConnection conn7 = new SqlConnection (connectionString);
  401. conn7.Open ();
  402. conn7.Close ();
  403. Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn4), "#8");
  404. conn3.ConnectionString += ";App=B";
  405. SqlConnection.ClearPool (conn3);
  406. // check if a pool is identified by its connection string
  407. Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn4), "#9");
  408. SqlConnection conn8 = new SqlConnection (connectionString);
  409. SqlConnection.ClearPool (conn8);
  410. // connection should not have been opened before to
  411. // clear the corresponding pool
  412. Assert.AreEqual (initial_connection_count, GetConnectionCount (conn4), "#10");
  413. SqlConnection conn9 = new SqlConnection (connectionString);
  414. conn9.Open ();
  415. conn9.Close ();
  416. Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn4), "#11");
  417. conn3.ConnectionString = connectionString;
  418. SqlConnection.ClearPool (conn3);
  419. Assert.AreEqual (initial_connection_count, GetConnectionCount (conn4), "#12");
  420. SqlConnection conn10 = new SqlConnection (connectionString);
  421. conn10.Open ();
  422. SqlConnection conn11 = new SqlConnection (connectionString + ";App=B");
  423. conn11.Open ();
  424. SqlConnection conn12 = new SqlConnection (connectionString + ";App=B");
  425. conn12.Open ();
  426. SqlConnection conn13 = new SqlConnection (connectionString + ";App=B");
  427. conn13.Open ();
  428. conn10.Close ();
  429. conn11.Close ();
  430. conn12.Close ();
  431. conn13.Close ();
  432. Assert.AreEqual (initial_connection_count + 4, GetConnectionCount (conn4), "#13");
  433. // check that other connection pools are not affected
  434. SqlConnection.ClearPool (conn13);
  435. Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn4), "#14");
  436. SqlConnection conn14 = new SqlConnection (connectionString);
  437. conn14.Open ();
  438. conn14.Dispose ();
  439. // a disposed connection cannot be used to clear a pool
  440. SqlConnection.ClearPool (conn14);
  441. Assert.AreEqual (initial_connection_count + 1, GetConnectionCount (conn4), "#15");
  442. SqlConnection.ClearPool (conn4);
  443. Assert.AreEqual (initial_connection_count, GetConnectionCount (conn4), "#16");
  444. conn4.Close ();
  445. }
  446. [Test]
  447. public void InterfaceTransactionTest ()
  448. {
  449. conn = new SqlConnection (connectionString);
  450. conn.Open ();
  451. IDbCommand idbCommand = new SqlCommand ("use [mono-test]", conn);
  452. idbCommand.Connection = null;
  453. Assert.AreEqual (null, idbCommand.Connection, "Connection should be null");
  454. idbCommand.Transaction = null;
  455. Assert.AreEqual (null, idbCommand.Transaction, "Transaction should be null");
  456. conn.Close ();
  457. }
  458. [Test]
  459. public void BeginTransaction ()
  460. {
  461. conn = new SqlConnection (connectionString);
  462. conn.Open ();
  463. SqlTransaction trans = conn.BeginTransaction ();
  464. Assert.AreSame (conn, trans.Connection, "#A1");
  465. Assert.AreEqual (IsolationLevel.ReadCommitted, trans.IsolationLevel, "#A2");
  466. trans.Rollback ();
  467. trans = conn.BeginTransaction ();
  468. try {
  469. conn.BeginTransaction ();
  470. Assert.Fail ("#B1");
  471. } catch (InvalidOperationException ex) {
  472. // SqlConnection does not support parallel transactions
  473. Assert.AreEqual (typeof(InvalidOperationException), ex.GetType(), "#B2");
  474. Assert.IsNull (ex.InnerException, "#B3");
  475. Assert.IsNotNull (ex.Message, "#B4");
  476. } finally {
  477. trans.Rollback();
  478. }
  479. try {
  480. trans = conn.BeginTransaction ();
  481. trans.Rollback ();
  482. trans = conn.BeginTransaction ();
  483. trans.Commit ();
  484. trans = conn.BeginTransaction ();
  485. } finally {
  486. trans.Rollback ();
  487. }
  488. }
  489. [Test]
  490. public void ConnectionString ()
  491. {
  492. conn = new SqlConnection (connectionString);
  493. // Test Repeated Keyoword should take the latest value
  494. conn.ConnectionString = conn.ConnectionString + ";server=RepeatedServer;";
  495. Assert.AreEqual ("RepeatedServer", ((SqlConnection)conn).DataSource, "#A1");
  496. conn.ConnectionString += ";database=gen;Initial Catalog=gen1";
  497. Assert.AreEqual ("gen1", conn.Database, "#A2");
  498. // Test if properties are set correctly
  499. string str = "server=localhost1;database=db;user id=user;";
  500. str += "password=pwd;Workstation ID=workstation;Packet Size=512;";
  501. str += "Connect Timeout=10";
  502. conn.ConnectionString = str;
  503. Assert.AreEqual ("localhost1", conn.DataSource, "#B1");
  504. Assert.AreEqual ("db", conn.Database, "#B2");
  505. Assert.AreEqual (ConnectionState.Closed, conn.State, "#B3");
  506. Assert.AreEqual ("workstation", conn.WorkstationId, "#B4");
  507. Assert.AreEqual (512, conn.PacketSize, "#B5");
  508. Assert.AreEqual (10, conn.ConnectionTimeout, "#B6");
  509. // Test if any leftover values exist from previous invocation
  510. conn.ConnectionString = connectionString;
  511. conn.ConnectionString = string.Empty;
  512. Assert.AreEqual (string.Empty, conn.DataSource, "#C1");
  513. Assert.AreEqual ("", conn.Database, "#C2");
  514. Assert.AreEqual (8000, conn.PacketSize, "#C3");
  515. Assert.AreEqual (15, conn.ConnectionTimeout, "#C4");
  516. Assert.IsTrue (string.Compare (conn.WorkstationId, Environment.MachineName, true) == 0, "#C5");
  517. }
  518. [Test]
  519. public void ConnectionString_Connection_Open ()
  520. {
  521. conn = new SqlConnection (connectionString);
  522. conn.ConnectionString = connectionString;
  523. conn.Open ();
  524. try {
  525. conn.ConnectionString = "server=localhost;database=tmp;";
  526. Assert.Fail ("#1");
  527. } catch (InvalidOperationException ex) {
  528. // Not allowed to change the 'ConnectionString'
  529. // property. The connection's current state is open
  530. Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
  531. Assert.IsNull (ex.InnerException, "#3");
  532. Assert.IsNotNull (ex.Message, "#4");
  533. } finally {
  534. conn.Close ();
  535. }
  536. }
  537. [Test]
  538. public void ServerVersionTest ()
  539. {
  540. conn = new SqlConnection (connectionString);
  541. // Test InvalidOperation Exception is thrown if Connection is CLOSED
  542. try {
  543. string s = conn.ServerVersion;
  544. Assert.Fail ("#A1:" + s);
  545. } catch (InvalidOperationException ex) {
  546. Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
  547. Assert.IsNull (ex.InnerException, "#A3");
  548. Assert.IsNotNull (ex.Message, "#A4");
  549. }
  550. // Test if Release Version is as per specification.
  551. conn.Open ();
  552. String [] version = conn.ServerVersion.Split ('.');
  553. Assert.AreEqual (2, version[0].Length,
  554. "#B1 The Major release shud be exactly 2 characters");
  555. Assert.AreEqual (2, version[1].Length,
  556. "#B2 The Minor release shud be exactly 2 characters");
  557. Assert.AreEqual (4, version[2].Length,
  558. "#B3 The Release version should be exactly 4 digits");
  559. }
  560. [Test]
  561. public void Database ()
  562. {
  563. conn = new SqlConnection (connectionString);
  564. string database = conn.Database;
  565. SqlCommand cmd;
  566. // Test if database property is updated when a query changes database
  567. conn.Open ();
  568. cmd = new SqlCommand ("use [master]" , conn);
  569. cmd.ExecuteNonQuery ();
  570. Assert.AreEqual ("master", conn.Database, "#1");
  571. // ensure we're really in the expected database
  572. if (ClientVersion == 7)
  573. cmd.CommandText = "SELECT name FROM sysdatabases WHERE name = 'master'";
  574. else
  575. cmd.CommandText = "SELECT name FROM sys.databases WHERE name = 'master'";
  576. using (SqlDataReader dr = cmd.ExecuteReader ()) {
  577. Assert.IsTrue (dr.Read (), "#2");
  578. }
  579. conn.Close ();
  580. Assert.AreEqual (database, conn.Database, "#3");
  581. // Test if the database property is reset on re-opening the connection
  582. conn.ConnectionString = connectionString;
  583. conn.Open ();
  584. Assert.AreEqual (database, conn.Database, "#4");
  585. // ensure we're really in the expected database
  586. cmd.CommandText = "SELECT fname FROM employee WHERE id = 2";
  587. using (SqlDataReader dr = cmd.ExecuteReader ()) {
  588. Assert.IsTrue (dr.Read (), "#5");
  589. Assert.AreEqual ("ramesh", dr.GetValue (0), "#6");
  590. }
  591. conn.Close ();
  592. }
  593. [Test] // bug #412571
  594. public void Dispose ()
  595. {
  596. StateChangeEventArgs stateChangeArgs;
  597. EventArgs disposedArgs;
  598. conn = new SqlConnection (connectionString + ";Connection Timeout=30;Packet Size=512;Workstation Id=Desktop");
  599. conn.Disposed += new EventHandler (Connection_Disposed);
  600. conn.Open ();
  601. conn.StateChange += new StateChangeEventHandler (Connection_StateChange);
  602. Assert.AreEqual (0, events.Count, "#A1");
  603. conn.Dispose ();
  604. Assert.AreEqual (string.Empty, conn.ConnectionString, "#A2");
  605. Assert.AreEqual (15, conn.ConnectionTimeout, "#A3");
  606. Assert.AreEqual (string.Empty, conn.Database, "#A4");
  607. Assert.AreEqual (string.Empty, conn.DataSource, "#A5");
  608. Assert.AreEqual (8000, conn.PacketSize, "#A6");
  609. Assert.AreEqual (ConnectionState.Closed, conn.State, "#A7");
  610. Assert.IsTrue (string.Compare (conn.WorkstationId, Environment.MachineName, true) == 0, "#A8");
  611. Assert.AreEqual (2, events.Count, "#A9");
  612. stateChangeArgs = events [0] as StateChangeEventArgs;
  613. Assert.IsNotNull (stateChangeArgs, "#B1");
  614. Assert.AreEqual (typeof (StateChangeEventArgs), stateChangeArgs.GetType (), "#B2");
  615. Assert.AreEqual (ConnectionState.Open, stateChangeArgs.OriginalState, "#B3");
  616. Assert.AreEqual (ConnectionState.Closed, stateChangeArgs.CurrentState, "B4");
  617. disposedArgs = events [1] as EventArgs;
  618. Assert.IsNotNull (disposedArgs, "#C1");
  619. Assert.AreEqual (typeof (EventArgs), disposedArgs.GetType (), "#C2");
  620. conn.Dispose ();
  621. Assert.AreEqual (ConnectionState.Closed, conn.State, "#D1");
  622. Assert.AreEqual (3, events.Count, "#D2");
  623. disposedArgs = events [2] as EventArgs;
  624. Assert.IsNotNull (disposedArgs, "#E1");
  625. Assert.AreEqual (typeof (EventArgs), disposedArgs.GetType (), "#E2");
  626. }
  627. void Connection_StateChange (object sender , StateChangeEventArgs e)
  628. {
  629. events.Add (e);
  630. }
  631. void Connection_Disposed (object sender , EventArgs e)
  632. {
  633. events.Add (e);
  634. }
  635. [Test]
  636. public void FireInfoMessageEventOnUserErrorsTest ()
  637. {
  638. conn = new SqlConnection ();
  639. Assert.AreEqual(false, conn.FireInfoMessageEventOnUserErrors, "#1 The default value should be false");
  640. conn.FireInfoMessageEventOnUserErrors = true;
  641. Assert.AreEqual(true, conn.FireInfoMessageEventOnUserErrors, "#1 The value should be true after setting the property to true");
  642. }
  643. [Test]
  644. public void StatisticsEnabledTest ()
  645. {
  646. conn = new SqlConnection ();
  647. Assert.AreEqual(false, conn.StatisticsEnabled, "#1 The default value should be false");
  648. conn.StatisticsEnabled = true;
  649. Assert.AreEqual(true, conn.StatisticsEnabled, "#1 The value should be true after setting the property to true");
  650. }
  651. [Test]
  652. [Category("NotWorking")]
  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.Instance.Sql.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() == ConnectionManager.Instance.DatabaseName)
  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. [Ignore("TODO: fix restrictions")]
  983. public void GetSchemaTest14()
  984. {
  985. bool flag = false;
  986. string [] restrictions = new string[4];
  987. restrictions[0] = ConnectionManager.Instance.DatabaseName;
  988. restrictions[1] = "dbo";
  989. restrictions[2] = null;
  990. restrictions[3] = "BASE TABLE";
  991. DataTable tab1 = conn.GetSchema("Tables", restrictions);
  992. foreach (DataRow row in tab1.Rows)
  993. {
  994. foreach (DataColumn col in tab1.Columns)
  995. {
  996. /*
  997. * We need to consider multiple values
  998. */
  999. if (col.ColumnName.ToString() == "TABLE_NAME" && row[col].ToString() == "binary_family")
  1000. {
  1001. flag = true;
  1002. break;
  1003. }
  1004. }
  1005. if (flag)
  1006. break;
  1007. }
  1008. Assert.AreEqual(true, flag, "#GS14 failed");
  1009. }
  1010. [Test]
  1011. [Ignore("TODO: fix restrictions")]
  1012. public void GetSchemaTest15()
  1013. {
  1014. bool flag = false;
  1015. string [] restrictions = new string[4];
  1016. restrictions[0] = ConnectionManager.Instance.DatabaseName;
  1017. restrictions[1] = null;
  1018. restrictions[2] = "binary_family";
  1019. restrictions[3] = null;
  1020. DataTable tab1 = conn.GetSchema("IndexColumns", restrictions);
  1021. foreach (DataRow row in tab1.Rows)
  1022. {
  1023. foreach (DataColumn col in tab1.Columns)
  1024. {
  1025. /*
  1026. * We need to consider multiple values
  1027. */
  1028. if (col.ColumnName.ToString() == "table_name" && row[col].ToString() == "binary_family")
  1029. {
  1030. flag = true;
  1031. break;
  1032. }
  1033. }
  1034. if (flag)
  1035. break;
  1036. }
  1037. Assert.AreEqual(true, flag, "#GS15 failed");
  1038. }
  1039. [Test]
  1040. [Ignore("TODO: fix restrictions")]
  1041. public void GetSchemaTest16()
  1042. {
  1043. bool flag = false;
  1044. string [] restrictions = new string[4];
  1045. restrictions[0] = ConnectionManager.Instance.DatabaseName;
  1046. restrictions[1] = null;
  1047. restrictions[2] = "sp_get_age";
  1048. restrictions[3] = null;
  1049. DataTable tab1 = conn.GetSchema("Procedures", restrictions);
  1050. foreach (DataRow row in tab1.Rows)
  1051. {
  1052. foreach (DataColumn col in tab1.Columns)
  1053. {
  1054. /*
  1055. * We need to consider multiple values
  1056. */
  1057. if (col.ColumnName.ToString() == "ROUTINE_NAME" && row[col].ToString() == "sp_get_age")
  1058. {
  1059. flag = true;
  1060. break;
  1061. }
  1062. }
  1063. if (flag)
  1064. break;
  1065. }
  1066. Assert.AreEqual(true, flag, "#GS16 failed");
  1067. }
  1068. [Test]
  1069. public void GetSchemaTest17()
  1070. {
  1071. bool flag = false;
  1072. DataTable tab1 = conn.GetSchema();
  1073. foreach (DataRow row in tab1.Rows)
  1074. {
  1075. foreach (DataColumn col in tab1.Columns)
  1076. {
  1077. /*
  1078. * We need to consider multiple values
  1079. */
  1080. if (col.ColumnName.ToString() == "CollectionName" && row[col].ToString() == "UserDefinedTypes")
  1081. {
  1082. flag = true;
  1083. break;
  1084. }
  1085. }
  1086. if (flag)
  1087. break;
  1088. }
  1089. Assert.AreEqual(true, flag, "#GS17 failed");
  1090. }
  1091. [Test]
  1092. public void GetSchemaTest18()
  1093. {
  1094. bool flag = false;
  1095. DataTable tab1 = conn.GetSchema("RESTRICTIONS");
  1096. foreach (DataRow row in tab1.Rows)
  1097. {
  1098. foreach (DataColumn col in tab1.Columns)
  1099. {
  1100. /*
  1101. * We need to consider multiple values
  1102. */
  1103. if (col.ColumnName.ToString() == "RestrictionDefault" && row[col].ToString() == "CONSTRAINT_NAME")
  1104. {
  1105. flag = true;
  1106. break;
  1107. }
  1108. }
  1109. if (flag)
  1110. break;
  1111. }
  1112. Assert.AreEqual(true, flag, "#GS18 failed");
  1113. }
  1114. [Test]
  1115. [ExpectedException (typeof (ArgumentException))]
  1116. public void GetSchemaTest19 ()
  1117. {
  1118. String [] restrictions = new String[1];
  1119. conn.GetSchema("RESTRICTIONS", restrictions);
  1120. }
  1121. [Test]
  1122. public void GetSchemaTest20 ()
  1123. {
  1124. bool flag = false;
  1125. DataTable tab1 = conn.GetSchema("DataTypes");
  1126. foreach (DataRow row in tab1.Rows)
  1127. {
  1128. foreach (DataColumn col in tab1.Columns)
  1129. {
  1130. /*
  1131. * We need to consider multiple values
  1132. */
  1133. if (col.ColumnName.ToString() == "TypeName" && row[col].ToString() == "uniqueidentifier")
  1134. {
  1135. flag = true;
  1136. break;
  1137. }
  1138. }
  1139. if (flag)
  1140. break;
  1141. }
  1142. Assert.AreEqual(true, flag, "#GS20 failed");
  1143. }
  1144. [Test]
  1145. public void GetSchemaTest21()
  1146. {
  1147. bool flag = false;
  1148. DataTable tab1 = conn.GetSchema();
  1149. foreach (DataRow row in tab1.Rows)
  1150. {
  1151. foreach (DataColumn col in tab1.Columns)
  1152. {
  1153. /*
  1154. * We need to consider multiple values
  1155. */
  1156. if (col.ColumnName.ToString() == "CollectionName" && row[col].ToString() == "UserDefinedTypes")
  1157. {
  1158. flag = true;
  1159. break;
  1160. }
  1161. }
  1162. if (flag)
  1163. break;
  1164. }
  1165. Assert.AreEqual(true, flag, "#GS21 failed");
  1166. }
  1167. [Test]
  1168. public void GetSchemaTest22()
  1169. {
  1170. bool flag = false;
  1171. DataTable tab1 = conn.GetSchema("ReservedWords");
  1172. foreach (DataRow row in tab1.Rows)
  1173. {
  1174. foreach (DataColumn col in tab1.Columns)
  1175. {
  1176. /*
  1177. * We need to consider multiple values
  1178. */
  1179. if (col.ColumnName.ToString() == "ReservedWord" && row[col].ToString() == "UPPER")
  1180. {
  1181. flag = true;
  1182. break;
  1183. }
  1184. }
  1185. if (flag)
  1186. break;
  1187. }
  1188. Assert.AreEqual(true, flag, "#GS22 failed");
  1189. }
  1190. [Test]
  1191. public void GetSchemaTest23()
  1192. {
  1193. bool flag = false;
  1194. DataTable tab1 = conn.GetSchema("ReservedWords");
  1195. foreach (DataRow row in tab1.Rows)
  1196. {
  1197. foreach (DataColumn col in tab1.Columns)
  1198. {
  1199. /*
  1200. * We need to consider multiple values
  1201. */
  1202. if (col.ColumnName.ToString() == "ReservedWord" && row[col].ToString() == "upper")
  1203. {
  1204. flag = true;
  1205. break;
  1206. }
  1207. }
  1208. if (flag)
  1209. break;
  1210. }
  1211. Assert.AreEqual(false, flag, "#GS23 failed");
  1212. }
  1213. [Test]
  1214. public void GetSchemaTest24()
  1215. {
  1216. bool flag = false;
  1217. string [] restrictions = new string[4];
  1218. restrictions[0] = ConnectionManager.Instance.DatabaseName;
  1219. restrictions[1] = null;
  1220. restrictions[2] = "sp_get_age";
  1221. restrictions[3] = null;
  1222. DataTable tab1 = conn.GetSchema("Procedures", restrictions);
  1223. foreach (DataRow row in tab1.Rows)
  1224. {
  1225. foreach (DataColumn col in tab1.Columns)
  1226. {
  1227. /*
  1228. * We need to consider multiple values
  1229. */
  1230. if (col.ColumnName.ToString() == "ROUTINE_NAME" && row[col].ToString() == "mono")
  1231. {
  1232. flag = true;
  1233. break;
  1234. }
  1235. }
  1236. if (flag)
  1237. break;
  1238. }
  1239. Assert.AreEqual(false, flag, "#GS24 failed");
  1240. }
  1241. [Test]
  1242. [ExpectedException (typeof (ArgumentException))]
  1243. public void GetSchemaTest25 ()
  1244. {
  1245. String [] restrictions = new String [1];
  1246. conn.GetSchema ("Mono", restrictions);
  1247. }
  1248. }
  1249. }