Replaced all ExpectedExceptionAttributes with the new Assert.Throws<>() method to work around a compatibility issue between TeamCity 4.5 and NUnit 2.5 Final

git-svn-id: file:///srv/devel/repo-conversion/nusu@137 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2009-05-07 19:36:27 +00:00
parent 06749b9cbb
commit d0fe47239e
20 changed files with 399 additions and 215 deletions

View file

@ -228,10 +228,11 @@ namespace Nuclex.Support.Collections {
/// Tests whether an exception is thrown if the indexer of the observable dictionary
/// is used to attempt to retrieve a non-existing value
/// </summary>
[Test, ExpectedException(typeof(KeyNotFoundException))]
public void TestThrowOnRetrieveNonExistingValueByIndexer() {
string numberName = this.observedDictionary[24];
Console.WriteLine(numberName);
[Test]
public void TestRetrieveNonExistingValueByIndexer() {
Assert.Throws<KeyNotFoundException>(
delegate() { Console.WriteLine(this.observedDictionary[24]); }
);
}
/// <summary>

View file

@ -100,33 +100,39 @@ namespace Nuclex.Support.Collections {
/// Tests whether the priority queue's enumerators are invalidated when the queue's
/// contents are modified
/// </summary>
[Test, ExpectedException(typeof(InvalidOperationException))]
[Test]
public void TestEnumeratorInvalidationOnModify() {
PriorityQueue<int> testQueue = new PriorityQueue<int>();
IEnumerator<int> testQueueEnumerator = testQueue.GetEnumerator();
testQueue.Enqueue(123);
testQueueEnumerator.MoveNext();
Assert.Throws<InvalidOperationException>(
delegate() { testQueueEnumerator.MoveNext(); }
);
}
#endif
/// <summary>
/// Verifies that an exception is thrown when Peek() is called on an empty queue
/// </summary>
[Test, ExpectedException(typeof(InvalidOperationException))]
[Test]
public void TestPeekEmptyQueue() {
PriorityQueue<int> testQueue = new PriorityQueue<int>();
testQueue.Peek();
Assert.Throws<InvalidOperationException>(
delegate() { testQueue.Peek(); }
);
}
/// <summary>
/// Verifies that an exception is thrown when Dequeue() is called on an empty queue
/// </summary>
[Test, ExpectedException(typeof(InvalidOperationException))]
[Test]
public void TestDequeueEmptyQueue() {
PriorityQueue<int> testQueue = new PriorityQueue<int>();
testQueue.Dequeue();
Assert.Throws<InvalidOperationException>(
delegate() { testQueue.Dequeue(); }
);
}
/// <summary>

View file

@ -81,28 +81,34 @@ namespace Nuclex.Support.Collections {
/// <summary>
/// Ensures that the Add() method of the read only collection throws an exception
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnAdd() {
ReadOnlyCollection<int> testCollection = new ReadOnlyCollection<int>(new int[0]);
(testCollection as ICollection<int>).Add(123);
Assert.Throws<NotSupportedException>(
delegate() { (testCollection as ICollection<int>).Add(123); }
);
}
/// <summary>
/// Ensures that the Remove() method of the read only collection throws an exception
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnRemove() {
ReadOnlyCollection<int> testCollection = new ReadOnlyCollection<int>(new int[0]);
(testCollection as ICollection<int>).Remove(123);
Assert.Throws<NotSupportedException>(
delegate() { (testCollection as ICollection<int>).Remove(123); }
);
}
/// <summary>
/// Ensures that the Clear() method of the read only collection throws an exception
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnClear() {
ReadOnlyCollection<int> testCollection = new ReadOnlyCollection<int>(new int[0]);
(testCollection as ICollection<int>).Clear();
Assert.Throws<NotSupportedException>(
delegate() { (testCollection as ICollection<int>).Clear(); }
);
}
/// <summary>
@ -118,7 +124,7 @@ namespace Nuclex.Support.Collections {
outputIntegers.Add(value);
}
CollectionAssert.AreEqual(inputIntegers, outputIntegers);
CollectionAssert.AreEqual(inputIntegers, outputIntegers);
}
/// <summary>

View file

@ -174,37 +174,42 @@ namespace Nuclex.Support.Collections {
/// Tests whether an exception is thrown if the indexer of the read only dictionary
/// is used to attempt to retrieve a non-existing value
/// </summary>
[Test, ExpectedException(typeof(KeyNotFoundException))]
[Test]
public void TestThrowOnRetrieveNonExistingValueByIndexer() {
Dictionary<int, string> numbers = createTestDictionary();
ReadOnlyDictionary<int, string> testDictionary = makeReadOnly(numbers);
string numberName = testDictionary[24];
Console.WriteLine(numberName);
Assert.Throws<KeyNotFoundException>(
delegate() { Console.WriteLine(testDictionary[24]); }
);
}
/// <summary>
/// Checks whether the read only dictionary will throw an exception if its
/// Add() method is called via the generic IDictionary&lt;&gt; interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnAddViaGenericIDictionary() {
Dictionary<int, string> numbers = createTestDictionary();
ReadOnlyDictionary<int, string> testDictionary = makeReadOnly(numbers);
(testDictionary as IDictionary<int, string>).Add(10, "ten");
Assert.Throws<NotSupportedException>(
delegate() { (testDictionary as IDictionary<int, string>).Add(10, "ten"); }
);
}
/// <summary>
/// Checks whether the read only dictionary will throw an exception if its
/// Remove() method is called via the generic IDictionary&lt;&gt; interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnRemoveViaGenericIDictionary() {
Dictionary<int, string> numbers = createTestDictionary();
ReadOnlyDictionary<int, string> testDictionary = makeReadOnly(numbers);
(testDictionary as IDictionary<int, string>).Remove(3);
Assert.Throws<NotSupportedException>(
delegate() { (testDictionary as IDictionary<int, string>).Remove(3); }
);
}
/// <summary>
@ -222,36 +227,42 @@ namespace Nuclex.Support.Collections {
/// Checks whether the read only dictionary will throw an exception if its
/// indexer is used to insert an item via the generic IDictionar&lt;&gt; interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnReplaceByIndexerViaGenericIDictionary() {
Dictionary<int, string> numbers = createTestDictionary();
ReadOnlyDictionary<int, string> testDictionary = makeReadOnly(numbers);
(testDictionary as IDictionary<int, string>)[24] = "twenty-four";
Assert.Throws<NotSupportedException>(
delegate() { (testDictionary as IDictionary<int, string>)[24] = "twenty-four"; }
);
}
/// <summary>
/// Checks whether the read only dictionary will throw an exception if its
/// Clear() method is called via the IDictionary interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnClearViaIDictionary() {
Dictionary<int, string> numbers = createTestDictionary();
ReadOnlyDictionary<int, string> testDictionary = makeReadOnly(numbers);
(testDictionary as IDictionary).Clear();
Assert.Throws<NotSupportedException>(
delegate() { (testDictionary as IDictionary).Clear(); }
);
}
/// <summary>
/// Checks whether the read only dictionary will throw an exception if its
/// Add() method is called via the IDictionary interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnAddViaIDictionary() {
Dictionary<int, string> numbers = createTestDictionary();
ReadOnlyDictionary<int, string> testDictionary = makeReadOnly(numbers);
(testDictionary as IDictionary).Add(24, "twenty-four");
Assert.Throws<NotSupportedException>(
delegate() { (testDictionary as IDictionary).Add(24, "twenty-four"); }
);
}
/// <summary>
@ -328,12 +339,14 @@ namespace Nuclex.Support.Collections {
/// Checks whether the read only dictionary will throw an exception if its
/// Remove() method is called via the IDictionary interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnRemoveViaIDictionary() {
Dictionary<int, string> numbers = createTestDictionary();
ReadOnlyDictionary<int, string> testDictionary = makeReadOnly(numbers);
(testDictionary as IDictionary).Remove(3);
Assert.Throws<NotSupportedException>(
delegate() { (testDictionary as IDictionary).Remove(3); }
);
}
/// <summary>
@ -352,25 +365,31 @@ namespace Nuclex.Support.Collections {
/// Checks whether the read only dictionary will throw an exception if its
/// indexer is used to insert an item via the IDictionary interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnReplaceByIndexerViaIDictionary() {
Dictionary<int, string> numbers = createTestDictionary();
ReadOnlyDictionary<int, string> testDictionary = makeReadOnly(numbers);
(testDictionary as IDictionary)[24] = "twenty-four";
Assert.Throws<NotSupportedException>(
delegate() { (testDictionary as IDictionary)[24] = "twenty-four"; }
);
}
/// <summary>
/// Checks whether the read only dictionary will throw an exception if its
/// Add() method is used via the generic ICollection&lt;&gt; interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnAddViaGenericICollection() {
Dictionary<int, string> numbers = createTestDictionary();
ReadOnlyDictionary<int, string> testDictionary = makeReadOnly(numbers);
(testDictionary as ICollection<KeyValuePair<int, string>>).Add(
new KeyValuePair<int, string>(24, "twenty-four")
Assert.Throws<NotSupportedException>(
delegate() {
(testDictionary as ICollection<KeyValuePair<int, string>>).Add(
new KeyValuePair<int, string>(24, "twenty-four")
);
}
);
}
@ -378,25 +397,31 @@ namespace Nuclex.Support.Collections {
/// Checks whether the read only dictionary will throw an exception if its
/// Clear() method is used via the generic ICollection&lt;&gt; interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnClearViaGenericICollection() {
Dictionary<int, string> numbers = createTestDictionary();
ReadOnlyDictionary<int, string> testDictionary = makeReadOnly(numbers);
(testDictionary as ICollection<KeyValuePair<int, string>>).Clear();
Assert.Throws<NotSupportedException>(
delegate() { (testDictionary as ICollection<KeyValuePair<int, string>>).Clear(); }
);
}
/// <summary>
/// Checks whether the read only dictionary will throw an exception if its
/// Remove() method is used via the generic ICollection&lt;&gt; interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnRemoveViaGenericICollection() {
Dictionary<int, string> numbers = createTestDictionary();
ReadOnlyDictionary<int, string> testDictionary = makeReadOnly(numbers);
(testDictionary as ICollection<KeyValuePair<int, string>>).Remove(
new KeyValuePair<int, string>(42, "fourty-two")
Assert.Throws<NotSupportedException>(
delegate() {
(testDictionary as ICollection<KeyValuePair<int, string>>).Remove(
new KeyValuePair<int, string>(42, "fourty-two")
);
}
);
}

