OracleCommandBuilder_DeriveParameters_O.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 OracleCommandBuilder_DeriveParameters_O : GHTBase
  32. {
  33. OracleConnection con;
  34. OracleCommand cmd;
  35. Exception exp = null;
  36. [SetUp]
  37. public void SetUp()
  38. {
  39. exp=null;
  40. BeginCase("Setup");
  41. try
  42. {
  43. con = new OracleConnection(ConnectedDataProvider.ConnectionString);
  44. con.Open();
  45. cmd = new OracleCommand("", con);
  46. Compare("Setup", "Setup");
  47. }
  48. catch(Exception ex) {exp = ex;}
  49. finally {EndCase(exp); exp = null;}
  50. }
  51. [TearDown]
  52. public void TearDown()
  53. {
  54. if (con != null)
  55. {
  56. if (con.State == ConnectionState.Open) con.Close();
  57. }
  58. }
  59. public static void Main()
  60. {
  61. OracleCommandBuilder_DeriveParameters_O tc = new OracleCommandBuilder_DeriveParameters_O();
  62. try
  63. {
  64. tc.BeginTest("OracleCommandBuilder_DeriveParameters_O");
  65. tc.SetUp();
  66. tc.run();
  67. tc.TearDown();
  68. }
  69. catch(Exception ex)
  70. {
  71. tc.exp = ex;
  72. }
  73. finally
  74. {
  75. tc.EndTest(tc.exp);
  76. }
  77. }
  78. public void run()
  79. {
  80. RetrieveParameters();
  81. }
  82. [Test]
  83. public void RetrieveParameters()
  84. {
  85. exp = null;
  86. try
  87. {
  88. BeginCase("retrieve parameters");
  89. if (ConnectedDataProvider.GetDbType(con) == DataBaseServer.DB2)
  90. {
  91. this.Skip("Not Implemented on DB2.");
  92. return;
  93. }
  94. switch (ConnectedDataProvider.GetDbType(con))
  95. {
  96. // case MonoTests.Utils.DataBaseServer.PostgreSQL:
  97. // cmd = new OracleCommand("GH_MULTIRECORDSETS('a','b','c')", con);
  98. // break;
  99. default:
  100. cmd = new OracleCommand("GH_MultiRecordSets", con);
  101. break;
  102. }
  103. cmd.CommandType = CommandType.StoredProcedure;
  104. OracleCommandBuilder.DeriveParameters(cmd);
  105. switch (ConnectedDataProvider.GetDbType(con))
  106. {
  107. case DataBaseServer.SQLServer:
  108. case DataBaseServer.Sybase:
  109. Compare(cmd.Parameters.Count, 1);
  110. Compare(cmd.Parameters[0].Direction, ParameterDirection.ReturnValue);
  111. Compare(cmd.Parameters[0].ParameterName, "RETURN_VALUE");
  112. break;
  113. case DataBaseServer.Oracle:
  114. Compare(cmd.Parameters.Count, 3);
  115. Compare(cmd.Parameters[0].Direction, ParameterDirection.Output);
  116. Compare(cmd.Parameters[1].Direction, ParameterDirection.Output);
  117. Compare(cmd.Parameters[2].Direction, ParameterDirection.Output);
  118. Compare(cmd.Parameters[0].ParameterName, "RCT_EMPLOYEES");
  119. break;
  120. case DataBaseServer.PostgreSQL:
  121. Compare(cmd.Parameters.Count, 1);
  122. Compare(cmd.Parameters[0].Direction, ParameterDirection.ReturnValue);
  123. Compare(cmd.Parameters[0].ParameterName, "returnValue");
  124. break;
  125. default:
  126. throw new ApplicationException(string.Format("GHT: Test not implemented for DB type {0}", ConnectedDataProvider.GetDbType(con)));
  127. }
  128. }
  129. catch(Exception ex)
  130. {
  131. exp = ex;
  132. }
  133. finally
  134. {
  135. EndCase(exp);
  136. exp = null;
  137. }
  138. }
  139. }
  140. }