CodeParameterDeclarationExpressionCollectionTest.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. CodeParameterDeclarationExpressionCollection coll1 = new CodeParameterDeclarationExpressionCollection ();
  138. coll1.Add (param1);
  139. coll1.Add (param2);
  140. CodeParameterDeclarationExpressionCollection coll2 = new CodeParameterDeclarationExpressionCollection(coll1);
  141. Assert.AreEqual (2, coll2.Count, "#1");
  142. Assert.AreEqual (0, coll2.IndexOf (param1), "#2");
  143. Assert.AreEqual (1, coll2.IndexOf (param2), "#3");
  144. CodeParameterDeclarationExpressionCollection coll3 = new CodeParameterDeclarationExpressionCollection(
  145. new CodeParameterDeclarationExpression[] {param1, param2});
  146. Assert.AreEqual (2, coll2.Count, "#4");
  147. Assert.AreEqual (0, coll2.IndexOf (param1), "#5");
  148. Assert.AreEqual (1, coll2.IndexOf (param2), "#6");
  149. }
  150. [Test]
  151. [ExpectedException (typeof (ArgumentNullException))]
  152. public void AddRange_Null_Array ()
  153. {
  154. CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
  155. coll.AddRange ((CodeParameterDeclarationExpression[]) null);
  156. }
  157. [Test]
  158. [ExpectedException (typeof (ArgumentNullException))]
  159. public void AddRange_Null_Collection ()
  160. {
  161. CodeParameterDeclarationExpressionCollection coll = new CodeParameterDeclarationExpressionCollection ();
  162. coll.AddRange ((CodeParameterDeclarationExpressionCollection) null);
  163. }
  164. }
  165. }