CodeAttributeArgumentCollectionTest.cs 8.2 KB

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