OleDbConnection_InfoMessage.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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.Threading;
  25. using System.Data;
  26. using NUnit.Framework;
  27. using MonoTests.System.Data.Utils;
  28. using System.Data.OleDb;
  29. namespace MonoTests.System.Data.OleDb
  30. {
  31. [TestFixture]
  32. public class OleDbConnection_InfoMessage : GHTBase
  33. {
  34. private int errorCounter=0;
  35. public static void Main()
  36. {
  37. OleDbConnection_InfoMessage tc = new OleDbConnection_InfoMessage();
  38. Exception exp = null;
  39. try
  40. {
  41. // Every Test must begin with BeginTest
  42. tc.BeginTest("OleDbConnection_InfoMessage");
  43. tc.run();
  44. }
  45. catch(Exception ex)
  46. {
  47. exp = ex;
  48. }
  49. finally
  50. {
  51. // Every Test must End with EndTest
  52. tc.EndTest(exp);
  53. }
  54. }
  55. public void run()
  56. {
  57. Exception exp = null;
  58. // Start Sub Test
  59. try
  60. {
  61. test();
  62. }
  63. catch(Exception ex)
  64. {
  65. exp = ex;
  66. }
  67. finally
  68. {
  69. // Every Sub Test must end with EndCase
  70. EndCase(exp);
  71. exp = null;
  72. }
  73. // End Sub Test
  74. }
  75. [Test]
  76. #if JAVA
  77. [Category("NotWorking")]
  78. #endif
  79. public void test()
  80. {
  81. BeginCase("InfoMessage testing");
  82. OleDbConnection con = new OleDbConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  83. con.Open();
  84. con.InfoMessage+=new OleDbInfoMessageEventHandler(con_InfoMessage);
  85. generateError(con);
  86. con.Close();
  87. }
  88. private void generateError(OleDbConnection con)
  89. {
  90. string errorString = string.Empty;
  91. OleDbCommand cmd = new OleDbCommand(string.Empty,con);
  92. switch (ConnectedDataProvider.GetDbType(con))
  93. {
  94. case DataBaseServer.SQLServer:
  95. case DataBaseServer.Sybase:
  96. {
  97. cmd.CommandText = "Raiserror ('A sample SQL informational message',10,1)";
  98. break;
  99. }
  100. case DataBaseServer.Oracle:
  101. case DataBaseServer.PostgreSQL:
  102. {
  103. cmd.CommandText = "GH_ERROR";
  104. //cmd.CommandText = "print 'This is a warning.'";
  105. //cmd.CommandText = "select count(SUPPLIERID) from GHTDB.PRODUCTS";
  106. cmd.CommandType = CommandType.StoredProcedure;
  107. break;
  108. }
  109. case DataBaseServer.DB2:
  110. {
  111. cmd.CommandText = "SIGNAL SQLSTATE '99999' SET MESSAGE_TEXT ='Blah Blah';";
  112. break;
  113. }
  114. default:
  115. {
  116. throw new NotImplementedException(string.Format("GHT: Test is not implemented for {0}", ConnectedDataProvider.GetDbType(con)));
  117. }
  118. }
  119. //cmd.CommandType = CommandType.StoredProcedure;
  120. cmd.ExecuteNonQuery();
  121. // cmd.CommandText = "TestInfoMessage";
  122. // cmd.CommandType = CommandType.StoredProcedure;
  123. if (errorCounter == 0)
  124. {
  125. Thread.Sleep(5000);
  126. }
  127. Compare(errorCounter,1);
  128. }
  129. private void con_InfoMessage(object sender, OleDbInfoMessageEventArgs e)
  130. {
  131. foreach(OleDbError err in e.Errors)
  132. {
  133. errorCounter++;
  134. }
  135. }
  136. //Activate This Construntor to log All To Standard output
  137. //public TestClass():base(true){}
  138. //Activate this constructor to log Failures to a log file
  139. //public TestClass(System.IO.TextWriter tw):base(tw, false){}
  140. //Activate this constructor to log All to a log file
  141. //public TestClass(System.IO.TextWriter tw):base(tw, true){}
  142. //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
  143. }
  144. }