DataTableCollection_CollectionChanged.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Authors:
  2. // Rafael Mizrahi <[email protected]>
  3. // Erez Lotan <[email protected]>
  4. // Oren Gurfinkel <[email protected]>
  5. // Ofer Borstein
  6. //
  7. // Copyright (c) 2004 Mainsoft Co.
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Data;
  30. using NUnit.Framework;
  31. using GHTUtils;
  32. using GHTUtils.Base;
  33. namespace tests.system_data_dll.System_Data
  34. {
  35. [TestFixture]
  36. public class DataTableCollection_CollectionChanged : GHTBase
  37. {
  38. private int counter=0;
  39. public static void Main()
  40. {
  41. DataTableCollection_CollectionChanged tc = new DataTableCollection_CollectionChanged();
  42. Exception exp = null;
  43. try
  44. {
  45. tc.BeginTest("DataTableCollection_CollectionChanged");
  46. tc.run();
  47. }
  48. catch(Exception ex)
  49. {
  50. exp = ex;
  51. }
  52. finally
  53. {
  54. tc.EndTest(exp);
  55. }
  56. }
  57. //Activate This Construntor to log All To Standard output
  58. //public TestClass():base(true){}
  59. //Activate this constructor to log Failures to a log file
  60. //public TestClass(System.IO.TextWriter tw):base(tw, false){}
  61. //Activate this constructor to log All to a log file
  62. //public TestClass(System.IO.TextWriter tw):base(tw, true){}
  63. //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
  64. public void run()
  65. {
  66. Exception exp = null;
  67. try
  68. {
  69. BeginCase("DataTableCollection_CollectionChanged1");
  70. DataTableCollection_CollectionChanged1();
  71. }
  72. catch(Exception ex)
  73. {
  74. exp = ex;
  75. }
  76. finally
  77. {
  78. EndCase(exp);
  79. exp = null;
  80. }
  81. }
  82. [Test]
  83. public void DataTableCollection_CollectionChanged1()
  84. {
  85. DataSet ds = new DataSet();
  86. ds.Tables.CollectionChanged+=new System.ComponentModel.CollectionChangeEventHandler(Tables_CollectionChanged);
  87. ds.Tables.Add();
  88. ds.Tables.Add();
  89. System.Threading.Thread.Sleep(500);
  90. Compare(counter,2);
  91. ds.Tables.Remove(ds.Tables[0]);
  92. ds.Tables.Remove(ds.Tables[0]);
  93. System.Threading.Thread.Sleep(500);
  94. Compare(counter,4);
  95. }
  96. private void Tables_CollectionChanged(object sender, System.ComponentModel.CollectionChangeEventArgs e)
  97. {
  98. counter++;
  99. }
  100. }
  101. }