CodeExpressionCollectionTest.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. //
  2. // CodeExpressionCollectionTest.cs
  3. // - Unit tests for System.CodeDom.CodeExpressionCollection
  4. //
  5. // Author:
  6. // Gert Driesen <[email protected]>
  7. //
  8. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using NUnit.Framework;
  30. using System;
  31. using System.Collections;
  32. using System.CodeDom;
  33. namespace MonoTests.System.CodeDom {
  34. [TestFixture]
  35. public class CodeExpressionCollectionTest {
  36. [Test]
  37. public void Constructor0 ()
  38. {
  39. CodeExpressionCollection coll = new CodeExpressionCollection ();
  40. Assert.IsFalse (((IList) coll).IsFixedSize, "#1");
  41. Assert.IsFalse (((IList) coll).IsReadOnly, "#2");
  42. Assert.AreEqual (0, coll.Count, "#3");
  43. Assert.IsFalse (((ICollection) coll).IsSynchronized, "#4");
  44. }
  45. [Test]
  46. public void Constructor1 ()
  47. {
  48. CodeExpression exp1 = new CodeExpression ();
  49. CodeExpression exp2 = new CodeExpression ();
  50. CodeExpression[] expressions = new CodeExpression[] { exp1, exp2 };
  51. CodeExpressionCollection coll = new CodeExpressionCollection (
  52. expressions);
  53. Assert.AreEqual (2, coll.Count, "#1");
  54. Assert.AreEqual (0, coll.IndexOf (exp1), "#2");
  55. Assert.AreEqual (1, coll.IndexOf (exp2), "#3");
  56. }
  57. [Test]
  58. [ExpectedException (typeof (ArgumentNullException))]
  59. public void Constructor1_NullItem ()
  60. {
  61. CodeExpression[] expressions = new CodeExpression[] {
  62. new CodeExpression (), null };
  63. CodeExpressionCollection coll = new CodeExpressionCollection (
  64. expressions);
  65. }
  66. [Test]
  67. [ExpectedException (typeof (ArgumentNullException))]
  68. public void Constructor1_Null () {
  69. CodeExpressionCollection coll = new CodeExpressionCollection (
  70. (CodeExpression[]) null);
  71. }
  72. [Test]
  73. public void Constructor2 ()
  74. {
  75. CodeExpression exp1 = new CodeExpression ();
  76. CodeExpression exp2 = new CodeExpression ();
  77. CodeExpressionCollection c = new CodeExpressionCollection ();
  78. c.Add (exp1);
  79. c.Add (exp2);
  80. CodeExpressionCollection coll = new CodeExpressionCollection (c);
  81. Assert.AreEqual (2, coll.Count, "#1");
  82. Assert.AreEqual (0, coll.IndexOf (exp1), "#2");
  83. Assert.AreEqual (1, coll.IndexOf (exp2), "#3");
  84. }
  85. [Test]
  86. [ExpectedException (typeof (ArgumentNullException))]
  87. public void Constructor2_Null ()
  88. {
  89. CodeExpressionCollection coll = new CodeExpressionCollection (
  90. (CodeExpressionCollection) null);
  91. }
  92. [Test]
  93. public void Add ()
  94. {
  95. CodeExpression exp1 = new CodeExpression ();
  96. CodeExpression exp2 = new CodeExpression ();
  97. CodeExpressionCollection coll = new CodeExpressionCollection ();
  98. Assert.AreEqual (0, coll.Add (exp1), "#1");
  99. Assert.AreEqual (1, coll.Count, "#2");
  100. Assert.AreEqual (0, coll.IndexOf (exp1), "#3");
  101. Assert.AreEqual (1, coll.Add (exp2), "#4");
  102. Assert.AreEqual (2, coll.Count, "#5");
  103. Assert.AreEqual (1, coll.IndexOf (exp2), "#6");
  104. }
  105. [Test]
  106. [ExpectedException (typeof (ArgumentNullException))]
  107. public void Add_Null () {
  108. CodeExpressionCollection coll = new CodeExpressionCollection ();
  109. coll.Add ((CodeExpression) null);
  110. }
  111. [Test]
  112. public void Insert ()
  113. {
  114. CodeExpression exp1 = new CodeExpression ();
  115. CodeExpression exp2 = new CodeExpression ();
  116. CodeExpressionCollection coll = new CodeExpressionCollection ();
  117. coll.Add (exp1);
  118. Assert.AreEqual (1, coll.Count, "#1");
  119. Assert.AreEqual (0, coll.IndexOf (exp1), "#2");
  120. coll.Insert (0, exp2);
  121. Assert.AreEqual (2, coll.Count, "#3");
  122. Assert.AreEqual (1, coll.IndexOf (exp1), "#4");
  123. Assert.AreEqual (0, coll.IndexOf (exp2), "#5");
  124. }
  125. [Test]
  126. [ExpectedException (typeof (ArgumentNullException))]
  127. public void Insert_Null ()
  128. {
  129. CodeExpressionCollection coll = new CodeExpressionCollection ();
  130. coll.Insert (0, (CodeExpression) null);
  131. }
  132. [Test]
  133. public void AddRange ()
  134. {
  135. CodeExpression exp1 = new CodeExpression ();
  136. CodeExpression exp2 = new CodeExpression ();
  137. CodeExpressionCollection coll1 = new CodeExpressionCollection ();
  138. coll1.Add (exp1);
  139. coll1.Add (exp2);
  140. CodeExpressionCollection coll2 = new CodeExpressionCollection(coll1);
  141. Assert.AreEqual (2, coll2.Count, "#1");
  142. Assert.AreEqual (0, coll2.IndexOf (exp1), "#2");
  143. Assert.AreEqual (1, coll2.IndexOf (exp2), "#3");
  144. CodeExpressionCollection coll3 = new CodeExpressionCollection(
  145. new CodeExpression[] {exp1, exp2});
  146. Assert.AreEqual (2, coll2.Count, "#4");
  147. Assert.AreEqual (0, coll2.IndexOf (exp1), "#5");
  148. Assert.AreEqual (1, coll2.IndexOf (exp2), "#6");
  149. }
  150. [Test]
  151. [ExpectedException (typeof (ArgumentNullException))]
  152. public void AddRange_Null_Array ()
  153. {
  154. CodeExpressionCollection coll = new CodeExpressionCollection ();
  155. coll.AddRange ((CodeExpression[]) null);
  156. }
  157. [Test]
  158. [ExpectedException (typeof (ArgumentNullException))]
  159. public void AddRange_Null_Collection ()
  160. {
  161. CodeExpressionCollection coll = new CodeExpressionCollection ();
  162. coll.AddRange ((CodeExpressionCollection) null);
  163. }
  164. [Test]
  165. public void AddRange_Self ()
  166. {
  167. CodeExpressionCollection coll = new CodeExpressionCollection ();
  168. coll.AddRange (coll);
  169. Assert.AreEqual (0, coll.Count, "0");
  170. }
  171. }
  172. }