CodeParameterDeclarationExpressionCollectionTest.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. //
  2. // CodeParameterDeclarationExpressionCollectionTest.cs
  3. // - Unit tests for System.CodeDom.CodeParameterDeclarationExpressionCollection
  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 CodeParameterDeclarationExpressionCollectionTest {
  36. [Test]
  37. public void Constructor0 ()
  38. {
  39. CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
  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. CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression ();
  49. CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression ();
  50. CodeParameterDeclarationExpression[] parameters = new CodeParameterDeclarationExpression[] { param1, param2 };
  51. CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection (
  52. parameters);
  53. Assert.AreEqual (2, coll.Count, "#1");
  54. Assert.AreEqual (0, coll.IndexOf (param1), "#2");
  55. Assert.AreEqual (1, coll.IndexOf (param2), "#3");
  56. }
  57. [Test]
  58. [ExpectedException (typeof (ArgumentNullException))]
  59. public void Constructor1_NullItem ()
  60. {
  61. CodeParameterDeclarationExpression[] parameters = new CodeParameterDeclarationExpression[] {
  62. new CodeParameterDeclarationExpression (), null };
  63. CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection (
  64. parameters);
  65. }
  66. [Test]
  67. [ExpectedException (typeof (ArgumentNullException))]
  68. public void Constructor1_Null () {
  69. CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection (
  70. (CodeParameterDeclarationExpression[]) null);
  71. }
  72. [Test]
  73. public void Constructor2 ()
  74. {
  75. CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression ();
  76. CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression ();
  77. CodeParameterDeclarationExpressionCollection c = new CodeParameterDeclarationExpressionCollection ();
  78. c.Add (param1);
  79. c.Add (param2);
  80. CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection (c);
  81. Assert.AreEqual (2, coll.Count, "#1");
  82. Assert.AreEqual (0, coll.IndexOf (param1), "#2");
  83. Assert.AreEqual (1, coll.IndexOf (param2), "#3");
  84. }
  85. [Test]
  86. [ExpectedException (typeof (ArgumentNullException))]
  87. public void Constructor2_Null ()
  88. {
  89. CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection (
  90. (CodeParameterDeclarationExpressionCollection) null);
  91. }
  92. [Test]
  93. public void Add ()
  94. {
  95. CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression ();
  96. CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression ();
  97. CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
  98. Assert.AreEqual (0, coll.Add (param1), "#1");
  99. Assert.AreEqual (1, coll.Count, "#2");
  100. Assert.AreEqual (0, coll.IndexOf (param1), "#3");
  101. Assert.AreEqual (1, coll.Add (param2), "#4");
  102. Assert.AreEqual (2, coll.Count, "#5");
  103. Assert.AreEqual (1, coll.IndexOf (param2), "#6");
  104. }
  105. [Test]
  106. [ExpectedException (typeof (ArgumentNullException))]
  107. public void Add_Null () {
  108. CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
  109. coll.Add ((CodeParameterDeclarationExpression) null);
  110. }
  111. [Test]
  112. public void Insert ()
  113. {
  114. CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression ();
  115. CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression ();
  116. CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
  117. coll.Add (param1);
  118. Assert.AreEqual (1, coll.Count, "#1");
  119. Assert.AreEqual (0, coll.IndexOf (param1), "#2");
  120. coll.Insert (0, param2);
  121. Assert.AreEqual (2, coll.Count, "#3");
  122. Assert.AreEqual (1, coll.IndexOf (param1), "#4");
  123. Assert.AreEqual (0, coll.IndexOf (param2), "#5");
  124. }
  125. [Test]
  126. [ExpectedException (typeof (ArgumentNullException))]
  127. public void Insert_Null ()
  128. {
  129. CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
  130. coll.Insert (0, (CodeParameterDeclarationExpression) null);
  131. }
  132. [Test]
  133. public void AddRange ()
  134. {
  135. CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression ();
  136. CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression ();
  137. CodeParameterDeclarationExpression param3 = new CodeParameterDeclarationExpression ();
  138. CodeParameterDeclarationExpressionCollection coll1 = new CodeParameterDeclarationExpressionCollection ();
  139. coll1.Add (param1);
  140. coll1.Add (param2);
  141. CodeParameterDeclarationExpressionCollection coll2 = new CodeParameterDeclarationExpressionCollection ();
  142. coll2.Add (param3);
  143. coll2.AddRange (coll1);
  144. Assert.AreEqual (3, coll2.Count, "#1");
  145. Assert.AreEqual (1, coll2.IndexOf (param1), "#2");
  146. Assert.AreEqual (2, coll2.IndexOf (param2), "#3");
  147. Assert.AreEqual (0, coll2.IndexOf (param3), "#4");
  148. CodeParameterDeclarationExpressionCollection coll3 = new CodeParameterDeclarationExpressionCollection ();
  149. coll3.Add (param3);
  150. coll3.AddRange (new CodeParameterDeclarationExpression[] { param1, param2 });
  151. Assert.AreEqual (3, coll2.Count, "#5");
  152. Assert.AreEqual (1, coll2.IndexOf (param1), "#6");
  153. Assert.AreEqual (2, coll2.IndexOf (param2), "#7");
  154. Assert.AreEqual (0, coll2.IndexOf (param3), "#8");
  155. }
  156. [Test]
  157. [ExpectedException (typeof (ArgumentNullException))]
  158. public void AddRange_Null_Array ()
  159. {
  160. CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
  161. coll.AddRange ((CodeParameterDeclarationExpression[]) null);
  162. }
  163. [Test]
  164. [ExpectedException (typeof (ArgumentNullException))]
  165. public void AddRange_Null_Item ()
  166. {
  167. CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
  168. coll.AddRange (new CodeParameterDeclarationExpression[] { null });
  169. }
  170. [Test]
  171. [ExpectedException (typeof (ArgumentNullException))]
  172. public void AddRange_Null_Collection ()
  173. {
  174. CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
  175. coll.AddRange ((CodeParameterDeclarationExpressionCollection) null);
  176. }
  177. [Test]
  178. public void AddRange_Self ()
  179. {
  180. CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
  181. coll.Add (new CodeParameterDeclarationExpression ());
  182. Assert.AreEqual (1, coll.Count, "#1");
  183. coll.AddRange (coll);
  184. Assert.AreEqual (2, coll.Count, "#2");
  185. }
  186. [Test]
  187. public void Remove ()
  188. {
  189. CodeParameterDeclarationExpression cpde1 = new CodeParameterDeclarationExpression ();
  190. CodeParameterDeclarationExpression cpde2 = new CodeParameterDeclarationExpression ();
  191. CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
  192. coll.Add (cpde1);
  193. coll.Add (cpde2);
  194. Assert.AreEqual (2, coll.Count, "#1");
  195. Assert.AreEqual (0, coll.IndexOf (cpde1), "#2");
  196. Assert.AreEqual (1, coll.IndexOf (cpde2), "#3");
  197. coll.Remove (cpde1);
  198. Assert.AreEqual (1, coll.Count, "#4");
  199. Assert.AreEqual (-1, coll.IndexOf (cpde1), "#5");
  200. Assert.AreEqual (0, coll.IndexOf (cpde2), "#6");
  201. }
  202. [Test]
  203. [ExpectedException (typeof (ArgumentException))]
  204. public void Remove_NotInCollection ()
  205. {
  206. CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
  207. coll.Remove (new CodeParameterDeclarationExpression ());
  208. }
  209. [Test]
  210. [ExpectedException (typeof (ArgumentNullException))]
  211. public void Remove_Null ()
  212. {
  213. CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
  214. coll.Remove ((CodeParameterDeclarationExpression) null);
  215. }
  216. }
  217. }