SqlConnection_BeginTransaction_S.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using System;
  2. using System.Data;
  3. using System.Data.OleDb;
  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 SqlConnection_BeginTransaction_S : ADONetTesterClass
  11. {
  12. SqlConnection con;
  13. [SetUp]
  14. public void SetUp()
  15. {
  16. Exception exp = null;
  17. BeginCase("Setup");
  18. try
  19. {
  20. con = new SqlConnection(ConnectedDataProvider.ConnectionStringSQLClient);
  21. con.Open();
  22. Compare("Setup", "Setup");
  23. }
  24. catch(Exception ex) {exp = ex;}
  25. finally {EndCase(exp); exp = null;}
  26. }
  27. [TearDown]
  28. public void TearDown()
  29. {
  30. if (con != null)
  31. {
  32. if (con.State == ConnectionState.Open) con.Close();
  33. }
  34. }
  35. public static void Main()
  36. {
  37. SqlConnection_BeginTransaction_S tc = new SqlConnection_BeginTransaction_S();
  38. Exception exp = null;
  39. try
  40. {
  41. tc.BeginTest("SqlConnection_BeginTransaction_S");
  42. //testing only on SQLServer
  43. if (ConnectedDataProvider.GetDbType(ConnectedDataProvider.ConnectionStringSQLClient) != DataBaseServer.SQLServer) return ;
  44. tc.SetUp();
  45. tc.run();
  46. tc.TearDown();
  47. }
  48. catch(Exception ex)
  49. {
  50. exp = ex;
  51. }
  52. finally
  53. {
  54. tc.EndTest(exp);
  55. }
  56. }
  57. [Test]
  58. public void run()
  59. {
  60. Exception exp = null;
  61. #region ---- Bug 2716 - MSSQL - SqlCommand.Transaction ----
  62. // testing only SQLServerr
  63. if (ConnectedDataProvider.GetDbType(con.ConnectionString) != DataBaseServer.SQLServer)
  64. {
  65. try
  66. {
  67. BeginCase("Bug 2716 - MSSQL - SqlCommand.Transaction");
  68. SqlCommand comm = new SqlCommand("SELECT * FROM Customers",con);
  69. SqlTransaction trans = con.BeginTransaction("transaction");
  70. comm.Transaction = trans;
  71. con.Close();
  72. Compare(con.State,ConnectionState.Closed);
  73. }
  74. catch(Exception ex)
  75. {
  76. exp = ex;
  77. }
  78. finally
  79. {
  80. if (con != null)
  81. {if (con.State == ConnectionState.Open) con.Close();}
  82. EndCase(exp);
  83. exp = null;
  84. }
  85. }
  86. #endregion
  87. }
  88. }
  89. }