SqlConnection_BeginTransaction_S.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. if (ConnectedDataProvider.GetDbType() != DataBaseServer.SQLServer) {
  17. //All tests in this class are only for MSSQLServer.
  18. Log(string.Format("All tests in this class are only for MSSQLServer and cannot be tested on {0}", ConnectedDataProvider.GetDbType()));
  19. return;
  20. }
  21. Exception exp = null;
  22. BeginCase("Setup");
  23. try
  24. {
  25. con = new SqlConnection(ConnectedDataProvider.ConnectionStringSQLClient);
  26. con.Open();
  27. Compare("Setup", "Setup");
  28. }
  29. catch(Exception ex) {exp = ex;}
  30. finally {EndCase(exp); exp = null;}
  31. }
  32. [TearDown]
  33. public void TearDown()
  34. {
  35. if (ConnectedDataProvider.GetDbType() != DataBaseServer.SQLServer) {
  36. //All tests in this class are only for MSSQLServer.
  37. Log(string.Format("All tests in this class are only for MSSQLServer and cannot be tested on {0}", ConnectedDataProvider.GetDbType()));
  38. return;
  39. }
  40. if (con != null)
  41. {
  42. if (con.State == ConnectionState.Open) con.Close();
  43. }
  44. }
  45. public static void Main()
  46. {
  47. SqlConnection_BeginTransaction_S tc = new SqlConnection_BeginTransaction_S();
  48. Exception exp = null;
  49. try
  50. {
  51. tc.BeginTest("SqlConnection_BeginTransaction_S");
  52. //testing only on SQLServer
  53. if (ConnectedDataProvider.GetDbType(ConnectedDataProvider.ConnectionStringSQLClient) != DataBaseServer.SQLServer) return ;
  54. tc.SetUp();
  55. tc.run();
  56. tc.TearDown();
  57. }
  58. catch(Exception ex)
  59. {
  60. exp = ex;
  61. }
  62. finally
  63. {
  64. tc.EndTest(exp);
  65. }
  66. }
  67. [Test]
  68. public void run()
  69. {
  70. if (ConnectedDataProvider.GetDbType() != DataBaseServer.SQLServer) {
  71. //All tests in this class are only for MSSQLServer.
  72. Log(string.Format("All tests in this class are only for MSSQLServer and cannot be tested on {0}", ConnectedDataProvider.GetDbType()));
  73. return;
  74. }
  75. Exception exp = null;
  76. #region ---- Bug 2716 - MSSQL - SqlCommand.Transaction ----
  77. // testing only SQLServerr
  78. if (ConnectedDataProvider.GetDbType(con.ConnectionString) != DataBaseServer.SQLServer)
  79. {
  80. try
  81. {
  82. BeginCase("Bug 2716 - MSSQL - SqlCommand.Transaction");
  83. SqlCommand comm = new SqlCommand("SELECT * FROM Customers",con);
  84. SqlTransaction trans = con.BeginTransaction("transaction");
  85. comm.Transaction = trans;
  86. con.Close();
  87. Compare(con.State,ConnectionState.Closed);
  88. }
  89. catch(Exception ex)
  90. {
  91. exp = ex;
  92. }
  93. finally
  94. {
  95. if (con != null)
  96. {if (con.State == ConnectionState.Open) con.Close();}
  97. EndCase(exp);
  98. exp = null;
  99. }
  100. }
  101. #endregion
  102. }
  103. }
  104. }