OleDbTransaction_IsolationLevel.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 OleDbTransaction_IsolationLevel : ADONetTesterClass
  32. {
  33. public static void Main()
  34. {
  35. OleDbTransaction_IsolationLevel tc = new OleDbTransaction_IsolationLevel();
  36. Exception exp = null;
  37. try
  38. {
  39. tc.BeginTest("OleDbTransaction_IsolationLevel");
  40. tc.run();
  41. }
  42. catch(Exception ex){exp = ex;}
  43. finally {tc.EndTest(exp);}
  44. }
  45. [Test]
  46. #if JAVA
  47. [Category("NotWorking")]
  48. #endif
  49. public void IsolationLevelChaos() {
  50. Exception exp = null;
  51. MonoTests.System.Data.Utils.DataBaseServer dbServer = ConnectedDataProvider.GetDbType(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  52. OleDbConnection con = new OleDbConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  53. OleDbTransaction txn = null;
  54. //supported only in SQLServer
  55. if (dbServer == MonoTests.System.Data.Utils.DataBaseServer.SQLServer) {
  56. try {
  57. BeginCase("IsolationLevel = Chaos");
  58. con.Open();
  59. txn=con.BeginTransaction(IsolationLevel.Chaos);
  60. Compare(txn.IsolationLevel,IsolationLevel.Chaos);
  61. }
  62. catch(Exception ex){exp = ex;}
  63. finally{EndCase(exp); exp = null; if (con.State == ConnectionState.Open) con.Close();}
  64. }
  65. }
  66. [Test]
  67. public void run()
  68. {
  69. Exception exp = null;
  70. MonoTests.System.Data.Utils.DataBaseServer dbServer = ConnectedDataProvider.GetDbType(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  71. OleDbConnection con = new OleDbConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  72. OleDbTransaction txn = null;
  73. try
  74. {
  75. BeginCase("IsolationLevel = ReadCommitted");
  76. con.Open();
  77. txn=con.BeginTransaction();
  78. Compare(txn.IsolationLevel,IsolationLevel.ReadCommitted);
  79. }
  80. catch(Exception ex){exp = ex;}
  81. finally{EndCase(exp); exp = null; if (con.State == ConnectionState.Open) con.Close();}
  82. //not supported in Oracle
  83. if (dbServer != MonoTests.System.Data.Utils.DataBaseServer.Oracle)
  84. {
  85. try
  86. {
  87. BeginCase("IsolationLevel = ReadUncommitted");
  88. con.Open();
  89. txn=con.BeginTransaction(IsolationLevel.ReadUncommitted );
  90. Compare(txn.IsolationLevel,IsolationLevel.ReadUncommitted);
  91. }
  92. catch(Exception ex){exp = ex;}
  93. finally{EndCase(exp); exp = null; if (con.State == ConnectionState.Open) con.Close();}
  94. }
  95. //not supported in Oracle
  96. if (dbServer != MonoTests.System.Data.Utils.DataBaseServer.Oracle)
  97. {
  98. try
  99. {
  100. BeginCase("IsolationLevel = RepeatableRead");
  101. con.Open();
  102. txn=con.BeginTransaction(IsolationLevel.RepeatableRead);
  103. Compare(txn.IsolationLevel,IsolationLevel.RepeatableRead);
  104. }
  105. catch(Exception ex){exp = ex;}
  106. finally{EndCase(exp); exp = null; if (con.State == ConnectionState.Open) con.Close();}
  107. }
  108. try
  109. {
  110. BeginCase("IsolationLevel = Serializable");
  111. con.Open();
  112. txn=con.BeginTransaction(IsolationLevel.Serializable);
  113. Compare(txn.IsolationLevel,IsolationLevel.Serializable);
  114. txn.Rollback();
  115. txn=con.BeginTransaction();
  116. txn.Rollback();
  117. }
  118. catch(Exception ex){exp = ex;}
  119. finally{EndCase(exp); exp = null; if (con.State == ConnectionState.Open) con.Close();}
  120. // not supported in DB2,MSSQL,Oracle,sybase and guess what... Postgres.
  121. if (dbServer != MonoTests.System.Data.Utils.DataBaseServer.DB2
  122. && dbServer != MonoTests.System.Data.Utils.DataBaseServer.SQLServer
  123. && dbServer != MonoTests.System.Data.Utils.DataBaseServer.Oracle
  124. && dbServer != DataBaseServer.PostgreSQL
  125. && dbServer != MonoTests.System.Data.Utils.DataBaseServer.Sybase )
  126. {
  127. try
  128. {
  129. BeginCase("IsolationLevel = Unspecified");
  130. con.Open();
  131. txn=con.BeginTransaction(IsolationLevel.Unspecified );
  132. Compare(txn.IsolationLevel,IsolationLevel.Unspecified );
  133. }
  134. catch(Exception ex){exp = ex;}
  135. finally{EndCase(exp); exp = null; if (con.State == ConnectionState.Open) con.Close();}
  136. }
  137. }
  138. }
  139. }