OleDbDataAdapter_Fill_1.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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.Text;
  25. using System.Data;
  26. using System.Data.OleDb ;
  27. using MonoTests.System.Data.Utils;
  28. using NUnit.Framework;
  29. namespace MonoTests.System.Data.OleDb
  30. {
  31. [TestFixture]
  32. public class OleDbDataAdapter_Fill_1: ADONetTesterClass
  33. {
  34. // transaction use was add for PostgreSQL
  35. OleDbTransaction tr;
  36. OleDbConnection con;
  37. OleDbCommand cmd;
  38. [SetUp]
  39. public void SetUp()
  40. {
  41. Exception exp = null;
  42. BeginCase("Setup");
  43. try
  44. {
  45. con = new OleDbConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  46. con.Open();
  47. // transaction use was add for PostgreSQL
  48. tr = con.BeginTransaction();
  49. cmd = new OleDbCommand("", con, tr);
  50. // prepare data
  51. base.PrepareDataForTesting(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  52. Compare("Setup" ,"Setup");
  53. }
  54. catch(Exception ex) {exp = ex;}
  55. finally {EndCase(exp); exp = null;}
  56. }
  57. [TearDown]
  58. public void TearDown()
  59. {
  60. // transaction use was add for PostgreSQL
  61. tr.Commit();
  62. if (con != null)
  63. {
  64. if (con.State == ConnectionState.Open) con.Close();
  65. }
  66. }
  67. public static void Main()
  68. {
  69. OleDbDataAdapter_Fill_1 tc = new OleDbDataAdapter_Fill_1();
  70. Exception exp = null;
  71. try
  72. {
  73. // Every Test must begin with BeginTest
  74. tc.BeginTest("OleDbDataAdapter_Fill_1");
  75. tc.SetUp();
  76. tc.run();
  77. tc.TearDown();
  78. }
  79. catch(Exception ex)
  80. {
  81. exp = ex;
  82. }
  83. finally
  84. {
  85. // Every Test must End with EndTest
  86. tc.EndTest(exp);
  87. }
  88. }
  89. [Test]
  90. public void run()
  91. {
  92. Exception exp = null;
  93. #if !JAVA
  94. if (ConnectedDataProvider.GetDbType(con) == DataBaseServer.Oracle)
  95. {
  96. StringBuilder messageBuilder = new StringBuilder();
  97. messageBuilder.Append("Test \"OleDbDataAdapter_Fill_1\" Skipped when running in .NET against Oracle database:\n");
  98. messageBuilder.Append("In .NET there is a bug when calling a SP with multiple REFCURSORS from oracle server, the workaround is to use OracleClient and not OleDb.\n");
  99. messageBuilder.Append("In GH we are not bug complient in this issue, because there is no workaround - We do not support the OracleClient namespace.");
  100. messageBuilder.Append(" (The java run is not skipped).");
  101. Log(messageBuilder.ToString());
  102. return;
  103. }
  104. if (ConnectedDataProvider.GetDbType(con) == DataBaseServer.PostgreSQL)
  105. {
  106. // fail to work on .NET OLEDB
  107. this.Log("Not testing PostgreSQL CommandType.StoredProcedure which return SETOF");
  108. return;
  109. }
  110. #endif
  111. cmd.CommandText = "GH_MULTIRECORDSETS";
  112. cmd.CommandType = CommandType.StoredProcedure;
  113. OleDbDataAdapter da = new OleDbDataAdapter(cmd);
  114. DataSet ds = new DataSet();
  115. //execute the fill command
  116. da.Fill(ds);
  117. try
  118. {
  119. BeginCase("Check table count");
  120. Compare(ds.Tables.Count ,3);
  121. }
  122. catch(Exception ex) {exp = ex;}
  123. finally {EndCase(exp); exp = null;}
  124. try
  125. {
  126. BeginCase("Check table 0 rows count");
  127. Compare(ds.Tables[0].Rows.Count ,2);
  128. }
  129. catch(Exception ex) {exp = ex;}
  130. finally {EndCase(exp); exp = null;}
  131. try
  132. {
  133. BeginCase("Check table 0 Columns count");
  134. Compare(ds.Tables[0].Columns.Count ,2);
  135. }
  136. catch(Exception ex) {exp = ex;}
  137. finally {EndCase(exp); exp = null;}
  138. try
  139. {
  140. BeginCase("Check table 1 rows count");
  141. Compare(ds.Tables[1].Rows.Count ,2);
  142. }
  143. catch(Exception ex) {exp = ex;}
  144. finally {EndCase(exp); exp = null;}
  145. try
  146. {
  147. BeginCase("Check table 1 Columns count");
  148. Compare(ds.Tables[1].Columns.Count ,3);
  149. }
  150. catch(Exception ex) {exp = ex;}
  151. finally {EndCase(exp); exp = null;}
  152. try
  153. {
  154. BeginCase("Check table 2 rows count");
  155. Compare(ds.Tables[2].Rows.Count ,0);
  156. }
  157. catch(Exception ex) {exp = ex;}
  158. finally {EndCase(exp); exp = null;}
  159. try
  160. {
  161. BeginCase("Check table 2 Columns count");
  162. Compare(ds.Tables[2].Columns.Count ,4);
  163. }
  164. catch(Exception ex) {exp = ex;}
  165. finally {EndCase(exp); exp = null;}
  166. }
  167. }
  168. }