OracleDataAdapter_Dispose.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. //
  2. // Copyright (c) 2006 Mainsoft Co.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. using System;
  24. using System.Data;
  25. using System.Data.OracleClient ;
  26. using MonoTests.System.Data.Utils;
  27. using NUnit.Framework;
  28. namespace MonoTests.System.Data.OracleClient
  29. {
  30. [TestFixture]
  31. public class OracleDataAdapter_Dispose : GHTBase
  32. {
  33. OracleConnection con;
  34. OracleCommand cmdSelect;
  35. OracleCommand cmdDelete;
  36. OracleCommand cmdUpdate;
  37. OracleCommand cmdInsert;
  38. [SetUp]
  39. public void SetUp() {
  40. string sqlSelect = "Select * from Customers where CustomerID = 'ABC'";
  41. con = new OracleConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  42. cmdSelect = new OracleCommand(sqlSelect,con);
  43. cmdDelete = new OracleCommand("",con);
  44. cmdUpdate = new OracleCommand("",con);
  45. cmdInsert = null;
  46. con.Open();
  47. }
  48. [TearDown]
  49. public void TearDown() {
  50. if (con.State == ConnectionState.Open) con.Close();
  51. }
  52. public static void Main()
  53. {
  54. OracleDataAdapter_Dispose tc = new OracleDataAdapter_Dispose();
  55. Exception exp = null;
  56. try
  57. {
  58. tc.BeginTest("OracleDataAdapter_Dispose");
  59. tc.SetUp();
  60. tc.run();
  61. tc.TearDown();
  62. }
  63. catch(Exception ex)
  64. {
  65. exp = ex;
  66. }
  67. finally
  68. {
  69. tc.EndTest(exp);
  70. }
  71. }
  72. //public TestClass():base(true){}
  73. //Activate this constructor to log Failures to a log file
  74. //public TestClass(System.IO.TextWriter tw):base(tw, false){}
  75. //Activate this constructor to log All to a log file
  76. //public TestClass(System.IO.TextWriter tw):base(tw, true){}
  77. //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
  78. [Test]
  79. public void run()
  80. {
  81. Exception exp = null;
  82. DataSet ds = new DataSet();
  83. OracleDataAdapter da = new OracleDataAdapter(cmdSelect);
  84. da.DeleteCommand = cmdDelete;
  85. da.UpdateCommand = cmdUpdate;
  86. da.InsertCommand = new OracleCommand("",con);
  87. cmdInsert = da.InsertCommand;
  88. da.Fill(ds);
  89. try
  90. {
  91. BeginCase("Dispose - check DataAdapter select command");
  92. da.Dispose();
  93. Compare(da.SelectCommand == null, true);
  94. }
  95. catch(Exception ex){exp = ex;}
  96. finally{EndCase(exp);exp = null;}
  97. try
  98. {
  99. BeginCase("Dispose - check DataAdapter insert command");
  100. Compare(da.InsertCommand == null, true);
  101. }
  102. catch(Exception ex){exp = ex;}
  103. finally{EndCase(exp);exp = null;}
  104. try
  105. {
  106. BeginCase("Dispose - check DataAdapter Delete Command");
  107. Compare(da.DeleteCommand == null, true);
  108. }
  109. catch(Exception ex){exp = ex;}
  110. finally{EndCase(exp);exp = null;}
  111. try
  112. {
  113. BeginCase("Dispose - check DataAdapter update command");
  114. Compare(da.UpdateCommand == null, true);
  115. }
  116. catch(Exception ex){exp = ex;}
  117. finally{EndCase(exp);exp = null;}
  118. try
  119. {
  120. BeginCase("Dispose - check select command object");
  121. Compare(cmdSelect != null, true);
  122. }
  123. catch(Exception ex){exp = ex;}
  124. finally{EndCase(exp);exp = null;}
  125. try
  126. {
  127. BeginCase("Dispose - check delete command object");
  128. Compare(cmdDelete != null, true);
  129. }
  130. catch(Exception ex){exp = ex;}
  131. finally{EndCase(exp);exp = null;}
  132. try
  133. {
  134. BeginCase("Dispose - check insert command object");
  135. Compare(cmdInsert != null, true);
  136. }
  137. catch(Exception ex){exp = ex;}
  138. finally{EndCase(exp);exp = null;}
  139. try
  140. {
  141. BeginCase("Dispose - check Update command object");
  142. Compare(cmdUpdate != null, true);
  143. }
  144. catch(Exception ex){exp = ex;}
  145. finally{EndCase(exp);exp = null;}
  146. try
  147. {
  148. BeginCase("Dispose - check cmdSelect.connection object");
  149. Compare(cmdSelect.Connection != null ,true);
  150. }
  151. catch(Exception ex){exp = ex;}
  152. finally{EndCase(exp);exp = null;}
  153. try
  154. {
  155. BeginCase("Dispose - check cmdDelete.connection object");
  156. Compare(cmdDelete.Connection != null ,true);
  157. }
  158. catch(Exception ex){exp = ex;}
  159. finally{EndCase(exp);exp = null;}
  160. try
  161. {
  162. BeginCase("Dispose - check cmdUpdate.connection object");
  163. Compare(cmdUpdate.Connection != null ,true);
  164. }
  165. catch(Exception ex){exp = ex;}
  166. finally{EndCase(exp);exp = null;}
  167. try
  168. {
  169. BeginCase("Dispose - check cmdInsert.connection object");
  170. Compare(cmdInsert.Connection != null ,true);
  171. }
  172. catch(Exception ex){exp = ex;}
  173. finally{EndCase(exp);exp = null;}
  174. try
  175. {
  176. BeginCase("Dispose - check command connection state");
  177. da.Dispose();
  178. Compare(cmdSelect.Connection.State ,ConnectionState.Open);
  179. }
  180. catch(Exception ex){exp = ex;}
  181. finally{EndCase(exp);exp = null;}
  182. }
  183. }
  184. }