OracleTransaction_IsolationLevel.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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.OracleClient;
  26. using MonoTests.System.Data.Utils;
  27. using NUnit.Framework;
  28. namespace MonoTests.System.Data.OracleClient
  29. {
  30. [TestFixture]
  31. public class OracleTransaction_IsolationLevel : ADONetTesterClass
  32. {
  33. public static void Main()
  34. {
  35. OracleTransaction_IsolationLevel tc = new OracleTransaction_IsolationLevel();
  36. Exception exp = null;
  37. try
  38. {
  39. tc.BeginTest("OracleTransaction_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. OracleConnection con = new OracleConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  53. OracleTransaction 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. #if JAVA
  68. [Category("NotWorking")]
  69. #endif
  70. public void run()
  71. {
  72. Exception exp = null;
  73. MonoTests.System.Data.Utils.DataBaseServer dbServer = ConnectedDataProvider.GetDbType(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  74. OracleConnection con = new OracleConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  75. OracleTransaction txn = null;
  76. try
  77. {
  78. BeginCase("IsolationLevel = ReadCommitted");
  79. con.Open();
  80. txn=con.BeginTransaction();
  81. Compare(txn.IsolationLevel,IsolationLevel.ReadCommitted);
  82. }
  83. catch(Exception ex){exp = ex;}
  84. finally{EndCase(exp); exp = null; if (con.State == ConnectionState.Open) con.Close();}
  85. //not supported in Oracle
  86. if (dbServer != MonoTests.System.Data.Utils.DataBaseServer.Oracle)
  87. {
  88. try
  89. {
  90. BeginCase("IsolationLevel = ReadUncommitted");
  91. con.Open();
  92. txn=con.BeginTransaction(IsolationLevel.ReadUncommitted );
  93. Compare(txn.IsolationLevel,IsolationLevel.ReadUncommitted);
  94. }
  95. catch(Exception ex){exp = ex;}
  96. finally{EndCase(exp); exp = null; if (con.State == ConnectionState.Open) con.Close();}
  97. }
  98. //not supported in Oracle
  99. if (dbServer != MonoTests.System.Data.Utils.DataBaseServer.Oracle)
  100. {
  101. try
  102. {
  103. BeginCase("IsolationLevel = RepeatableRead");
  104. con.Open();
  105. txn=con.BeginTransaction(IsolationLevel.RepeatableRead);
  106. Compare(txn.IsolationLevel,IsolationLevel.RepeatableRead);
  107. }
  108. catch(Exception ex){exp = ex;}
  109. finally{EndCase(exp); exp = null; if (con.State == ConnectionState.Open) con.Close();}
  110. }
  111. try
  112. {
  113. BeginCase("IsolationLevel = Serializable");
  114. con.Open();
  115. txn=con.BeginTransaction(IsolationLevel.Serializable);
  116. Compare(txn.IsolationLevel,IsolationLevel.Serializable);
  117. txn.Rollback();
  118. txn=con.BeginTransaction();
  119. txn.Rollback();
  120. }
  121. catch(Exception ex){exp = ex;}
  122. finally{EndCase(exp); exp = null; if (con.State == ConnectionState.Open) con.Close();}
  123. // not supported in DB2,MSSQL,Oracle,sybase and guess what... Postgres.
  124. if (dbServer != MonoTests.System.Data.Utils.DataBaseServer.DB2
  125. && dbServer != MonoTests.System.Data.Utils.DataBaseServer.SQLServer
  126. && dbServer != MonoTests.System.Data.Utils.DataBaseServer.Oracle
  127. && dbServer != DataBaseServer.PostgreSQL
  128. && dbServer != MonoTests.System.Data.Utils.DataBaseServer.Sybase )
  129. {
  130. try
  131. {
  132. BeginCase("IsolationLevel = Unspecified");
  133. con.Open();
  134. txn=con.BeginTransaction(IsolationLevel.Unspecified );
  135. Compare(txn.IsolationLevel,IsolationLevel.Unspecified );
  136. }
  137. catch(Exception ex){exp = ex;}
  138. finally{EndCase(exp); exp = null; if (con.State == ConnectionState.Open) con.Close();}
  139. }
  140. }
  141. }
  142. }