DataAdapterTest.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. //
  2. // DataAdapterTest.cs - NUnit Test Cases for testing the DataAdapter class
  3. //
  4. // Author:
  5. // Miguel de Icaza ([email protected])
  6. // Gert Driesen ([email protected])
  7. //
  8. // Copyright (c) 2006 Novell Inc., and the individuals listed
  9. // on the ChangeLog entries.
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System;
  31. using System.Data;
  32. using System.Data.Common;
  33. using NUnit.Framework;
  34. namespace MonoTests.System.Data.Common
  35. {
  36. [TestFixture]
  37. public class DataAdapterTest
  38. {
  39. [Test]
  40. public void AcceptChangesDuringFill ()
  41. {
  42. DataAdapter da = new MyAdapter ();
  43. da.AcceptChangesDuringFill = true;
  44. Assert.IsTrue (da.AcceptChangesDuringFill, "#1");
  45. da.AcceptChangesDuringFill = false;
  46. Assert.IsFalse (da.AcceptChangesDuringFill, "#2");
  47. da.AcceptChangesDuringFill = true;
  48. Assert.IsTrue (da.AcceptChangesDuringFill, "#3");
  49. }
  50. #if NET_2_0
  51. [Test]
  52. public void AcceptChangesDuringUpdate ()
  53. {
  54. DataAdapter da = new MyAdapter ();
  55. da.AcceptChangesDuringUpdate = true;
  56. Assert.IsTrue (da.AcceptChangesDuringUpdate, "#1");
  57. da.AcceptChangesDuringUpdate = false;
  58. Assert.IsFalse (da.AcceptChangesDuringUpdate, "#2");
  59. da.AcceptChangesDuringUpdate = true;
  60. Assert.IsTrue (da.AcceptChangesDuringUpdate, "#3");
  61. }
  62. #endif
  63. [Test]
  64. public void ContinueUpdateOnError ()
  65. {
  66. DataAdapter da = new MyAdapter ();
  67. da.ContinueUpdateOnError = true;
  68. Assert.IsTrue (da.ContinueUpdateOnError, "#1");
  69. da.ContinueUpdateOnError = false;
  70. Assert.IsFalse (da.ContinueUpdateOnError, "#2");
  71. da.ContinueUpdateOnError = true;
  72. Assert.IsTrue (da.ContinueUpdateOnError, "#3");
  73. }
  74. #if NET_2_0
  75. [Test]
  76. public void Fill_Direct ()
  77. {
  78. DataAdapter da = new MyAdapter ();
  79. DataSet ds = new DataSet ();
  80. try {
  81. da.Fill (ds);
  82. Assert.Fail ("#1");
  83. } catch (NotSupportedException ex) {
  84. // Specified method is not supported
  85. Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
  86. Assert.IsNull (ex.InnerException, "#3");
  87. Assert.IsNotNull (ex.Message, "#4");
  88. }
  89. }
  90. [Test]
  91. public void FillLoadOption ()
  92. {
  93. DataAdapter da = new MyAdapter ();
  94. da.FillLoadOption = LoadOption.PreserveChanges;
  95. Assert.AreEqual (LoadOption.PreserveChanges, da.FillLoadOption, "#1");
  96. da.FillLoadOption = LoadOption.OverwriteChanges;
  97. Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#2");
  98. da.FillLoadOption = LoadOption.Upsert;
  99. Assert.AreEqual (LoadOption.Upsert, da.FillLoadOption, "#3");
  100. }
  101. [Test]
  102. public void FillLoadOption_Invalid ()
  103. {
  104. DataAdapter da = new MyAdapter ();
  105. try {
  106. da.FillLoadOption = (LoadOption) 666;
  107. Assert.Fail ("#1");
  108. } catch (ArgumentOutOfRangeException ex) {
  109. // The LoadOption enumeration value, 666, is invalid
  110. Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
  111. Assert.IsNull (ex.InnerException, "#3");
  112. Assert.IsNotNull (ex.Message, "#4");
  113. Assert.IsTrue (ex.Message.IndexOf ("LoadOption") != -1, "#5");
  114. Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6");
  115. Assert.IsNotNull (ex.ParamName, "#7");
  116. Assert.AreEqual ("LoadOption", ex.ParamName, "#8");
  117. }
  118. }
  119. #endif
  120. [Test]
  121. public void MissingMappingAction_Valid ()
  122. {
  123. DataAdapter da = new MyAdapter ();
  124. da.MissingMappingAction = MissingMappingAction.Passthrough;
  125. Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#1");
  126. da.MissingMappingAction = MissingMappingAction.Ignore;
  127. Assert.AreEqual (MissingMappingAction.Ignore, da.MissingMappingAction, "#2");
  128. da.MissingMappingAction = MissingMappingAction.Error;
  129. Assert.AreEqual (MissingMappingAction.Error, da.MissingMappingAction, "#3");
  130. }
  131. [Test]
  132. public void MissingMappingAction_Invalid ()
  133. {
  134. DataAdapter da = new MyAdapter ();
  135. try {
  136. da.MissingMappingAction = (MissingMappingAction) 666;
  137. Assert.Fail ("#1");
  138. #if NET_2_0
  139. } catch (ArgumentOutOfRangeException ex) {
  140. // The MissingMappingAction enumeration value, 666, is invalid
  141. Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
  142. Assert.IsNull (ex.InnerException, "#3");
  143. Assert.IsNotNull (ex.Message, "#4");
  144. Assert.IsTrue (ex.Message.IndexOf ("MissingMappingAction") != -1, "#5");
  145. Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6");
  146. Assert.IsNotNull (ex.ParamName, "#7");
  147. Assert.AreEqual ("MissingMappingAction", ex.ParamName, "#8");
  148. }
  149. #else
  150. } catch (ArgumentException ex) {
  151. // The MissingMappingAction enumeration value, 666, is invalid
  152. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  153. Assert.IsNull (ex.InnerException, "#3");
  154. Assert.IsNotNull (ex.Message, "#4");
  155. Assert.IsTrue (ex.Message.IndexOf ("MissingMappingAction") != -1, "#5");
  156. Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6");
  157. Assert.IsNull (ex.ParamName, "#7");
  158. }
  159. #endif
  160. }
  161. [Test]
  162. public void MissingSchemaAction_Valid ()
  163. {
  164. DataAdapter da = new MyAdapter ();
  165. da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
  166. Assert.AreEqual (MissingSchemaAction.AddWithKey, da.MissingSchemaAction, "#1");
  167. da.MissingSchemaAction = MissingSchemaAction.Ignore;
  168. Assert.AreEqual (MissingSchemaAction.Ignore, da.MissingSchemaAction, "#2");
  169. da.MissingSchemaAction = MissingSchemaAction.Error;
  170. Assert.AreEqual (MissingSchemaAction.Error, da.MissingSchemaAction, "#3");
  171. }
  172. [Test]
  173. public void MissingSchemaAction_Invalid ()
  174. {
  175. DataAdapter da = new MyAdapter ();
  176. try {
  177. da.MissingSchemaAction = (MissingSchemaAction) 666;
  178. Assert.Fail ("#1");
  179. #if NET_2_0
  180. } catch (ArgumentOutOfRangeException ex) {
  181. // The MissingSchemaAction enumeration value, 666, is invalid
  182. Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
  183. Assert.IsNull (ex.InnerException, "#3");
  184. Assert.IsNotNull (ex.Message, "#4");
  185. Assert.IsTrue (ex.Message.IndexOf ("MissingSchemaAction") != -1, "#5");
  186. Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6");
  187. Assert.IsNotNull (ex.ParamName, "#7");
  188. Assert.AreEqual ("MissingSchemaAction", ex.ParamName, "#8");
  189. }
  190. #else
  191. } catch (ArgumentException ex) {
  192. // The MissingSchemaAction enumeration value, 666, is invalid
  193. Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
  194. Assert.IsNull (ex.InnerException, "#3");
  195. Assert.IsNotNull (ex.Message, "#4");
  196. Assert.IsTrue (ex.Message.IndexOf ("MissingSchemaAction") != -1, "#5");
  197. Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6");
  198. Assert.IsNull (ex.ParamName, "#7");
  199. }
  200. #endif
  201. }
  202. #if NET_2_0
  203. [Test]
  204. public void ReturnProviderSpecificTypes ()
  205. {
  206. DataAdapter da = new MyAdapter ();
  207. da.ReturnProviderSpecificTypes = true;
  208. Assert.IsTrue (da.ReturnProviderSpecificTypes, "#1");
  209. da.ReturnProviderSpecificTypes = false;
  210. Assert.IsFalse (da.ReturnProviderSpecificTypes, "#2");
  211. da.ReturnProviderSpecificTypes = true;
  212. Assert.IsTrue (da.ReturnProviderSpecificTypes, "#3");
  213. }
  214. #endif
  215. }
  216. class MyAdapter : DataAdapter
  217. {
  218. #if ONLY_1_1
  219. public override int Fill (DataSet dataSet)
  220. {
  221. throw new NotImplementedException ();
  222. }
  223. public override DataTable[] FillSchema (DataSet dataSet, SchemaType schemaType)
  224. {
  225. throw new NotImplementedException ();
  226. }
  227. public override IDataParameter[] GetFillParameters ()
  228. {
  229. throw new NotImplementedException ();
  230. }
  231. public override int Update (DataSet dataSet)
  232. {
  233. throw new NotImplementedException ();
  234. }
  235. #endif
  236. }
  237. }