OleDbDataAdapter_Dispose.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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.OleDb ;
  26. using MonoTests.System.Data.Utils;
  27. using NUnit.Framework;
  28. namespace MonoTests.System.Data.OleDb
  29. {
  30. [TestFixture]
  31. public class OleDbDataAdapter_Dispose : GHTBase
  32. {
  33. public static void Main()
  34. {
  35. OleDbDataAdapter_Dispose tc = new OleDbDataAdapter_Dispose();
  36. Exception exp = null;
  37. try
  38. {
  39. tc.BeginTest("OleDbDataAdapter_Dispose");
  40. tc.run();
  41. }
  42. catch(Exception ex)
  43. {
  44. exp = ex;
  45. }
  46. finally
  47. {
  48. tc.EndTest(exp);
  49. }
  50. }
  51. //public TestClass():base(true){}
  52. //Activate this constructor to log Failures to a log file
  53. //public TestClass(System.IO.TextWriter tw):base(tw, false){}
  54. //Activate this constructor to log All to a log file
  55. //public TestClass(System.IO.TextWriter tw):base(tw, true){}
  56. //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
  57. [Test]
  58. public void run()
  59. {
  60. Exception exp = null;
  61. DataSet ds = new DataSet();
  62. string sqlSelect = "Select * from Customers where CustomerID = 'ABC'";
  63. OleDbConnection con = new OleDbConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  64. OleDbCommand cmdSelect = new OleDbCommand(sqlSelect,con);
  65. OleDbCommand cmdDelete = new OleDbCommand("",con);
  66. OleDbCommand cmdUpdate = new OleDbCommand("",con);
  67. OleDbCommand cmdInsert = null;
  68. con.Open();
  69. OleDbDataAdapter da = new OleDbDataAdapter(cmdSelect);
  70. da.DeleteCommand = cmdDelete;
  71. da.UpdateCommand = cmdUpdate;
  72. da.InsertCommand = new OleDbCommand("",con);
  73. cmdInsert = da.InsertCommand;
  74. da.Fill(ds);
  75. try
  76. {
  77. BeginCase("Dispose - check DataAdapter select command");
  78. da.Dispose();
  79. Compare(da.SelectCommand == null, true);
  80. }
  81. catch(Exception ex){exp = ex;}
  82. finally{EndCase(exp);exp = null;}
  83. try
  84. {
  85. BeginCase("Dispose - check DataAdapter insert command");
  86. Compare(da.InsertCommand == null, true);
  87. }
  88. catch(Exception ex){exp = ex;}
  89. finally{EndCase(exp);exp = null;}
  90. try
  91. {
  92. BeginCase("Dispose - check DataAdapter Delete Command");
  93. Compare(da.DeleteCommand == null, true);
  94. }
  95. catch(Exception ex){exp = ex;}
  96. finally{EndCase(exp);exp = null;}
  97. try
  98. {
  99. BeginCase("Dispose - check DataAdapter update command");
  100. Compare(da.UpdateCommand == null, true);
  101. }
  102. catch(Exception ex){exp = ex;}
  103. finally{EndCase(exp);exp = null;}
  104. try
  105. {
  106. BeginCase("Dispose - check select command object");
  107. Compare(cmdSelect != null, true);
  108. }
  109. catch(Exception ex){exp = ex;}
  110. finally{EndCase(exp);exp = null;}
  111. try
  112. {
  113. BeginCase("Dispose - check delete command object");
  114. Compare(cmdDelete != null, true);
  115. }
  116. catch(Exception ex){exp = ex;}
  117. finally{EndCase(exp);exp = null;}
  118. try
  119. {
  120. BeginCase("Dispose - check insert command object");
  121. Compare(cmdInsert != null, true);
  122. }
  123. catch(Exception ex){exp = ex;}
  124. finally{EndCase(exp);exp = null;}
  125. try
  126. {
  127. BeginCase("Dispose - check Update command object");
  128. Compare(cmdUpdate != null, true);
  129. }
  130. catch(Exception ex){exp = ex;}
  131. finally{EndCase(exp);exp = null;}
  132. try
  133. {
  134. BeginCase("Dispose - check cmdSelect.connection object");
  135. Compare(cmdSelect.Connection != null ,true);
  136. }
  137. catch(Exception ex){exp = ex;}
  138. finally{EndCase(exp);exp = null;}
  139. try
  140. {
  141. BeginCase("Dispose - check cmdDelete.connection object");
  142. Compare(cmdDelete.Connection != null ,true);
  143. }
  144. catch(Exception ex){exp = ex;}
  145. finally{EndCase(exp);exp = null;}
  146. try
  147. {
  148. BeginCase("Dispose - check cmdUpdate.connection object");
  149. Compare(cmdUpdate.Connection != null ,true);
  150. }
  151. catch(Exception ex){exp = ex;}
  152. finally{EndCase(exp);exp = null;}
  153. try
  154. {
  155. BeginCase("Dispose - check cmdInsert.connection object");
  156. Compare(cmdInsert.Connection != null ,true);
  157. }
  158. catch(Exception ex){exp = ex;}
  159. finally{EndCase(exp);exp = null;}
  160. try
  161. {
  162. BeginCase("Dispose - check command connection state");
  163. da.Dispose();
  164. Compare(cmdSelect.Connection.State ,ConnectionState.Open);
  165. }
  166. catch(Exception ex){exp = ex;}
  167. finally{EndCase(exp);exp = null;}
  168. }
  169. }
  170. }