// System.Collections.CollectionBase\r
// Test suite for System.Collections.CollectionBase\r
//\r
-// Author:\r
+// Authors:\r
// Nick D. Drochak II\r
+// Gonzalo Paniagua Javier (gonzalo@ximian.com)\r
//\r
// (C) 2001 Nick D. Drochak II\r
+// (c) 2003 Ximian, Inc. (http://www.ximian.com)\r
//\r
\r
\r
{\r
\r
[TestFixture]\r
-public class CollectionBaseTest\r
+public class CollectionBaseTest : Assertion\r
{\r
// We need a concrete class to test the abstract base class\r
public class ConcreteCollection : CollectionBase \r
public bool onSetCompleteFired;\r
public int onSetCompleteOldValue;\r
public int onSetCompleteNewValue;\r
+ public int mustThrowException;\r
+ public bool onValidateFired;\r
\r
// This constructor is used to test OnValid()\r
public ConcreteCollection() \r
}\r
}\r
\r
+ void CheckIfThrow ()\r
+ {\r
+ if (mustThrowException > 0) {\r
+ mustThrowException--;\r
+ if (mustThrowException == 0)\r
+ throw new Exception ();\r
+ }\r
+ }\r
+ \r
// A helper method to look at a value in the list at a specific index\r
public int PeekAt(int index)\r
{\r
return (int) listObj[index];\r
}\r
\r
+ protected override void OnValidate (object value) {\r
+ this.onValidateFired = true;\r
+ CheckIfThrow ();\r
+ base.OnValidate (value);\r
+ }\r
+\r
// Mark the flag if this hook is fired\r
protected override void OnClear() {\r
this.onClearFired = true;\r
+ CheckIfThrow ();\r
}\r
\r
// Mark the flag if this hook is fired\r
protected override void OnClearComplete() \r
{\r
this.onClearCompleteFired = true;\r
+ CheckIfThrow ();\r
}\r
\r
// Mark the flag, and save the paramter if this hook is fired\r
{\r
this.onInsertFired = true;\r
this.onInsertIndex = index;\r
+ CheckIfThrow ();\r
}\r
\r
// Mark the flag, and save the paramter if this hook is fired\r
{\r
this.onInsertCompleteFired = true;\r
this.onInsertCompleteIndex = index;\r
+ CheckIfThrow ();\r
}\r
\r
// Mark the flag, and save the paramter if this hook is fired\r
{\r
this.onRemoveFired = true;\r
this.onRemoveIndex = index;\r
+ CheckIfThrow ();\r
}\r
\r
// Mark the flag, and save the paramter if this hook is fired\r
{\r
this.onRemoveCompleteFired = true;\r
this.onRemoveCompleteIndex = index;\r
+ CheckIfThrow ();\r
}\r
\r
// Mark the flag, and save the paramters if this hook is fired\r
this.onSetFired = true;\r
this.onSetOldValue = (int) oldValue;\r
this.onSetNewValue = (int) newValue;\r
+ CheckIfThrow ();\r
}\r
\r
// Mark the flag, and save the paramters if this hook is fired\r
this.onSetCompleteFired = true;\r
this.onSetCompleteOldValue = (int) oldValue;\r
this.onSetCompleteNewValue = (int) newValue;\r
+ CheckIfThrow ();\r
+ }\r
+\r
+ public IList BaseList {\r
+ get { return base.List; }\r
}\r
} // public class ConcreteCollection\r
\r
public void Count() {\r
ConcreteCollection myCollection;\r
myCollection = new ConcreteCollection(4);\r
- Assertion.Assert(4 == myCollection.Count);\r
+ Assert(4 == myCollection.Count);\r
}\r
\r
// Make sure GetEnumerator returns an object\r
public void GetEnumerator() {\r
ConcreteCollection myCollection;\r
myCollection = new ConcreteCollection(4);\r
- Assertion.Assert(null != myCollection.GetEnumerator());\r
+ Assert(null != myCollection.GetEnumerator());\r
}\r
\r
// OnValid disallows nulls\r
numberOfItems = 3;\r
// The constructor inserts\r
myCollection = new ConcreteCollection(numberOfItems);\r
- Assertion.Assert(myCollection.onInsertFired);\r
- Assertion.Assert(myCollection.onInsertCompleteFired);\r
+ Assert(myCollection.onInsertFired);\r
+ Assert(myCollection.onInsertCompleteFired);\r
\r
// Using the IList interface, check inserts in the middle\r
IList listObj = myCollection;\r
listObj.Insert(1, 9);\r
- Assertion.Assert(myCollection.onInsertIndex == 1);\r
- Assertion.Assert(myCollection.onInsertCompleteIndex == 1);\r
- Assertion.Assert(myCollection.PeekAt(1) == 9);\r
+ Assert(myCollection.onInsertIndex == 1);\r
+ Assert(myCollection.onInsertCompleteIndex == 1);\r
+ Assert(myCollection.PeekAt(1) == 9);\r
}\r
\r
// Test Clear and it's hooks\r
numberOfItems = 1;\r
myCollection = new ConcreteCollection(numberOfItems);\r
myCollection.Clear();\r
- Assertion.Assert(myCollection.Count == 0);\r
- Assertion.Assert(myCollection.onClearFired);\r
- Assertion.Assert(myCollection.onClearCompleteFired);\r
+ Assert(myCollection.Count == 0);\r
+ Assert(myCollection.onClearFired);\r
+ Assert(myCollection.onClearCompleteFired);\r
}\r
\r
// Test RemoveAt, other removes and the hooks\r
myCollection.RemoveAt(1);\r
\r
// We should see the original third one in it's place\r
- Assertion.Assert(myCollection.PeekAt(1) == 2);\r
- Assertion.Assert(myCollection.onRemoveFired);\r
- Assertion.Assert(myCollection.onRemoveIndex == 1);\r
- Assertion.Assert(myCollection.onRemoveCompleteFired);\r
- Assertion.Assert(myCollection.onRemoveCompleteIndex == 1);\r
+ Assert(myCollection.PeekAt(1) == 2);\r
+ Assert(myCollection.onRemoveFired);\r
+ Assert(myCollection.onRemoveIndex == 1);\r
+ Assert(myCollection.onRemoveCompleteFired);\r
+ Assert(myCollection.onRemoveCompleteIndex == 1);\r
IList listObj = myCollection;\r
listObj.Remove(0);\r
// Confirm parameters are being passed to the hooks\r
- Assertion.Assert(myCollection.onRemoveIndex == 0);\r
- Assertion.Assert(myCollection.onRemoveCompleteIndex == 0);\r
+ Assert(myCollection.onRemoveIndex == 0);\r
+ Assert(myCollection.onRemoveCompleteIndex == 0);\r
}\r
\r
// Test the random access feature\r
myCollection = new ConcreteCollection(numberOfItems);\r
IList listObj = myCollection;\r
listObj[0] = 99;\r
- Assertion.Assert((int) listObj[0] == 99);\r
- Assertion.Assert(myCollection.onSetFired);\r
- Assertion.Assert(myCollection.onSetCompleteFired);\r
- Assertion.Assert(myCollection.onSetOldValue == 0);\r
- Assertion.Assert(myCollection.onSetCompleteOldValue == 0);\r
- Assertion.Assert(myCollection.onSetNewValue == 99);\r
- Assertion.Assert(myCollection.onSetCompleteNewValue == 99);\r
+ Assert((int) listObj[0] == 99);\r
+ Assert(myCollection.onSetFired);\r
+ Assert(myCollection.onSetCompleteFired);\r
+ Assert(myCollection.onSetOldValue == 0);\r
+ Assert(myCollection.onSetCompleteOldValue == 0);\r
+ Assert(myCollection.onSetNewValue == 99);\r
+ Assert(myCollection.onSetCompleteNewValue == 99);\r
+ }\r
+\r
+ [Test]\r
+ public void InsertComplete_Add ()\r
+ {\r
+ ConcreteCollection coll = new ConcreteCollection (0);\r
+ coll.mustThrowException = 1;\r
+\r
+ try {\r
+ coll.BaseList.Add (0);\r
+ } catch {\r
+ }\r
+ AssertEquals (0, coll.Count);\r
+ }\r
+\r
+ [Test]\r
+ [ExpectedException (typeof (ArgumentOutOfRangeException))]\r
+ public void ValidateCalled ()\r
+ {\r
+ ConcreteCollection coll = new ConcreteCollection (0);\r
+ coll.mustThrowException = 1;\r
+\r
+ try {\r
+ coll.BaseList [5] = 8888;\r
+ } catch (ArgumentOutOfRangeException) {\r
+ throw;\r
+ } finally {\r
+ AssertEquals (false, coll.onValidateFired);\r
+ }\r
+ }\r
+\r
+ [Test]\r
+ public void SetCompleteCalled ()\r
+ {\r
+ ConcreteCollection coll = new ConcreteCollection (0);\r
+\r
+ coll.BaseList.Add (88);\r
+ coll.mustThrowException = 1;\r
+ try {\r
+ coll.BaseList [0] = 11;\r
+ } catch {\r
+ } finally {\r
+ AssertEquals (false, coll.onSetCompleteFired);\r
+ }\r
}\r
}\r
\r