SqlConnection_InfoMessage.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System;
  2. using System.Data;
  3. using System.Data.SqlClient;
  4. using System.Threading;
  5. using MonoTests.System.Data.Utils;
  6. using NUnit.Framework;
  7. namespace MonoTests.System.Data.SqlClient
  8. {
  9. [TestFixture]
  10. public class SqlConnection_InfoMessage : GHTBase
  11. {
  12. private int errorCounter=0;
  13. public static void Main()
  14. {
  15. SqlConnection_InfoMessage tc = new SqlConnection_InfoMessage();
  16. Exception exp = null;
  17. try
  18. {
  19. // Every Test must begin with BeginTest
  20. tc.BeginTest("NoName");
  21. tc.run();
  22. }
  23. catch(Exception ex)
  24. {
  25. exp = ex;
  26. }
  27. finally
  28. {
  29. // Every Test must End with EndTest
  30. tc.EndTest(exp);
  31. }
  32. // After test is ready, remove this line
  33. }
  34. [Test]
  35. [Category("NotWorking")]
  36. public void run()
  37. {
  38. if (ConnectedDataProvider.GetDbType() != DataBaseServer.SQLServer) {
  39. //All tests in this class are only for MSSQLServer.
  40. Log(string.Format("All tests in this class are only for MSSQLServer and cannot be tested on {0}", ConnectedDataProvider.GetDbType()));
  41. return;
  42. }
  43. Exception exp = null;
  44. // Start Sub Test
  45. try
  46. {
  47. BeginCase("InfoMessage testing");
  48. SqlConnection con = new SqlConnection(ConnectedDataProvider.ConnectionStringSQLClient);
  49. con.Open();
  50. con.InfoMessage+=new SqlInfoMessageEventHandler(con_InfoMessage);
  51. generateError(con);
  52. con.Close();
  53. }
  54. catch(Exception ex)
  55. {
  56. exp = ex;
  57. }
  58. finally
  59. {
  60. // Every Sub Test must end with EndCase
  61. EndCase(exp);
  62. exp = null;
  63. }
  64. // End Sub Test
  65. }
  66. private void generateError(SqlConnection con)
  67. {
  68. string errorString = string.Empty;
  69. SqlCommand cmd = new SqlCommand (string.Empty,con);
  70. cmd.CommandText = "Raiserror ('A sample SQL informational message',10,1)";
  71. cmd.ExecuteNonQuery();
  72. // cmd.CommandText = "TestInfoMessage";
  73. // cmd.CommandType = CommandType.StoredProcedure;
  74. if (errorCounter == 0)
  75. {
  76. Thread.Sleep(5000);
  77. }
  78. Compare(errorCounter,1);
  79. }
  80. //Activate This Construntor to log All To Standard output
  81. //public TestClass():base(true){}
  82. //Activate this constructor to log Failures to a log file
  83. //public TestClass(System.IO.TextWriter tw):base(tw, false){}
  84. //Activate this constructor to log All to a log file
  85. //public TestClass(System.IO.TextWriter tw):base(tw, true){}
  86. //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
  87. private void con_InfoMessage(object sender, SqlInfoMessageEventArgs e)
  88. {
  89. errorCounter++;
  90. }
  91. }
  92. }