TestOracleClient.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // TestOracleClient.cs - Tests Sytem.Data.OracleClient
  3. // data provider in Mono.
  4. //
  5. // Part of managed C#/.NET library System.Data.OracleClient.dll
  6. //
  7. // Part of the Mono class libraries at
  8. // mcs/class/System.Data.OracleClient/System.Data.OracleClient.OCI
  9. //
  10. // Tests:
  11. // Assembly: System.Data.OracleClient.dll
  12. // Namespace: System.Data.OracleClient
  13. //
  14. // Author:
  15. // Daniel Morgan <[email protected]>
  16. //
  17. // Copyright (C) Daniel Morgan, 2002
  18. //
  19. using System;
  20. using System.Runtime.InteropServices;
  21. using System.Data.OracleClient;
  22. namespace Test.OracleClient
  23. {
  24. public class OracleTest
  25. {
  26. public OracleTest()
  27. {
  28. }
  29. static void DoTest1(OracleConnection con, int conn)
  30. {
  31. string inst = conn.ToString();
  32. string insertSql =
  33. "insert into scott.emp " +
  34. "(empno, ename, job, sal, deptno) " +
  35. "values(123" + inst + "," +
  36. "'conn" + inst + "'," +
  37. "'homy" + inst + "'," +
  38. "321" + inst + ",20)";
  39. Console.WriteLine("insertSql: " + insertSql);
  40. OracleCommand cmd = new OracleCommand();
  41. cmd.Connection = con;
  42. cmd.CommandText = insertSql;
  43. cmd.ExecuteNonQuery();
  44. if(conn == 2)
  45. cmd.CommandText = "rollback";
  46. else
  47. cmd.CommandText = "commit";
  48. cmd.ExecuteNonQuery();
  49. }
  50. static void DoTest9(OracleConnection con) {
  51. string inst = "9";
  52. string insertSql =
  53. "insert into scott.emp " +
  54. "(empno, ename, job, sal, deptno) " +
  55. "values(123" + inst + "," +
  56. "'conn" + inst + "'," +
  57. "'homy" + inst + "'," +
  58. "321" + inst + ",20)";
  59. Console.WriteLine("insertSql: " + insertSql);
  60. OracleCommand cmd = new OracleCommand();
  61. cmd.Connection = con;
  62. cmd.CommandText = insertSql;
  63. cmd.ExecuteNonQuery();
  64. cmd.CommandText = "commit";
  65. cmd.ExecuteNonQuery();
  66. }
  67. static void ConnectionCount() {
  68. uint count = OracleConnection.ConnectionCount;
  69. string msg = "Connection Count: " + count.ToString();
  70. Console.WriteLine(msg);
  71. }
  72. static void Wait(string msg)
  73. {
  74. Console.WriteLine(msg);
  75. Console.WriteLine("Waiting... Presee Enter to continue...");
  76. string nothing = Console.ReadLine();
  77. }
  78. [STAThread]
  79. static void Main(string[] args)
  80. {
  81. string connectionString;
  82. connectionString =
  83. "Data Source=dansdb;" +
  84. "User ID=scott;" +
  85. "Password=tiger";
  86. Wait("Verify database.");
  87. ConnectionCount(); // should be 0
  88. OracleConnection con1 = new OracleConnection();
  89. con1.ConnectionString = connectionString;
  90. con1.Open();
  91. ConnectionCount(); // should be 1
  92. OracleConnection con2 = new OracleConnection();
  93. con2.ConnectionString = connectionString;
  94. con2.Open();
  95. ConnectionCount(); // should be 2
  96. OracleConnection con3 = new OracleConnection();
  97. con3.ConnectionString = connectionString;
  98. con3.Open();
  99. ConnectionCount(); // should be 3
  100. Wait("Verify Connected.");
  101. DoTest1(con1, 1);
  102. DoTest1(con2, 2);
  103. DoTest1(con3, 3);
  104. DoTest9(con1);
  105. Wait("Verify Proper Results.");
  106. ConnectionCount(); // should be 3
  107. con1.Close();
  108. ConnectionCount(); // should be 2
  109. con2.Close();
  110. ConnectionCount(); // should be 1
  111. con3.Close();
  112. ConnectionCount(); // should be 0
  113. Wait("Verify Disconnected");
  114. }
  115. }
  116. }