SqlDataAdapterTest.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. //
  2. // SqlDataAdapterTest.cs - NUnit Test Cases for testing the
  3. // SqlDataAdapter class
  4. // Author:
  5. // Gert Driesen ([email protected])
  6. //
  7. // Copyright (c) 2007 Gert Driesen
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Data;
  30. using System.Data.Odbc;
  31. using System.Data.SqlClient;
  32. using NUnit.Framework;
  33. namespace MonoTests.System.Data.SqlClient
  34. {
  35. [TestFixture]
  36. public class SqlDataAdapterTest
  37. {
  38. [Test] // SqlDataAdapter ()
  39. public void Constructor1 ()
  40. {
  41. SqlDataAdapter da = new SqlDataAdapter ();
  42. Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
  43. #if NET_2_0
  44. Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
  45. #endif
  46. Assert.IsNull (da.Container, "#3");
  47. Assert.IsFalse (da.ContinueUpdateOnError, "#4");
  48. Assert.IsNull (da.DeleteCommand, "#5");
  49. #if NET_2_0
  50. Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
  51. #endif
  52. Assert.IsNull (da.InsertCommand, "#7");
  53. Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
  54. Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
  55. #if NET_2_0
  56. Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
  57. #endif
  58. Assert.IsNull (da.SelectCommand, "#11");
  59. Assert.IsNull (da.Site, "#12");
  60. Assert.IsNotNull (da.TableMappings, "#13");
  61. Assert.AreEqual (0, da.TableMappings.Count, "#14");
  62. #if NET_2_0
  63. Assert.AreEqual (1, da.UpdateBatchSize, "#15");
  64. #endif
  65. Assert.IsNull (da.UpdateCommand, "#16");
  66. }
  67. [Test] // SqlDataAdapter (SqlCommand)
  68. public void Constructor2 ()
  69. {
  70. SqlCommand cmd = new SqlCommand ();
  71. SqlDataAdapter da = new SqlDataAdapter (cmd);
  72. Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
  73. #if NET_2_0
  74. Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
  75. #endif
  76. Assert.IsNull (da.Container, "#3");
  77. Assert.IsFalse (da.ContinueUpdateOnError, "#4");
  78. Assert.IsNull (da.DeleteCommand, "#5");
  79. #if NET_2_0
  80. Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
  81. #endif
  82. Assert.IsNull (da.InsertCommand, "#7");
  83. Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
  84. Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
  85. #if NET_2_0
  86. Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
  87. #endif
  88. Assert.IsNotNull (da.SelectCommand, "#11");
  89. Assert.AreSame (cmd, da.SelectCommand, "#12");
  90. Assert.IsNull (da.Site, "#13");
  91. Assert.IsNotNull (da.TableMappings, "#14");
  92. Assert.AreEqual (0, da.TableMappings.Count, "#15");
  93. #if NET_2_0
  94. Assert.AreEqual (1, da.UpdateBatchSize, "#16");
  95. #endif
  96. Assert.IsNull (da.UpdateCommand, "#17");
  97. }
  98. [Test] // SqlDataAdapter (SqlCommand)
  99. public void Constructor2_SelectCommand_Null ()
  100. {
  101. SqlDataAdapter da = new SqlDataAdapter ((SqlCommand) null);
  102. Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
  103. #if NET_2_0
  104. Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
  105. #endif
  106. Assert.IsNull (da.Container, "#3");
  107. Assert.IsFalse (da.ContinueUpdateOnError, "#4");
  108. Assert.IsNull (da.DeleteCommand, "#5");
  109. #if NET_2_0
  110. Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
  111. #endif
  112. Assert.IsNull (da.InsertCommand, "#7");
  113. Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
  114. Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
  115. #if NET_2_0
  116. Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
  117. #endif
  118. Assert.IsNull (da.SelectCommand, "#11");
  119. Assert.IsNull (da.Site, "#12");
  120. Assert.IsNotNull (da.TableMappings, "#13");
  121. Assert.AreEqual (0, da.TableMappings.Count, "#14");
  122. #if NET_2_0
  123. Assert.AreEqual (1, da.UpdateBatchSize, "#15");
  124. #endif
  125. Assert.IsNull (da.UpdateCommand, "#16");
  126. }
  127. [Test] // SqlDataAdapter (string, SqlConnection)
  128. public void Constructor3 ()
  129. {
  130. string selectCommandText = "SELECT * FROM Authors";
  131. SqlConnection selectConnection = new SqlConnection ();
  132. SqlDataAdapter da = new SqlDataAdapter (selectCommandText,
  133. selectConnection);
  134. Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
  135. #if NET_2_0
  136. Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
  137. #endif
  138. Assert.IsNull (da.Container, "#3");
  139. Assert.IsFalse (da.ContinueUpdateOnError, "#4");
  140. Assert.IsNull (da.DeleteCommand, "#5");
  141. #if NET_2_0
  142. Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
  143. #endif
  144. Assert.IsNull (da.InsertCommand, "#7");
  145. Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
  146. Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
  147. #if NET_2_0
  148. Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
  149. #endif
  150. Assert.IsNotNull (da.SelectCommand, "#11");
  151. Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
  152. Assert.AreSame (selectConnection, da.SelectCommand.Connection, "#13");
  153. Assert.IsNull (da.Site, "#14");
  154. Assert.IsNotNull (da.TableMappings, "#15");
  155. Assert.AreEqual (0, da.TableMappings.Count, "#16");
  156. #if NET_2_0
  157. Assert.AreEqual (1, da.UpdateBatchSize, "#17");
  158. #endif
  159. Assert.IsNull (da.UpdateCommand, "#18");
  160. }
  161. [Test] // SqlDataAdapter (string, SqlConnection)
  162. public void Constructor3_SelectCommandText_Null ()
  163. {
  164. SqlConnection selectConnection = new SqlConnection ();
  165. SqlDataAdapter da = new SqlDataAdapter ((string) null,
  166. selectConnection);
  167. Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
  168. #if NET_2_0
  169. Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
  170. #endif
  171. Assert.IsNull (da.Container, "#3");
  172. Assert.IsFalse (da.ContinueUpdateOnError, "#4");
  173. Assert.IsNull (da.DeleteCommand, "#5");
  174. #if NET_2_0
  175. Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
  176. #endif
  177. Assert.IsNull (da.InsertCommand, "#7");
  178. Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
  179. Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
  180. #if NET_2_0
  181. Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
  182. #endif
  183. Assert.IsNotNull (da.SelectCommand, "#11");
  184. Assert.IsNotNull (da.SelectCommand.CommandText, "#12");
  185. Assert.AreEqual (string.Empty, da.SelectCommand.CommandText, "#13");
  186. Assert.AreSame (selectConnection, da.SelectCommand.Connection, "#14");
  187. Assert.IsNull (da.Site, "#15");
  188. Assert.IsNotNull (da.TableMappings, "#16");
  189. Assert.AreEqual (0, da.TableMappings.Count, "#17");
  190. #if NET_2_0
  191. Assert.AreEqual (1, da.UpdateBatchSize, "#18");
  192. #endif
  193. Assert.IsNull (da.UpdateCommand, "#19");
  194. }
  195. [Test] // SqlDataAdapter (string, SqlConnection)
  196. public void Constructor3_SelectConnection_Null ()
  197. {
  198. string selectCommandText = "SELECT * FROM Authors";
  199. SqlDataAdapter da = new SqlDataAdapter (selectCommandText,
  200. (SqlConnection) null);
  201. Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
  202. #if NET_2_0
  203. Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
  204. #endif
  205. Assert.IsNull (da.Container, "#3");
  206. Assert.IsFalse (da.ContinueUpdateOnError, "#4");
  207. Assert.IsNull (da.DeleteCommand, "#5");
  208. #if NET_2_0
  209. Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
  210. #endif
  211. Assert.IsNull (da.InsertCommand, "#7");
  212. Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
  213. Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
  214. #if NET_2_0
  215. Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
  216. #endif
  217. Assert.IsNotNull (da.SelectCommand, "#11");
  218. Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
  219. Assert.IsNull (da.SelectCommand.Connection, "#13");
  220. Assert.IsNull (da.Site, "#14");
  221. Assert.IsNotNull (da.TableMappings, "#15");
  222. Assert.AreEqual (0, da.TableMappings.Count, "#16");
  223. #if NET_2_0
  224. Assert.AreEqual (1, da.UpdateBatchSize, "#17");
  225. #endif
  226. Assert.IsNull (da.UpdateCommand, "#18");
  227. }
  228. [Test] // SqlDataAdapter (string, string)]
  229. public void Constructor4 ()
  230. {
  231. string selectCommandText = "SELECT * FROM Authors";
  232. string selectConnectionString = "server=SQLSRV;database=Mono";
  233. SqlDataAdapter da = new SqlDataAdapter (selectCommandText,
  234. selectConnectionString);
  235. Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
  236. #if NET_2_0
  237. Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
  238. #endif
  239. Assert.IsNull (da.Container, "#3");
  240. Assert.IsFalse (da.ContinueUpdateOnError, "#4");
  241. Assert.IsNull (da.DeleteCommand, "#5");
  242. #if NET_2_0
  243. Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
  244. #endif
  245. Assert.IsNull (da.InsertCommand, "#7");
  246. Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
  247. Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
  248. #if NET_2_0
  249. Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
  250. #endif
  251. Assert.IsNotNull (da.SelectCommand, "#11");
  252. Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
  253. Assert.IsNotNull (da.SelectCommand.Connection, "#13");
  254. Assert.AreEqual (selectConnectionString, da.SelectCommand.Connection.ConnectionString, "#14");
  255. Assert.IsNull (da.Site, "#15");
  256. Assert.IsNotNull (da.TableMappings, "#16");
  257. Assert.AreEqual (0, da.TableMappings.Count, "#17");
  258. #if NET_2_0
  259. Assert.AreEqual (1, da.UpdateBatchSize, "#18");
  260. #endif
  261. Assert.IsNull (da.UpdateCommand, "#19");
  262. }
  263. [Test] // SqlDataAdapter (string, string)]
  264. public void Constructor4_SelectCommandText_Null ()
  265. {
  266. string selectConnectionString = "server=SQLSRV;database=Mono";
  267. SqlDataAdapter da = new SqlDataAdapter ((string) null,
  268. selectConnectionString);
  269. Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
  270. #if NET_2_0
  271. Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
  272. #endif
  273. Assert.IsNull (da.Container, "#3");
  274. Assert.IsFalse (da.ContinueUpdateOnError, "#4");
  275. Assert.IsNull (da.DeleteCommand, "#5");
  276. #if NET_2_0
  277. Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
  278. #endif
  279. Assert.IsNull (da.InsertCommand, "#7");
  280. Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
  281. Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
  282. #if NET_2_0
  283. Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
  284. #endif
  285. Assert.IsNotNull (da.SelectCommand, "#11");
  286. Assert.IsNotNull (da.SelectCommand.CommandText, "#12");
  287. Assert.AreEqual (string.Empty, da.SelectCommand.CommandText, "#13");
  288. Assert.IsNotNull (da.SelectCommand.Connection, "#14");
  289. Assert.AreEqual (selectConnectionString, da.SelectCommand.Connection.ConnectionString, "#15");
  290. Assert.IsNull (da.Site, "#16");
  291. Assert.IsNotNull (da.TableMappings, "#17");
  292. Assert.AreEqual (0, da.TableMappings.Count, "#18");
  293. #if NET_2_0
  294. Assert.AreEqual (1, da.UpdateBatchSize, "#19");
  295. #endif
  296. Assert.IsNull (da.UpdateCommand, "#20");
  297. }
  298. [Test] // SqlDataAdapter (string, string)]
  299. public void Constructor4_SelectConnectionString_Null ()
  300. {
  301. string selectCommandText = "SELECT * FROM Authors";
  302. SqlDataAdapter da = new SqlDataAdapter (selectCommandText,
  303. (string) null);
  304. Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
  305. #if NET_2_0
  306. Assert.IsTrue (da.AcceptChangesDuringUpdate, "#2");
  307. #endif
  308. Assert.IsNull (da.Container, "#3");
  309. Assert.IsFalse (da.ContinueUpdateOnError, "#4");
  310. Assert.IsNull (da.DeleteCommand, "#5");
  311. #if NET_2_0
  312. Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#6");
  313. #endif
  314. Assert.IsNull (da.InsertCommand, "#7");
  315. Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#8");
  316. Assert.AreEqual (MissingSchemaAction.Add, da.MissingSchemaAction, "#9");
  317. #if NET_2_0
  318. Assert.IsFalse (da.ReturnProviderSpecificTypes, "#10");
  319. #endif
  320. Assert.IsNotNull (da.SelectCommand, "#11");
  321. Assert.AreSame (selectCommandText, da.SelectCommand.CommandText, "#12");
  322. Assert.IsNotNull (da.SelectCommand.Connection, "#14");
  323. Assert.AreEqual (string.Empty, da.SelectCommand.Connection.ConnectionString, "#15");
  324. Assert.IsNull (da.Site, "#16");
  325. Assert.IsNotNull (da.TableMappings, "#17");
  326. Assert.AreEqual (0, da.TableMappings.Count, "#18");
  327. #if NET_2_0
  328. Assert.AreEqual (1, da.UpdateBatchSize, "#19");
  329. #endif
  330. Assert.IsNull (da.UpdateCommand, "#20");
  331. }
  332. [Test]
  333. public void DeleteCommand ()
  334. {
  335. SqlDataAdapter da = new SqlDataAdapter ();
  336. SqlCommand cmd1 = new SqlCommand ();
  337. SqlCommand cmd2 = new SqlCommand ();
  338. da.DeleteCommand = cmd1;
  339. Assert.AreSame (cmd1, da.DeleteCommand, "#1");
  340. da.DeleteCommand = cmd2;
  341. Assert.AreSame (cmd2, da.DeleteCommand, "#2");
  342. da.DeleteCommand = null;
  343. Assert.IsNull (da.DeleteCommand, "#3");
  344. }
  345. [Test]
  346. public void DeleteCommand_IDbDataAdapter ()
  347. {
  348. IDbDataAdapter da = new SqlDataAdapter ();
  349. SqlCommand cmd1 = new SqlCommand ();
  350. SqlCommand cmd2 = new SqlCommand ();
  351. da.DeleteCommand = cmd1;
  352. Assert.AreSame (cmd1, da.DeleteCommand, "#A1");
  353. da.DeleteCommand = cmd2;
  354. Assert.AreSame (cmd2, da.DeleteCommand, "#A2");
  355. da.DeleteCommand = null;
  356. Assert.IsNull (da.DeleteCommand, "#A3");
  357. try {
  358. da.DeleteCommand = new OdbcCommand ();
  359. Assert.Fail ("#B1");
  360. } catch (InvalidCastException ex) {
  361. Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
  362. Assert.IsNull (ex.InnerException, "#B3");
  363. Assert.IsNotNull (ex.Message, "#B4");
  364. }
  365. }
  366. [Test]
  367. public void Dispose ()
  368. {
  369. SqlDataAdapter da = new SqlDataAdapter ();
  370. da.DeleteCommand = new SqlCommand ();
  371. da.InsertCommand = new SqlCommand ();
  372. da.SelectCommand = new SqlCommand ();
  373. da.UpdateCommand = new SqlCommand ();
  374. da.Dispose ();
  375. Assert.IsNull (da.DeleteCommand, "#1");
  376. Assert.IsNull (da.InsertCommand, "#2");
  377. Assert.IsNull (da.SelectCommand, "#3");
  378. Assert.IsNotNull (da.TableMappings, "#4");
  379. Assert.AreEqual (0, da.TableMappings.Count, "#5");
  380. Assert.IsNull (da.UpdateCommand, "#6");
  381. }
  382. [Test]
  383. public void InsertCommand ()
  384. {
  385. SqlDataAdapter da = new SqlDataAdapter ();
  386. SqlCommand cmd1 = new SqlCommand ();
  387. SqlCommand cmd2 = new SqlCommand ();
  388. da.InsertCommand = cmd1;
  389. Assert.AreSame (cmd1, da.InsertCommand, "#1");
  390. da.InsertCommand = cmd2;
  391. Assert.AreSame (cmd2, da.InsertCommand, "#2");
  392. da.InsertCommand = null;
  393. Assert.IsNull (da.InsertCommand, "#3");
  394. }
  395. [Test]
  396. public void InsertCommand_IDbDataAdapter ()
  397. {
  398. IDbDataAdapter da = new SqlDataAdapter ();
  399. SqlCommand cmd1 = new SqlCommand ();
  400. SqlCommand cmd2 = new SqlCommand ();
  401. da.InsertCommand = cmd1;
  402. Assert.AreSame (cmd1, da.InsertCommand, "#A1");
  403. da.InsertCommand = cmd2;
  404. Assert.AreSame (cmd2, da.InsertCommand, "#A2");
  405. da.InsertCommand = null;
  406. Assert.IsNull (da.InsertCommand, "#A3");
  407. try {
  408. da.InsertCommand = new OdbcCommand ();
  409. Assert.Fail ("#B1");
  410. } catch (InvalidCastException ex) {
  411. Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
  412. Assert.IsNull (ex.InnerException, "#B3");
  413. Assert.IsNotNull (ex.Message, "#B4");
  414. }
  415. }
  416. [Test]
  417. public void SelectCommand ()
  418. {
  419. SqlDataAdapter da = new SqlDataAdapter ();
  420. SqlCommand cmd1 = new SqlCommand ();
  421. SqlCommand cmd2 = new SqlCommand ();
  422. da.SelectCommand = cmd1;
  423. Assert.AreSame (cmd1, da.SelectCommand, "#1");
  424. da.SelectCommand = cmd2;
  425. Assert.AreSame (cmd2, da.SelectCommand, "#2");
  426. da.SelectCommand = null;
  427. Assert.IsNull (da.SelectCommand, "#3");
  428. }
  429. [Test]
  430. public void SelectCommand_IDbDataAdapter ()
  431. {
  432. IDbDataAdapter da = new SqlDataAdapter ();
  433. SqlCommand cmd1 = new SqlCommand ();
  434. SqlCommand cmd2 = new SqlCommand ();
  435. da.SelectCommand = cmd1;
  436. Assert.AreSame (cmd1, da.SelectCommand, "#A1");
  437. da.SelectCommand = cmd2;
  438. Assert.AreSame (cmd2, da.SelectCommand, "#A2");
  439. da.SelectCommand = null;
  440. Assert.IsNull (da.SelectCommand, "#A3");
  441. try {
  442. da.SelectCommand = new OdbcCommand ();
  443. Assert.Fail ("#B1");
  444. } catch (InvalidCastException ex) {
  445. Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
  446. Assert.IsNull (ex.InnerException, "#B3");
  447. Assert.IsNotNull (ex.Message, "#B4");
  448. }
  449. }
  450. #if NET_2_0
  451. [Test]
  452. public void UpdateBatchSize ()
  453. {
  454. SqlDataAdapter da = new SqlDataAdapter ();
  455. da.UpdateBatchSize = 0;
  456. Assert.AreEqual (0, da.UpdateBatchSize, "#1");
  457. da.UpdateBatchSize = int.MaxValue;
  458. Assert.AreEqual (int.MaxValue, da.UpdateBatchSize, "#2");
  459. da.UpdateBatchSize = 1;
  460. Assert.AreEqual (1, da.UpdateBatchSize, "#3");
  461. }
  462. [Test]
  463. public void UpdateBatchSize_Negative ()
  464. {
  465. SqlDataAdapter da = new SqlDataAdapter ();
  466. try {
  467. da.UpdateBatchSize = -1;
  468. Assert.Fail ("#1");
  469. } catch (ArgumentOutOfRangeException ex) {
  470. Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
  471. Assert.IsNull (ex.InnerException, "#3");
  472. Assert.IsNotNull (ex.Message, "#4");
  473. Assert.IsNotNull (ex.ParamName, "#5");
  474. Assert.AreEqual ("UpdateBatchSize", ex.ParamName, "#6");
  475. }
  476. }
  477. #endif
  478. [Test]
  479. public void UpdateCommand ()
  480. {
  481. SqlDataAdapter da = new SqlDataAdapter ();
  482. SqlCommand cmd1 = new SqlCommand ();
  483. SqlCommand cmd2 = new SqlCommand ();
  484. da.UpdateCommand = cmd1;
  485. Assert.AreSame (cmd1, da.UpdateCommand, "#1");
  486. da.UpdateCommand = cmd2;
  487. Assert.AreSame (cmd2, da.UpdateCommand, "#2");
  488. da.UpdateCommand = null;
  489. Assert.IsNull (da.UpdateCommand, "#3");
  490. }
  491. [Test]
  492. public void UpdateCommand_IDbDataAdapter ()
  493. {
  494. IDbDataAdapter da = new SqlDataAdapter ();
  495. SqlCommand cmd1 = new SqlCommand ();
  496. SqlCommand cmd2 = new SqlCommand ();
  497. da.UpdateCommand = cmd1;
  498. Assert.AreSame (cmd1, da.UpdateCommand, "#A1");
  499. da.UpdateCommand = cmd2;
  500. Assert.AreSame (cmd2, da.UpdateCommand, "#A2");
  501. da.UpdateCommand = null;
  502. Assert.IsNull (da.UpdateCommand, "#A3");
  503. try {
  504. da.UpdateCommand = new OdbcCommand ();
  505. Assert.Fail ("#B1");
  506. } catch (InvalidCastException ex) {
  507. Assert.AreEqual (typeof (InvalidCastException), ex.GetType (), "#B2");
  508. Assert.IsNull (ex.InnerException, "#B3");
  509. Assert.IsNotNull (ex.Message, "#B4");
  510. }
  511. }
  512. }
  513. }