ListViewGroupCollectionTest.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // ListViewGroupCollectionTest.cs
  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. // Copyright (c) 2006 Daniel Nauck
  24. //
  25. // Author:
  26. // Daniel Nauck (dna(at)mono-project(dot)de)
  27. #if NET_2_0
  28. using System;
  29. using System.Windows.Forms;
  30. using System.Drawing;
  31. using System.Reflection;
  32. using System.Collections;
  33. using NUnit.Framework;
  34. namespace MonoTests.System.Windows.Forms
  35. {
  36. [TestFixture]
  37. public class ListViewGroupCollectionTest
  38. {
  39. ListViewGroupCollection grpCol = null;
  40. [SetUp]
  41. public void SetUp()
  42. {
  43. ListView lv = new ListView ();
  44. grpCol = lv.Groups;
  45. }
  46. [Test]
  47. public void DefaultProperties ()
  48. {
  49. Assert.AreEqual (false, ((IList)grpCol).IsReadOnly, "#A1");
  50. Assert.AreEqual (false, ((IList)grpCol).IsFixedSize, "#A2");
  51. Assert.AreEqual (true, ((ICollection)grpCol).IsSynchronized, "#A3");
  52. Assert.AreEqual (grpCol, ((ICollection)grpCol).SyncRoot, "#A4");
  53. Assert.AreEqual (0, grpCol.Count, "#A5");
  54. }
  55. [Test]
  56. public void AddTest ()
  57. {
  58. grpCol.Add (new ListViewGroup ("Item1"));
  59. grpCol.Add (new ListViewGroup ("Item2"));
  60. Assert.AreEqual (2, grpCol.Count, "#B1");
  61. }
  62. [Test]
  63. public void ClearTest ()
  64. {
  65. grpCol.Add (new ListViewGroup ("Item1"));
  66. grpCol.Add (new ListViewGroup ("Item2"));
  67. grpCol.Clear ();
  68. Assert.AreEqual (0, grpCol.Count, "#C1");
  69. }
  70. [Test]
  71. public void ContainsTest ()
  72. {
  73. ListViewGroup obj = new ListViewGroup ("Item1");
  74. ListViewGroup obj2 = new ListViewGroup ("Item2");
  75. grpCol.Add (obj);
  76. Assert.AreEqual (true, grpCol.Contains (obj), "#D1");
  77. Assert.AreEqual (false, grpCol.Contains (obj2), "#D2");
  78. }
  79. [Test]
  80. public void IndexOfTest ()
  81. {
  82. ListViewGroup obj = new ListViewGroup ("Item1");
  83. ListViewGroup obj2 = new ListViewGroup ("Item2");
  84. grpCol.Add (obj);
  85. grpCol.Add (obj2);
  86. Assert.AreEqual (1, grpCol.IndexOf (obj2), "#E1");
  87. }
  88. [Test]
  89. public void RemoveTest ()
  90. {
  91. ListViewGroup obj = new ListViewGroup ("Item1");
  92. ListViewGroup obj2 = new ListViewGroup ("Item2");
  93. grpCol.Add (obj);
  94. grpCol.Add (obj2);
  95. grpCol.Remove (obj);
  96. Assert.AreEqual (1, grpCol.Count, "#F1");
  97. }
  98. [Test]
  99. public void RemoveAtTest ()
  100. {
  101. ListViewGroup obj = new ListViewGroup ("Item1");
  102. ListViewGroup obj2 = new ListViewGroup ("Item2");
  103. grpCol.Add (obj);
  104. grpCol.Add (obj2);
  105. grpCol.RemoveAt (0);
  106. Assert.AreEqual (1, grpCol.Count, "#G1");
  107. Assert.AreEqual (true, grpCol.Contains (obj2), "#G2");
  108. }
  109. [Test]
  110. [ExpectedException (typeof (ArgumentOutOfRangeException))]
  111. public void IndexerOutOfRangeTest ()
  112. {
  113. grpCol.Add (new ListViewGroup ("Item1"));
  114. grpCol[10] = null;
  115. }
  116. [Test]
  117. public void IndexerOutOfRangeTest2()
  118. { //.NET 2.0 don't throw a exception here
  119. grpCol.Add (new ListViewGroup ("Item1"));
  120. grpCol["TestItemThatDoesNotExist"] = null;
  121. }
  122. }
  123. }
  124. #endif