OracleCommand_ExecuteScalar.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 OracleCommand_ExecuteScalar : GHTBase
  32. {
  33. OracleConnection con;
  34. OracleCommand cmd;
  35. [SetUp]
  36. public void SetUp()
  37. {
  38. Exception exp = null;
  39. BeginCase("Setup");
  40. try
  41. {
  42. con = new OracleConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  43. con.Open();
  44. //prepare Data
  45. OracleCommand cmdPrepare = new OracleCommand("", con);
  46. cmdPrepare.CommandText = "DELETE FROM Employees WHERE EmployeeID = 99999";
  47. cmdPrepare.ExecuteNonQuery();
  48. cmdPrepare.CommandText = "INSERT INTO Employees (EmployeeID, FirstName, LastName) VALUES (99999,'OferXYZ', 'Testing')";
  49. cmdPrepare.ExecuteNonQuery();
  50. cmdPrepare.Dispose();
  51. cmd = new OracleCommand("", con);
  52. }
  53. catch(Exception ex) {exp = ex;}
  54. finally {EndCase(exp); exp = null;}
  55. }
  56. [TearDown]
  57. public void TearDown()
  58. {
  59. if (con != null)
  60. {
  61. if (con.State == ConnectionState.Open) con.Close();
  62. }
  63. }
  64. public static void Main()
  65. {
  66. OracleCommand_ExecuteScalar tc = new OracleCommand_ExecuteScalar();
  67. Exception exp = null;
  68. try
  69. {
  70. tc.BeginTest("OracleCommand_ExecuteScalar");
  71. tc.SetUp();
  72. tc.run();
  73. tc.TearDown();
  74. }
  75. catch(Exception ex){exp = ex;}
  76. finally {tc.EndTest(exp);}
  77. }
  78. [Test]
  79. public void run()
  80. {
  81. Exception exp = null;
  82. object objResult = null;
  83. cmd.CommandText="Select FirstName,City From Employees Where EmployeeID=-1";
  84. try
  85. {
  86. BeginCase("Execute Scalar");
  87. objResult = cmd.ExecuteScalar();
  88. Compare(objResult==null,true);
  89. }
  90. catch(Exception ex){exp = ex;}
  91. finally{EndCase(exp); exp = null;}
  92. cmd.CommandText="Select FirstName,City From Employees Where EmployeeID=99999 ";
  93. try
  94. {
  95. BeginCase("Execute Scalar");
  96. objResult = cmd.ExecuteScalar();
  97. Compare(objResult.ToString(), "OferXYZ");
  98. }
  99. catch(Exception ex){exp = ex;}
  100. finally{EndCase(exp); exp = null;}
  101. try
  102. {
  103. BeginCase("Execute Scalar again");
  104. objResult = cmd.ExecuteScalar();
  105. Compare(objResult.ToString(), "OferXYZ");
  106. }
  107. catch(Exception ex){exp = ex;}
  108. finally{EndCase(exp); exp = null;}
  109. }
  110. }
  111. }