OracleDataAdapter_Fill_1.cs 5.4 KB

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