View file

@ -112,20 +112,24 @@ namespace Nuclex.Support.Collections {
/// Checks whether the read only list will throw an exception if its Insert() method
/// is called via the generic IList&lt;&gt; interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnInsertViaGenericIList() {
ReadOnlyList<int> testList = new ReadOnlyList<int>(new int[0]);
(testList as IList<int>).Insert(0, 12345);
Assert.Throws<NotSupportedException>(
delegate() { (testList as IList<int>).Insert(0, 12345); }
);
}
/// <summary>
/// Checks whether the read only list will throw an exception if its RemoveAt() method
/// is called via the generic IList&lt;&gt; interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnRemoveViaGenericIList() {
ReadOnlyList<int> testList = new ReadOnlyList<int>(new int[1]);
(testList as IList<int>).RemoveAt(0);
Assert.Throws<NotSupportedException>(
delegate() { (testList as IList<int>).RemoveAt(0); }
);
}
/// <summary>
@ -147,43 +151,51 @@ namespace Nuclex.Support.Collections {
/// Checks whether the indexer method of the read only list will throw an exception
/// if it is attempted to be used for replacing an item
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnReplaceByIndexerViaGenericIList() {
ReadOnlyList<int> testList = new ReadOnlyList<int>(new int[1]);
(testList as IList<int>)[0] = 12345;
Assert.Throws<NotSupportedException>(
delegate() { (testList as IList<int>)[0] = 12345; }
);
}
/// <summary>
/// Checks whether the read only list will throw an exception if its Add() method
/// is called via the generic ICollection&lt;&gt; interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnAddViaGenericICollection() {
ReadOnlyList<int> testList = new ReadOnlyList<int>(new int[0]);
(testList as ICollection<int>).Add(12345);
Assert.Throws<NotSupportedException>(
delegate() { (testList as ICollection<int>).Add(12345); }
);
}
/// <summary>
/// Checks whether the read only list will throw an exception if its Clear() method
/// is called via the generic ICollection&lt;&gt; interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnClearViaGenericICollection() {
ReadOnlyList<int> testList = new ReadOnlyList<int>(new int[1]);
(testList as ICollection<int>).Clear();
Assert.Throws<NotSupportedException>(
delegate() { (testList as ICollection<int>).Clear(); }
);
}
/// <summary>
/// Checks whether the read only list will throw an exception if its Remove() method
/// is called via the generic ICollection&lt;&gt; interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnRemoveViaGenericICollection() {
int[] integers = new int[] { 12, 34, 67, 89 };
ReadOnlyList<int> testList = new ReadOnlyList<int>(integers);
(testList as ICollection<int>).Remove(89);
Assert.Throws<NotSupportedException>(
delegate() { (testList as ICollection<int>).Remove(89); }
);
}
/// <summary>
@ -206,20 +218,24 @@ namespace Nuclex.Support.Collections {
/// Checks whether the read only list will throw an exception if its Clear() method
/// is called via the IList interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnClearViaIList() {
ReadOnlyList<int> testList = new ReadOnlyList<int>(new int[1]);
(testList as IList).Clear();
Assert.Throws<NotSupportedException>(
delegate() { (testList as IList).Clear(); }
);
}
/// <summary>
/// Checks whether the read only list will throw an exception if its Add() method
/// is called via the IList interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnAddViaIList() {
ReadOnlyList<int> testList = new ReadOnlyList<int>(new int[0]);
(testList as IList).Add(12345);
Assert.Throws<NotSupportedException>(
delegate() { (testList as IList).Add(12345); }
);
}
/// <summary>
@ -254,10 +270,12 @@ namespace Nuclex.Support.Collections {
/// Checks whether the read only list will throw an exception if its Insert() method
/// is called via the IList interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnInsertViaIList() {
ReadOnlyList<int> testList = new ReadOnlyList<int>(new int[0]);
(testList as IList).Insert(0, 12345);
Assert.Throws<NotSupportedException>(
delegate() { (testList as IList).Insert(0, 12345); }
);
}
/// <summary>
@ -276,23 +294,27 @@ namespace Nuclex.Support.Collections {
/// Checks whether the read only list will throw an exception if its Remove() method
/// is called via the IList interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnRemoveViaIList() {
int[] integers = new int[] { 1234, 6789 };
ReadOnlyList<int> testList = new ReadOnlyList<int>(integers);
(testList as IList).Remove(6789);
Assert.Throws<NotSupportedException>(
delegate() { (testList as IList).Remove(6789); }
);
}
/// <summary>
/// Checks whether the read only list will throw an exception if its Remove() method
/// is called via the IList interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnRemoveAtViaIList() {
ReadOnlyList<int> testList = new ReadOnlyList<int>(new int[1]);
(testList as IList).RemoveAt(0);
Assert.Throws<NotSupportedException>(
delegate() { (testList as IList).RemoveAt(0); }
);
}
/// <summary>
@ -314,11 +336,13 @@ namespace Nuclex.Support.Collections {
/// Checks whether the indexer method of the read only list will throw an exception
/// if it is attempted to be used for replacing an item
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnReplaceByIndexerViaIList() {
ReadOnlyList<int> testList = new ReadOnlyList<int>(new int[1]);
(testList as IList)[0] = 12345;
Assert.Throws<NotSupportedException>(
delegate() { (testList as IList)[0] = 12345; }
);
}
/// <summary>

View file

@ -102,13 +102,15 @@ namespace Nuclex.Support.Collections {
/// Verifies that the CopyTo() method of the transforming read only collection throws
/// an exception if the target array is too small to hold the collection's contents
/// </summary>
[Test, ExpectedException(typeof(ArgumentException))]
[Test]
public void TestThrowOnCopyToTooSmallArray() {
int[] inputIntegers = new int[] { 12, 34, 56, 78 };
StringTransformer testCollection = new StringTransformer(inputIntegers);
string[] outputStrings = new string[testCollection.Count - 1];
testCollection.CopyTo(outputStrings, 0);
Assert.Throws<ArgumentException>(
delegate() { testCollection.CopyTo(outputStrings, 0); }
);
}
/// <summary>
@ -203,20 +205,24 @@ namespace Nuclex.Support.Collections {
/// Checks whether the transforming read only collection will throw an exception
/// if its Insert() method is called via the generic IList&lt;&gt; interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnInsertViaGenericIList() {
StringTransformer testCollection = new StringTransformer(new int[0]);
(testCollection as IList<string>).Insert(0, "12345");
Assert.Throws<NotSupportedException>(
delegate() { (testCollection as IList<string>).Insert(0, "12345"); }
);
}
/// <summary>
/// Checks whether the transforming read only collection will throw an exception
/// if its RemoveAt() method is called via the generic IList&lt;&gt; interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnRemoveViaGenericIList() {
StringTransformer testCollection = new StringTransformer(new int[1]);
(testCollection as IList<string>).RemoveAt(0);
Assert.Throws<NotSupportedException>(
delegate() { (testCollection as IList<string>).RemoveAt(0); }
);
}
/// <summary>
@ -238,43 +244,51 @@ namespace Nuclex.Support.Collections {
/// Checks whether the indexer method of the transforming read only collection
/// will throw an exception if it is attempted to be used for replacing an item
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnReplaceByIndexerViaGenericIList() {
StringTransformer testCollection = new StringTransformer(new int[1]);
(testCollection as IList<string>)[0] = "12345";
Assert.Throws<NotSupportedException>(
delegate() { (testCollection as IList<string>)[0] = "12345"; }
);
}
/// <summary>
/// Checks whether the transforming read only collection will throw an exception
/// if its Add() method is called via the generic ICollection&lt;&gt; interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnAddViaGenericICollection() {
StringTransformer testCollection = new StringTransformer(new int[0]);
(testCollection as ICollection<string>).Add("12345");
Assert.Throws<NotSupportedException>(
delegate() { (testCollection as ICollection<string>).Add("12345"); }
);
}
/// <summary>
/// Checks whether the transforming read only collection will throw an exception
/// if its Clear() method is called via the generic ICollection&lt;&gt; interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnClearViaGenericICollection() {
StringTransformer testCollection = new StringTransformer(new int[1]);
(testCollection as ICollection<string>).Clear();
Assert.Throws<NotSupportedException>(
delegate() { (testCollection as ICollection<string>).Clear(); }
);
}
/// <summary>
/// Checks whether the transforming read only collection will throw an exception
/// if its Remove() method is called via the generic ICollection&lt;&gt; interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnRemoveViaGenericICollection() {
int[] integers = new int[] { 12, 34, 67, 89 };
StringTransformer testCollection = new StringTransformer(integers);
(testCollection as ICollection<string>).Remove("89");
Assert.Throws<NotSupportedException>(
delegate() { (testCollection as ICollection<string>).Remove("89"); }
);
}
/// <summary>
@ -298,20 +312,24 @@ namespace Nuclex.Support.Collections {
/// Checks whether the transforming read only collection will throw an exception
/// if its Clear() method is called via the IList interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnClearViaIList() {
StringTransformer testCollection = new StringTransformer(new int[1]);
(testCollection as IList).Clear();
Assert.Throws<NotSupportedException>(
delegate() { (testCollection as IList).Clear(); }
);
}
/// <summary>
/// Checks whether the transforming read only collection will throw an exception
/// if its Add() method is called via the IList interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnAddViaIList() {
StringTransformer testCollection = new StringTransformer(new int[0]);
(testCollection as IList).Add("12345");
Assert.Throws<NotSupportedException>(
delegate() { (testCollection as IList).Add("12345"); }
);
}
/// <summary>
@ -346,10 +364,12 @@ namespace Nuclex.Support.Collections {
/// Checks whether the transforming read only collection will throw an exception
/// if its Insert() method is called via the IList interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnInsertViaIList() {
StringTransformer testCollection = new StringTransformer(new int[0]);
(testCollection as IList).Insert(0, "12345");
Assert.Throws<NotSupportedException>(
delegate() { (testCollection as IList).Insert(0, "12345"); }
);
}
/// <summary>
@ -369,23 +389,27 @@ namespace Nuclex.Support.Collections {
/// Checks whether the transforming read only collection will throw an exception
/// if its Remove() method is called via the IList interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnRemoveViaIList() {
int[] integers = new int[] { 1234, 6789 };
StringTransformer testCollection = new StringTransformer(integers);
(testCollection as IList).Remove("6789");
Assert.Throws<NotSupportedException>(
delegate() { (testCollection as IList).Remove("6789"); }
);
}
/// <summary>
/// Checks whether the transforming read only collection will throw an exception
/// if its Remove() method is called via the IList interface
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnRemoveAtViaIList() {
StringTransformer testCollection = new StringTransformer(new int[1]);
(testCollection as IList).RemoveAt(0);
Assert.Throws<NotSupportedException>(
delegate() { (testCollection as IList).RemoveAt(0); }
);
}
/// <summary>
@ -407,11 +431,13 @@ namespace Nuclex.Support.Collections {
/// Checks whether the indexer method of the transforming read only collection
/// will throw an exception if it is attempted to be used for replacing an item
/// </summary>
[Test, ExpectedException(typeof(NotSupportedException))]
[Test]
public void TestThrowOnReplaceByIndexerViaIList() {
StringTransformer testCollection = new StringTransformer(new int[1]);
(testCollection as IList)[0] = "12345";
Assert.Throws<NotSupportedException>(
delegate() { (testCollection as IList)[0] = "12345"; }
);
}
/// <summary>

View file

@ -104,13 +104,15 @@ namespace Nuclex.Support.Collections {
/// Test whether the non-typesafe Add() method throws an exception if an object is
/// added that is not compatible to the collection's item type
/// </summary>
[Test, ExpectedException(typeof(ArgumentException))]
[Test]
public void TestThrowOnAddIncompatibleObject() {
WeakCollection<Dummy> dummies = new WeakCollection<Dummy>(
new List<WeakReference<Dummy>>()
);
(dummies as IList).Add(new object());
Assert.Throws<ArgumentException>(
delegate() { (dummies as IList).Add(new object()); }
);
}
/// <summary>
@ -243,13 +245,15 @@ namespace Nuclex.Support.Collections {
/// Verifies that an exception is thrown if an incompatible object is passed to
/// the non-typesafe variant of the IndexOf() method
/// </summary>
[Test, ExpectedException(typeof(ArgumentException))]
[Test]
public void TestThrowOnIndexOfWithIncompatibleObject() {
WeakCollection<Dummy> dummies = new WeakCollection<Dummy>(
new List<WeakReference<Dummy>>()
);
Assert.IsNull((dummies as IList).IndexOf(new object()));
Assert.Throws<ArgumentException>(
delegate() { Assert.IsNull((dummies as IList).IndexOf(new object())); }
);
}
/// <summary>Test whether the IndexOf() method can cope with null references</summary>
@ -289,7 +293,7 @@ namespace Nuclex.Support.Collections {
/// Verifies that the CopyTo() method of the weak collection throws an exception
/// if the target array is too small to hold the collection's contents
/// </summary>
[Test, ExpectedException(typeof(ArgumentException))]
[Test]
public void TestThrowOnCopyToTooSmallArray() {
WeakCollection<Dummy> dummies = new WeakCollection<Dummy>(
new List<WeakReference<Dummy>>()
@ -300,7 +304,9 @@ namespace Nuclex.Support.Collections {
dummies.Add(fourFiveSixDummy);
Dummy[] outputStrings = new Dummy[dummies.Count - 1];
dummies.CopyTo(outputStrings, 0);
Assert.Throws<ArgumentException>(
delegate() { dummies.CopyTo(outputStrings, 0); }
);
}
/// <summary>
@ -368,7 +374,7 @@ namespace Nuclex.Support.Collections {
/// Verifies that the non-typesafe Insert() method correctly shifts items in
/// the collection
/// </summary>
[Test, ExpectedException(typeof(ArgumentException))]
[Test]
public void TestThrowOnInsertIncompatibleObject() {
WeakCollection<Dummy> dummies = new WeakCollection<Dummy>(
new List<WeakReference<Dummy>>()
@ -377,7 +383,9 @@ namespace Nuclex.Support.Collections {
dummies.Add(oneTwoThreeDummy);
Dummy fourFiveSixDummy = new Dummy(456);
(dummies as IList).Insert(0, new object());
Assert.Throws<ArgumentException>(
delegate() { (dummies as IList).Insert(0, new object()); }
);
}
/// <summary>
@ -476,7 +484,7 @@ namespace Nuclex.Support.Collections {
/// Tests whether the non-typesafe indexer of the weak collection throws
/// the correct exception if an incompatible object is assigned
/// </summary>
[Test, ExpectedException(typeof(ArgumentException))]
[Test]
public void TestThrowOnIndexerWithIncompatibleObject() {
WeakCollection<Dummy> dummies = new WeakCollection<Dummy>(
new List<WeakReference<Dummy>>()
@ -484,7 +492,9 @@ namespace Nuclex.Support.Collections {
Dummy oneTwoThreeDummy = new Dummy(123);
dummies.Add(oneTwoThreeDummy);
(dummies as IList)[0] = new object();
Assert.Throws<ArgumentException>(
delegate() { (dummies as IList)[0] = new object(); }
);
}
/// <summary>Tests the Remove() method of the weak collection</summary>
@ -540,12 +550,14 @@ namespace Nuclex.Support.Collections {
/// an exception if an object is tried to be removed that is incompatible with
/// the collection's item type
/// </summary>
[Test, ExpectedException(typeof(ArgumentException))]
[Test]
public void TestThrowOnRemoveIncompatibleObject() {
WeakCollection<Dummy> dummies = new WeakCollection<Dummy>(
new List<WeakReference<Dummy>>()
);
(dummies as IList).Remove(new object());
Assert.Throws<ArgumentException>(
delegate() { (dummies as IList).Remove(new object()); }
);
}
/// <summary>Tests the RemoveAt() method of the weak collection</summary>