SqlCommand_ExecuteReader_.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Data;
  3. using System.Data.SqlClient;
  4. using MonoTests.System.Data.Utils;
  5. using NUnit.Framework;
  6. namespace MonoTests.System.Data.SqlClient
  7. {
  8. [TestFixture]
  9. public class SqlCommand_ExecuteReader_ : ADONetTesterClass
  10. {
  11. private Exception exp;
  12. public static void Main()
  13. {
  14. SqlCommand_ExecuteReader_ tc = new SqlCommand_ExecuteReader_();
  15. try
  16. {
  17. // Every Test must begin with BeginTest
  18. tc.BeginTest("SqlCommand_ExecuteReader");
  19. tc.run();
  20. }
  21. catch(Exception ex)
  22. {
  23. tc.exp = ex;
  24. }
  25. finally
  26. {
  27. // Every Test must End with EndTest
  28. tc.EndTest(tc.exp);
  29. }
  30. }
  31. [Test]
  32. public void run()
  33. {
  34. // testing only SQLServerr
  35. if (ConnectedDataProvider.GetDbType() != DataBaseServer.SQLServer)
  36. {
  37. Log("This test is relevant only for MSSQLServer!");
  38. return;
  39. }
  40. DoTestCheckSqlStatementThatDeclaresLocalVariableAndUsesIt();
  41. }
  42. public void DoTestCheckSqlStatementThatDeclaresLocalVariableAndUsesIt()
  43. {
  44. SqlConnection conn = new SqlConnection(ConnectedDataProvider.ConnectionStringSQLClient);
  45. SqlDataReader rdr=null;
  46. try
  47. {
  48. BeginCase("Check sql statement that declares a local variable and uses it.");
  49. SqlCommand cmd = new SqlCommand();
  50. conn.Open();
  51. cmd.Connection = conn;
  52. cmd.CommandText = "declare @var int; select @var=1;";
  53. cmd.CommandType = CommandType.Text;
  54. rdr = cmd.ExecuteReader();
  55. Compare(rdr.Read(), false);
  56. }
  57. catch (Exception ex)
  58. {
  59. exp = ex;
  60. }
  61. finally
  62. {
  63. EndCase(exp);
  64. exp = null;
  65. if (conn != null && conn.State != ConnectionState.Closed)
  66. {
  67. conn.Close();
  68. }
  69. if (rdr != null && !rdr.IsClosed)
  70. {
  71. rdr.Close();
  72. }
  73. }
  74. }
  75. }
  76. }