DataAdapterTest.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. [Test]
  51. public void AcceptChangesDuringUpdate ()
  52. {
  53. DataAdapter da = new MyAdapter ();
  54. da.AcceptChangesDuringUpdate = true;
  55. Assert.IsTrue (da.AcceptChangesDuringUpdate, "#1");
  56. da.AcceptChangesDuringUpdate = false;
  57. Assert.IsFalse (da.AcceptChangesDuringUpdate, "#2");
  58. da.AcceptChangesDuringUpdate = true;
  59. Assert.IsTrue (da.AcceptChangesDuringUpdate, "#3");
  60. }
  61. [Test]
  62. public void ContinueUpdateOnError ()
  63. {
  64. DataAdapter da = new MyAdapter ();
  65. da.ContinueUpdateOnError = true;
  66. Assert.IsTrue (da.ContinueUpdateOnError, "#1");
  67. da.ContinueUpdateOnError = false;
  68. Assert.IsFalse (da.ContinueUpdateOnError, "#2");
  69. da.ContinueUpdateOnError = true;
  70. Assert.IsTrue (da.ContinueUpdateOnError, "#3");
  71. }
  72. [Test]
  73. public void Fill_Direct ()
  74. {
  75. DataAdapter da = new MyAdapter ();
  76. DataSet ds = new DataSet ();
  77. try {
  78. da.Fill (ds);
  79. Assert.Fail ("#1");
  80. } catch (NotSupportedException ex) {
  81. // Specified method is not supported
  82. Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
  83. Assert.IsNull (ex.InnerException, "#3");
  84. Assert.IsNotNull (ex.Message, "#4");
  85. }
  86. }
  87. [Test]
  88. public void FillLoadOption ()
  89. {
  90. DataAdapter da = new MyAdapter ();
  91. da.FillLoadOption = LoadOption.PreserveChanges;
  92. Assert.AreEqual (LoadOption.PreserveChanges, da.FillLoadOption, "#1");
  93. da.FillLoadOption = LoadOption.OverwriteChanges;
  94. Assert.AreEqual (LoadOption.OverwriteChanges, da.FillLoadOption, "#2");
  95. da.FillLoadOption = LoadOption.Upsert;
  96. Assert.AreEqual (LoadOption.Upsert, da.FillLoadOption, "#3");
  97. }
  98. [Test]
  99. public void FillLoadOption_Invalid ()
  100. {
  101. DataAdapter da = new MyAdapter ();
  102. try {
  103. da.FillLoadOption = (LoadOption) 666;
  104. Assert.Fail ("#1");
  105. } catch (ArgumentOutOfRangeException ex) {
  106. // The LoadOption enumeration value, 666, is invalid
  107. Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
  108. Assert.IsNull (ex.InnerException, "#3");
  109. Assert.IsNotNull (ex.Message, "#4");
  110. Assert.IsTrue (ex.Message.IndexOf ("LoadOption") != -1, "#5");
  111. Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6");
  112. Assert.IsNotNull (ex.ParamName, "#7");
  113. Assert.AreEqual ("LoadOption", ex.ParamName, "#8");
  114. }
  115. }
  116. [Test]
  117. public void MissingMappingAction_Valid ()
  118. {
  119. DataAdapter da = new MyAdapter ();
  120. da.MissingMappingAction = MissingMappingAction.Passthrough;
  121. Assert.AreEqual (MissingMappingAction.Passthrough, da.MissingMappingAction, "#1");
  122. da.MissingMappingAction = MissingMappingAction.Ignore;
  123. Assert.AreEqual (MissingMappingAction.Ignore, da.MissingMappingAction, "#2");
  124. da.MissingMappingAction = MissingMappingAction.Error;
  125. Assert.AreEqual (MissingMappingAction.Error, da.MissingMappingAction, "#3");
  126. }
  127. [Test]
  128. public void MissingMappingAction_Invalid ()
  129. {
  130. DataAdapter da = new MyAdapter ();
  131. try {
  132. da.MissingMappingAction = (MissingMappingAction) 666;
  133. Assert.Fail ("#1");
  134. } catch (ArgumentOutOfRangeException ex) {
  135. // The MissingMappingAction enumeration value, 666, is invalid
  136. Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
  137. Assert.IsNull (ex.InnerException, "#3");
  138. Assert.IsNotNull (ex.Message, "#4");
  139. Assert.IsTrue (ex.Message.IndexOf ("MissingMappingAction") != -1, "#5");
  140. Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6");
  141. Assert.IsNotNull (ex.ParamName, "#7");
  142. Assert.AreEqual ("MissingMappingAction", ex.ParamName, "#8");
  143. }
  144. }
  145. [Test]
  146. public void MissingSchemaAction_Valid ()
  147. {
  148. DataAdapter da = new MyAdapter ();
  149. da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
  150. Assert.AreEqual (MissingSchemaAction.AddWithKey, da.MissingSchemaAction, "#1");
  151. da.MissingSchemaAction = MissingSchemaAction.Ignore;
  152. Assert.AreEqual (MissingSchemaAction.Ignore, da.MissingSchemaAction, "#2");
  153. da.MissingSchemaAction = MissingSchemaAction.Error;
  154. Assert.AreEqual (MissingSchemaAction.Error, da.MissingSchemaAction, "#3");
  155. }
  156. [Test]
  157. public void MissingSchemaAction_Invalid ()
  158. {
  159. DataAdapter da = new MyAdapter ();
  160. try {
  161. da.MissingSchemaAction = (MissingSchemaAction) 666;
  162. Assert.Fail ("#1");
  163. } catch (ArgumentOutOfRangeException ex) {
  164. // The MissingSchemaAction enumeration value, 666, is invalid
  165. Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
  166. Assert.IsNull (ex.InnerException, "#3");
  167. Assert.IsNotNull (ex.Message, "#4");
  168. Assert.IsTrue (ex.Message.IndexOf ("MissingSchemaAction") != -1, "#5");
  169. Assert.IsTrue (ex.Message.IndexOf ("666") != -1, "#6");
  170. Assert.IsNotNull (ex.ParamName, "#7");
  171. Assert.AreEqual ("MissingSchemaAction", ex.ParamName, "#8");
  172. }
  173. }
  174. [Test]
  175. public void ReturnProviderSpecificTypes ()
  176. {
  177. DataAdapter da = new MyAdapter ();
  178. da.ReturnProviderSpecificTypes = true;
  179. Assert.IsTrue (da.ReturnProviderSpecificTypes, "#1");
  180. da.ReturnProviderSpecificTypes = false;
  181. Assert.IsFalse (da.ReturnProviderSpecificTypes, "#2");
  182. da.ReturnProviderSpecificTypes = true;
  183. Assert.IsTrue (da.ReturnProviderSpecificTypes, "#3");
  184. }
  185. }
  186. class MyAdapter : DataAdapter
  187. {
  188. }
  189. }