2
0

OleDbConnection_BeginTransaction.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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.OleDb ;
  26. using MonoTests.System.Data.Utils;
  27. using NUnit.Framework;
  28. namespace MonoTests.System.Data.OleDb
  29. {
  30. [TestFixture]
  31. public class OleDbConnection_BeginTransaction : ADONetTesterClass
  32. {
  33. Exception exp = null;
  34. OleDbConnection con = null;
  35. OleDbTransaction tran = null;
  36. public static void Main()
  37. {
  38. OleDbConnection_BeginTransaction tc = new OleDbConnection_BeginTransaction();
  39. Exception exp = null;
  40. try
  41. {
  42. tc.BeginTest("OleDbConnection_BeginTransaction");
  43. tc.run();
  44. }
  45. catch(Exception ex){exp = ex;}
  46. finally {tc.EndTest(exp);}
  47. }
  48. [SetUp]
  49. public void SetUp() {
  50. con = new OleDbConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  51. con.Open();
  52. }
  53. [TearDown]
  54. public void TearDown() {
  55. if (con != null && con.State == ConnectionState.Open) con.Close();
  56. }
  57. [Test]
  58. #if JAVA
  59. [Category("NotWorking")]
  60. #endif
  61. public void TestBeginTransactionChaos() {
  62. DataBaseServer dbType = ConnectedDataProvider.GetDbType(con);
  63. // not supported on DB2 and Oracle and Sybase
  64. if (dbType != DataBaseServer.Oracle && dbType != DataBaseServer.DB2 && dbType != DataBaseServer.Sybase) {
  65. con.Close();
  66. con.Open();
  67. try {
  68. BeginCase("BeginTransaction - IsolationLevel Chaos");
  69. tran = con.BeginTransaction(IsolationLevel.Chaos);
  70. Compare(tran == null, false);
  71. }
  72. catch(Exception ex){exp = ex;}
  73. finally{EndCase(exp); exp = null;}
  74. }
  75. /* not supported by MSSQL,DB2,Oracle
  76. con.Close();
  77. con.Open();
  78. try
  79. {
  80. BeginCase("BeginTransaction - IsolationLevel Unspecified");
  81. tran = con.BeginTransaction(IsolationLevel.Unspecified );
  82. Compare(tran == null, false);
  83. }
  84. catch(Exception ex){exp = ex;}
  85. finally{EndCase(exp); exp = null;}
  86. */
  87. }
  88. [Test]
  89. public void run()
  90. {
  91. try
  92. {
  93. BeginCase("BeginTransaction");
  94. tran = con.BeginTransaction();
  95. Compare(tran == null, false);
  96. }
  97. catch(Exception ex){exp = ex;}
  98. finally{EndCase(exp); exp = null;}
  99. con.Close();
  100. con.Open();
  101. try
  102. {
  103. BeginCase("BeginTransaction - IsolationLevel ReadCommitted");
  104. tran = con.BeginTransaction(IsolationLevel.ReadCommitted);
  105. Compare(tran == null, false);
  106. }
  107. catch(Exception ex){exp = ex;}
  108. finally{EndCase(exp); exp = null;}
  109. DataBaseServer dbType = ConnectedDataProvider.GetDbType(con);
  110. //Not supported by JDBC driver for oracle
  111. if (dbType != DataBaseServer.Oracle)
  112. {
  113. con.Close();
  114. con.Open();
  115. try
  116. {
  117. BeginCase("BeginTransaction - IsolationLevel ReadUncommitted");
  118. tran = con.BeginTransaction(IsolationLevel.ReadUncommitted );
  119. Compare(tran == null, false);
  120. }
  121. catch(Exception ex){exp = ex;}
  122. finally{EndCase(exp); exp = null;}
  123. con.Close();
  124. con.Open();
  125. try
  126. {
  127. BeginCase("BeginTransaction - IsolationLevel RepeatableRead");
  128. tran = con.BeginTransaction(IsolationLevel.RepeatableRead);
  129. Compare(tran == null, false);
  130. }
  131. catch(Exception ex){exp = ex;}
  132. finally{EndCase(exp); exp = null;}
  133. con.Close();
  134. con.Open();
  135. try
  136. {
  137. BeginCase("BeginTransaction - IsolationLevel Serializable");
  138. tran = con.BeginTransaction(IsolationLevel.Serializable );
  139. Compare(tran == null, false);
  140. }
  141. catch(Exception ex){exp = ex;}
  142. finally{EndCase(exp); exp = null;}
  143. }
  144. }
  145. }
  146. }