DbDataAdapterTest.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. //
  2. // DbDataAdapterTest.cs - NUnit Test Cases for testing the DbDataAdapter class
  3. //
  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.Common;
  31. using System.Data.SqlClient;
  32. using NUnit.Framework;
  33. namespace MonoTests.System.Data.Common
  34. {
  35. [TestFixture]
  36. public class DbDataAdapterTest
  37. {
  38. #if NET_2_0
  39. [Test]
  40. public void UpdateBatchSize ()
  41. {
  42. MyAdapter da = new MyAdapter ();
  43. try {
  44. da.UpdateBatchSize = 0;
  45. Assert.Fail ("#A1");
  46. } catch (NotSupportedException ex) {
  47. // Specified method is not supported
  48. Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#A2");
  49. Assert.IsNull (ex.InnerException, "#A3");
  50. Assert.IsNotNull (ex.Message, "#A4");
  51. }
  52. Assert.AreEqual (1, da.UpdateBatchSize, "#A5");
  53. try {
  54. da.UpdateBatchSize = int.MaxValue;
  55. Assert.Fail ("#B1");
  56. } catch (NotSupportedException ex) {
  57. // Specified method is not supported
  58. Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#B2");
  59. Assert.IsNull (ex.InnerException, "#B3");
  60. Assert.IsNotNull (ex.Message, "#B4");
  61. }
  62. Assert.AreEqual (1, da.UpdateBatchSize, "#B5");
  63. da.UpdateBatchSize = 1;
  64. Assert.AreEqual (1, da.UpdateBatchSize, "#C");
  65. }
  66. [Test]
  67. public void UpdateBatchSize_Negative ()
  68. {
  69. MyAdapter da = new MyAdapter ();
  70. try {
  71. da.UpdateBatchSize = -1;
  72. Assert.Fail ("#1");
  73. } catch (NotSupportedException ex) {
  74. // Specified method is not supported
  75. Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
  76. Assert.IsNull (ex.InnerException, "#3");
  77. Assert.IsNotNull (ex.Message, "#4");
  78. }
  79. }
  80. [Test]
  81. public void AddToBatch ()
  82. {
  83. MyAdapter da = new MyAdapter ();
  84. try {
  85. da.AddToBatch (new SqlCommand ());
  86. Assert.Fail ("#1");
  87. } catch (NotSupportedException ex) {
  88. Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
  89. Assert.IsNull (ex.InnerException, "#3");
  90. Assert.IsNotNull (ex.Message, "#4");
  91. }
  92. }
  93. [Test]
  94. public void ClearBatch ()
  95. {
  96. MyAdapter da = new MyAdapter ();
  97. try {
  98. da.ClearBatch ();
  99. Assert.Fail ("#1");
  100. } catch (NotSupportedException ex) {
  101. Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
  102. Assert.IsNull (ex.InnerException, "#3");
  103. Assert.IsNotNull (ex.Message, "#4");
  104. }
  105. }
  106. [Test]
  107. public void ExecuteBatch ()
  108. {
  109. MyAdapter da = new MyAdapter ();
  110. try {
  111. da.ExecuteBatch ();
  112. Assert.Fail ("#1");
  113. } catch (NotSupportedException ex) {
  114. Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
  115. Assert.IsNull (ex.InnerException, "#3");
  116. Assert.IsNotNull (ex.Message, "#4");
  117. }
  118. }
  119. [Test]
  120. public void GetBatchedParameter ()
  121. {
  122. MyAdapter da = new MyAdapter ();
  123. try {
  124. da.GetBatchedParameter (1, 1);
  125. Assert.Fail ("#1");
  126. } catch (NotSupportedException ex) {
  127. Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
  128. Assert.IsNull (ex.InnerException, "#3");
  129. Assert.IsNotNull (ex.Message, "#4");
  130. }
  131. }
  132. [Test]
  133. public void GetBatchedRecordsAffected ()
  134. {
  135. MyAdapter da = new MyAdapter ();
  136. int recordsAffected = 0;
  137. Exception error = null;
  138. Assert.IsTrue (da. GetBatchedRecordsAffected (int.MinValue,
  139. out recordsAffected, out error), "#1");
  140. Assert.AreEqual (1, recordsAffected, "#2");
  141. Assert.IsNull (error, "#3");
  142. }
  143. [Test]
  144. public void InitializeBatching ()
  145. {
  146. MyAdapter da = new MyAdapter ();
  147. try {
  148. da.InitializeBatching ();
  149. Assert.Fail ("#1");
  150. } catch (NotSupportedException ex) {
  151. Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
  152. Assert.IsNull (ex.InnerException, "#3");
  153. Assert.IsNotNull (ex.Message, "#4");
  154. }
  155. }
  156. [Test]
  157. public void TerminateBatching ()
  158. {
  159. MyAdapter da = new MyAdapter ();
  160. try {
  161. da.TerminateBatching ();
  162. Assert.Fail ("#1");
  163. } catch (NotSupportedException ex) {
  164. Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
  165. Assert.IsNull (ex.InnerException, "#3");
  166. Assert.IsNotNull (ex.Message, "#4");
  167. }
  168. }
  169. #endif
  170. class MyAdapter : DbDataAdapter
  171. {
  172. #if ONLY_1_1
  173. protected override RowUpdatedEventArgs CreateRowUpdatedEvent (DataRow dataRow, IDbCommand command,
  174. StatementType statementType,
  175. DataTableMapping tableMapping)
  176. {
  177. throw new NotImplementedException ();
  178. }
  179. protected override RowUpdatingEventArgs CreateRowUpdatingEvent (DataRow dataRow, IDbCommand command,
  180. StatementType statementType,
  181. DataTableMapping tableMapping)
  182. {
  183. throw new NotImplementedException ();
  184. }
  185. protected override void OnRowUpdated (RowUpdatedEventArgs value)
  186. {
  187. throw new NotImplementedException ();
  188. }
  189. protected override void OnRowUpdating (RowUpdatingEventArgs value)
  190. {
  191. throw new NotImplementedException ();
  192. }
  193. #endif
  194. #if NET_2_0
  195. public new int AddToBatch (IDbCommand command)
  196. {
  197. return base.AddToBatch (command);
  198. }
  199. public new void ClearBatch ()
  200. {
  201. base.ClearBatch ();
  202. }
  203. public new void ExecuteBatch ()
  204. {
  205. base.ClearBatch ();
  206. }
  207. public new IDataParameter GetBatchedParameter (int commandIdentifier, int parameterIndex)
  208. {
  209. return base.GetBatchedParameter (commandIdentifier, parameterIndex);
  210. }
  211. public new bool GetBatchedRecordsAffected (int commandIdentifier, out int recordsAffected, out Exception error)
  212. {
  213. return base.GetBatchedRecordsAffected (commandIdentifier, out recordsAffected, out error);
  214. }
  215. public new void InitializeBatching ()
  216. {
  217. base.InitializeBatching ();
  218. }
  219. public new void TerminateBatching ()
  220. {
  221. base.TerminateBatching ();
  222. }
  223. #endif
  224. }
  225. }
  226. }