2
0

SqlConnection_InfoMessage.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. Exception exp = null;
  39. // Start Sub Test
  40. try
  41. {
  42. BeginCase("InfoMessage testing");
  43. SqlConnection con = new SqlConnection(ConnectedDataProvider.ConnectionStringSQLClient);
  44. con.Open();
  45. con.InfoMessage+=new SqlInfoMessageEventHandler(con_InfoMessage);
  46. generateError(con);
  47. con.Close();
  48. }
  49. catch(Exception ex)
  50. {
  51. exp = ex;
  52. }
  53. finally
  54. {
  55. // Every Sub Test must end with EndCase
  56. EndCase(exp);
  57. exp = null;
  58. }
  59. // End Sub Test
  60. }
  61. private void generateError(SqlConnection con)
  62. {
  63. string errorString = string.Empty;
  64. SqlCommand cmd = new SqlCommand (string.Empty,con);
  65. cmd.CommandText = "Raiserror ('A sample SQL informational message',10,1)";
  66. cmd.ExecuteNonQuery();
  67. // cmd.CommandText = "TestInfoMessage";
  68. // cmd.CommandType = CommandType.StoredProcedure;
  69. if (errorCounter == 0)
  70. {
  71. Thread.Sleep(5000);
  72. }
  73. Compare(errorCounter,1);
  74. }
  75. //Activate This Construntor to log All To Standard output
  76. //public TestClass():base(true){}
  77. //Activate this constructor to log Failures to a log file
  78. //public TestClass(System.IO.TextWriter tw):base(tw, false){}
  79. //Activate this constructor to log All to a log file
  80. //public TestClass(System.IO.TextWriter tw):base(tw, true){}
  81. //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
  82. private void con_InfoMessage(object sender, SqlInfoMessageEventArgs e)
  83. {
  84. errorCounter++;
  85. }
  86. }
  87. }