| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- //
- // CodeExpressionCollectionTest.cs
- // - Unit tests for System.CodeDom.CodeExpressionCollection
- //
- // Author:
- // Gert Driesen <[email protected]>
- //
- // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using NUnit.Framework;
- using System;
- using System.Collections;
- using System.CodeDom;
- namespace MonoTests.System.CodeDom {
- [TestFixture]
- public class CodeExpressionCollectionTest {
- [Test]
- public void Constructor0 ()
- {
- CodeExpressionCollection coll = new CodeExpressionCollection ();
- Assert.IsFalse (((IList) coll).IsFixedSize, "#1");
- Assert.IsFalse (((IList) coll).IsReadOnly, "#2");
- Assert.AreEqual (0, coll.Count, "#3");
- Assert.IsFalse (((ICollection) coll).IsSynchronized, "#4");
- }
- [Test]
- public void Constructor1 ()
- {
- CodeExpression exp1 = new CodeExpression ();
- CodeExpression exp2 = new CodeExpression ();
- CodeExpression[] expressions = new CodeExpression[] { exp1, exp2 };
- CodeExpressionCollection coll = new CodeExpressionCollection (
- expressions);
- Assert.AreEqual (2, coll.Count, "#1");
- Assert.AreEqual (0, coll.IndexOf (exp1), "#2");
- Assert.AreEqual (1, coll.IndexOf (exp2), "#3");
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void Constructor1_NullItem ()
- {
- CodeExpression[] expressions = new CodeExpression[] {
- new CodeExpression (), null };
- CodeExpressionCollection coll = new CodeExpressionCollection (
- expressions);
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void Constructor1_Null () {
- CodeExpressionCollection coll = new CodeExpressionCollection (
- (CodeExpression[]) null);
- }
- [Test]
- public void Constructor2 ()
- {
- CodeExpression exp1 = new CodeExpression ();
- CodeExpression exp2 = new CodeExpression ();
- CodeExpressionCollection c = new CodeExpressionCollection ();
- c.Add (exp1);
- c.Add (exp2);
- CodeExpressionCollection coll = new CodeExpressionCollection (c);
- Assert.AreEqual (2, coll.Count, "#1");
- Assert.AreEqual (0, coll.IndexOf (exp1), "#2");
- Assert.AreEqual (1, coll.IndexOf (exp2), "#3");
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void Constructor2_Null ()
- {
- CodeExpressionCollection coll = new CodeExpressionCollection (
- (CodeExpressionCollection) null);
- }
- [Test]
- public void Add ()
- {
- CodeExpression exp1 = new CodeExpression ();
- CodeExpression exp2 = new CodeExpression ();
- CodeExpressionCollection coll = new CodeExpressionCollection ();
- Assert.AreEqual (0, coll.Add (exp1), "#1");
- Assert.AreEqual (1, coll.Count, "#2");
- Assert.AreEqual (0, coll.IndexOf (exp1), "#3");
- Assert.AreEqual (1, coll.Add (exp2), "#4");
- Assert.AreEqual (2, coll.Count, "#5");
- Assert.AreEqual (1, coll.IndexOf (exp2), "#6");
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void Add_Null () {
- CodeExpressionCollection coll = new CodeExpressionCollection ();
- coll.Add ((CodeExpression) null);
- }
- [Test]
- public void Insert ()
- {
- CodeExpression exp1 = new CodeExpression ();
- CodeExpression exp2 = new CodeExpression ();
- CodeExpressionCollection coll = new CodeExpressionCollection ();
- coll.Add (exp1);
- Assert.AreEqual (1, coll.Count, "#1");
- Assert.AreEqual (0, coll.IndexOf (exp1), "#2");
- coll.Insert (0, exp2);
- Assert.AreEqual (2, coll.Count, "#3");
- Assert.AreEqual (1, coll.IndexOf (exp1), "#4");
- Assert.AreEqual (0, coll.IndexOf (exp2), "#5");
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void Insert_Null ()
- {
- CodeExpressionCollection coll = new CodeExpressionCollection ();
- coll.Insert (0, (CodeExpression) null);
- }
- [Test]
- public void AddRange ()
- {
- CodeExpression exp1 = new CodeExpression ();
- CodeExpression exp2 = new CodeExpression ();
- CodeExpressionCollection coll1 = new CodeExpressionCollection ();
- coll1.Add (exp1);
- coll1.Add (exp2);
- CodeExpressionCollection coll2 = new CodeExpressionCollection(coll1);
- Assert.AreEqual (2, coll2.Count, "#1");
- Assert.AreEqual (0, coll2.IndexOf (exp1), "#2");
- Assert.AreEqual (1, coll2.IndexOf (exp2), "#3");
- CodeExpressionCollection coll3 = new CodeExpressionCollection(
- new CodeExpression[] {exp1, exp2});
- Assert.AreEqual (2, coll2.Count, "#4");
- Assert.AreEqual (0, coll2.IndexOf (exp1), "#5");
- Assert.AreEqual (1, coll2.IndexOf (exp2), "#6");
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void AddRange_Null_Array ()
- {
- CodeExpressionCollection coll = new CodeExpressionCollection ();
- coll.AddRange ((CodeExpression[]) null);
- }
- [Test]
- [ExpectedException (typeof (ArgumentNullException))]
- public void AddRange_Null_Collection ()
- {
- CodeExpressionCollection coll = new CodeExpressionCollection ();
- coll.AddRange ((CodeExpressionCollection) null);
- }
- [Test]
- public void AddRange_Self ()
- {
- CodeExpressionCollection coll = new CodeExpressionCollection ();
- coll.AddRange (coll);
- Assert.AreEqual (0, coll.Count, "0");
- }
- }
- }
|