SqlParameter_Direction.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using System;
  2. using System.Text;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using MonoTests.System.Data.Utils;
  6. using NUnit.Framework;
  7. namespace MonoTests.System.Data.SqlClient
  8. {
  9. [TestFixture]
  10. public class SqlParameter_Direction : GHTBase
  11. {
  12. private Exception exp;
  13. public static void Main()
  14. {
  15. SqlParameter_Direction tc = new SqlParameter_Direction();
  16. tc.exp = null;
  17. tc.TestSetup();
  18. try
  19. {
  20. // Every Test must begin with BeginTest
  21. tc.BeginTest("SqlParameter_Direction");
  22. tc.run();
  23. }
  24. catch(Exception ex)
  25. {
  26. tc.exp = ex;
  27. }
  28. finally
  29. {
  30. tc.EndTest(tc.exp);
  31. tc.TestTearDown();
  32. }
  33. }
  34. public void run()
  35. {
  36. TestBug4703();
  37. }
  38. [TestFixtureSetUp]
  39. public void TestSetup()
  40. {
  41. BeginCase("Test Setup");
  42. SqlConnection con = new SqlConnection(ConnectedDataProvider.ConnectionStringSQLClient);
  43. StringBuilder createTestSpBuilder = new StringBuilder();
  44. createTestSpBuilder.Append("CREATE PROCEDURE dbo.GHSP_DateTimeOutputTest");
  45. createTestSpBuilder.Append("(");
  46. createTestSpBuilder.Append(" @LastRefresh datetime OUTPUT");
  47. createTestSpBuilder.Append(")");
  48. createTestSpBuilder.Append("AS ");
  49. createTestSpBuilder.Append("SET @LastRefresh = GETDATE() ");
  50. createTestSpBuilder.Append("RETURN");
  51. SqlCommand createTestSpCmd = null;
  52. try
  53. {
  54. createTestSpCmd = new SqlCommand(createTestSpBuilder.ToString(), con);
  55. con.Open();
  56. createTestSpCmd.ExecuteNonQuery();
  57. Pass("Test setup completed successfuly.");
  58. }
  59. catch (Exception ex)
  60. {
  61. Fail("Test setup failed");
  62. exp = ex;
  63. }
  64. finally
  65. {
  66. EndCase(exp);
  67. if (con != null && con.State != ConnectionState.Closed)
  68. {
  69. con.Close();
  70. }
  71. }
  72. }
  73. [TestFixtureTearDown()]
  74. public void TestTearDown()
  75. {
  76. BeginCase("Test Teardown");
  77. SqlConnection con = new SqlConnection(ConnectedDataProvider.ConnectionStringSQLClient);
  78. StringBuilder createTestSpBuilder = new StringBuilder();
  79. string dropTestSpSql = "DROP PROCEDURE dbo.GHSP_DateTimeOutputTest";
  80. SqlCommand dropTestSpCmd = null;
  81. try
  82. {
  83. dropTestSpCmd = new SqlCommand(dropTestSpSql, con);
  84. con.Open();
  85. dropTestSpCmd.ExecuteNonQuery();
  86. Pass("Test teardown completed successfuly.");
  87. }
  88. catch (Exception ex)
  89. {
  90. Fail("Test teardown failed");
  91. exp = ex;
  92. }
  93. finally
  94. {
  95. EndCase(exp);
  96. if (con != null && con.State != ConnectionState.Closed)
  97. {
  98. con.Close();
  99. }
  100. }
  101. }
  102. [Test]
  103. public void TestBug4703()
  104. {
  105. try
  106. {
  107. BeginCase("Test Bug 4703 - DateTime output parameter of stored procedure contains incorrect time ( always 12:00 AM )");
  108. string strConnection = ConnectedDataProvider.ConnectionStringSQLClient;
  109. SqlConnection conn = new SqlConnection(strConnection);
  110. conn.Open();
  111. SqlCommand command = conn.CreateCommand();
  112. SqlParameter param = null;
  113. command.CommandType = CommandType.StoredProcedure;
  114. command.CommandText = "GHSP_DateTimeOutputTest";
  115. param = command.CreateParameter();
  116. param.ParameterName="@LastRefresh";
  117. param.DbType = DbType.DateTime;
  118. param.Direction = ParameterDirection.InputOutput;
  119. DateTime testValue = DateTime.Now;
  120. param.Value = testValue;
  121. command.Parameters.Add( param );
  122. Compare(param.Value, testValue);
  123. }
  124. catch(Exception ex)
  125. {
  126. exp = ex;
  127. }
  128. finally
  129. {
  130. EndCase(exp);
  131. exp = null;
  132. }
  133. }
  134. }
  135. }