From d0fe47239ec2bef5f131d78b08753206ee35b922 Mon Sep 17 00:00:00 2001 From: Markus Ewald Date: Thu, 7 May 2009 19:36:27 +0000 Subject: [PATCH] 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 --- .../Collections/ObservableDictionary.Test.cs | 9 ++- Source/Collections/PriorityQueue.Test.cs | 20 +++-- Source/Collections/ReadOnlyCollection.Test.cs | 20 +++-- Source/Collections/ReadOnlyDictionary.Test.cs | 77 +++++++++++------- Source/Collections/ReadOnlyList.Test.cs | 72 +++++++++++------ .../TransformingReadOnlyCollection.Test.cs | 78 ++++++++++++------- Source/Collections/WeakCollection.Test.cs | 36 ++++++--- Source/IO/ChainStream.Test.cs | 50 +++++++----- Source/IO/PartialStream.Test.cs | 59 ++++++++------ Source/IO/RingMemoryStream.Test.cs | 43 ++++++---- Source/Licensing/LicenseKey.Test.cs | 19 +++-- Source/Plugins/FactoryEmployer.Test.cs | 12 ++- Source/Plugins/InstanceEmployer.Test.cs | 12 ++- Source/Scheduling/OperationQueue.Test.cs | 8 +- .../ThreadCallbackOperation.Test.cs | 12 ++- Source/Scheduling/ThreadOperation.Test.cs | 12 ++- Source/StringSegment.Test.cs | 51 +++++++----- Source/Tracking/ProgressTracker.Test.cs | 6 +- Source/Tracking/Request.Test.cs | 12 ++- Source/Tracking/Transaction.Test.cs | 6 +- 20 files changed, 399 insertions(+), 215 deletions(-) diff --git a/Source/Collections/ObservableDictionary.Test.cs b/Source/Collections/ObservableDictionary.Test.cs index 6b932f6..befd74b 100644 --- a/Source/Collections/ObservableDictionary.Test.cs +++ b/Source/Collections/ObservableDictionary.Test.cs @@ -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 /// - [Test, ExpectedException(typeof(KeyNotFoundException))] - public void TestThrowOnRetrieveNonExistingValueByIndexer() { - string numberName = this.observedDictionary[24]; - Console.WriteLine(numberName); + [Test] + public void TestRetrieveNonExistingValueByIndexer() { + Assert.Throws( + delegate() { Console.WriteLine(this.observedDictionary[24]); } + ); } /// diff --git a/Source/Collections/PriorityQueue.Test.cs b/Source/Collections/PriorityQueue.Test.cs index 3b3871e..fd70b80 100644 --- a/Source/Collections/PriorityQueue.Test.cs +++ b/Source/Collections/PriorityQueue.Test.cs @@ -100,33 +100,39 @@ namespace Nuclex.Support.Collections { /// Tests whether the priority queue's enumerators are invalidated when the queue's /// contents are modified /// - [Test, ExpectedException(typeof(InvalidOperationException))] + [Test] public void TestEnumeratorInvalidationOnModify() { PriorityQueue testQueue = new PriorityQueue(); IEnumerator testQueueEnumerator = testQueue.GetEnumerator(); testQueue.Enqueue(123); - - testQueueEnumerator.MoveNext(); + + Assert.Throws( + delegate() { testQueueEnumerator.MoveNext(); } + ); } #endif /// /// Verifies that an exception is thrown when Peek() is called on an empty queue /// - [Test, ExpectedException(typeof(InvalidOperationException))] + [Test] public void TestPeekEmptyQueue() { PriorityQueue testQueue = new PriorityQueue(); - testQueue.Peek(); + Assert.Throws( + delegate() { testQueue.Peek(); } + ); } /// /// Verifies that an exception is thrown when Dequeue() is called on an empty queue /// - [Test, ExpectedException(typeof(InvalidOperationException))] + [Test] public void TestDequeueEmptyQueue() { PriorityQueue testQueue = new PriorityQueue(); - testQueue.Dequeue(); + Assert.Throws( + delegate() { testQueue.Dequeue(); } + ); } /// diff --git a/Source/Collections/ReadOnlyCollection.Test.cs b/Source/Collections/ReadOnlyCollection.Test.cs index a65afe4..cb6c26c 100644 --- a/Source/Collections/ReadOnlyCollection.Test.cs +++ b/Source/Collections/ReadOnlyCollection.Test.cs @@ -81,28 +81,34 @@ namespace Nuclex.Support.Collections { /// /// Ensures that the Add() method of the read only collection throws an exception /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnAdd() { ReadOnlyCollection testCollection = new ReadOnlyCollection(new int[0]); - (testCollection as ICollection).Add(123); + Assert.Throws( + delegate() { (testCollection as ICollection).Add(123); } + ); } /// /// Ensures that the Remove() method of the read only collection throws an exception /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnRemove() { ReadOnlyCollection testCollection = new ReadOnlyCollection(new int[0]); - (testCollection as ICollection).Remove(123); + Assert.Throws( + delegate() { (testCollection as ICollection).Remove(123); } + ); } /// /// Ensures that the Clear() method of the read only collection throws an exception /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnClear() { ReadOnlyCollection testCollection = new ReadOnlyCollection(new int[0]); - (testCollection as ICollection).Clear(); + Assert.Throws( + delegate() { (testCollection as ICollection).Clear(); } + ); } /// @@ -118,7 +124,7 @@ namespace Nuclex.Support.Collections { outputIntegers.Add(value); } - CollectionAssert.AreEqual(inputIntegers, outputIntegers); + CollectionAssert.AreEqual(inputIntegers, outputIntegers); } /// diff --git a/Source/Collections/ReadOnlyDictionary.Test.cs b/Source/Collections/ReadOnlyDictionary.Test.cs index 4f3d363..1083b44 100644 --- a/Source/Collections/ReadOnlyDictionary.Test.cs +++ b/Source/Collections/ReadOnlyDictionary.Test.cs @@ -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 /// - [Test, ExpectedException(typeof(KeyNotFoundException))] + [Test] public void TestThrowOnRetrieveNonExistingValueByIndexer() { Dictionary numbers = createTestDictionary(); ReadOnlyDictionary testDictionary = makeReadOnly(numbers); - string numberName = testDictionary[24]; - Console.WriteLine(numberName); + Assert.Throws( + delegate() { Console.WriteLine(testDictionary[24]); } + ); } /// /// Checks whether the read only dictionary will throw an exception if its /// Add() method is called via the generic IDictionary<> interface /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnAddViaGenericIDictionary() { Dictionary numbers = createTestDictionary(); ReadOnlyDictionary testDictionary = makeReadOnly(numbers); - (testDictionary as IDictionary).Add(10, "ten"); + Assert.Throws( + delegate() { (testDictionary as IDictionary).Add(10, "ten"); } + ); } /// /// Checks whether the read only dictionary will throw an exception if its /// Remove() method is called via the generic IDictionary<> interface /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnRemoveViaGenericIDictionary() { Dictionary numbers = createTestDictionary(); ReadOnlyDictionary testDictionary = makeReadOnly(numbers); - (testDictionary as IDictionary).Remove(3); + Assert.Throws( + delegate() { (testDictionary as IDictionary).Remove(3); } + ); } /// @@ -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<> interface /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnReplaceByIndexerViaGenericIDictionary() { Dictionary numbers = createTestDictionary(); ReadOnlyDictionary testDictionary = makeReadOnly(numbers); - (testDictionary as IDictionary)[24] = "twenty-four"; + Assert.Throws( + delegate() { (testDictionary as IDictionary)[24] = "twenty-four"; } + ); } /// /// Checks whether the read only dictionary will throw an exception if its /// Clear() method is called via the IDictionary interface /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnClearViaIDictionary() { Dictionary numbers = createTestDictionary(); ReadOnlyDictionary testDictionary = makeReadOnly(numbers); - (testDictionary as IDictionary).Clear(); + Assert.Throws( + delegate() { (testDictionary as IDictionary).Clear(); } + ); } /// /// Checks whether the read only dictionary will throw an exception if its /// Add() method is called via the IDictionary interface /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnAddViaIDictionary() { Dictionary numbers = createTestDictionary(); ReadOnlyDictionary testDictionary = makeReadOnly(numbers); - - (testDictionary as IDictionary).Add(24, "twenty-four"); + + Assert.Throws( + delegate() { (testDictionary as IDictionary).Add(24, "twenty-four"); } + ); } /// @@ -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 /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnRemoveViaIDictionary() { Dictionary numbers = createTestDictionary(); ReadOnlyDictionary testDictionary = makeReadOnly(numbers); - (testDictionary as IDictionary).Remove(3); + Assert.Throws( + delegate() { (testDictionary as IDictionary).Remove(3); } + ); } /// @@ -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 /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnReplaceByIndexerViaIDictionary() { Dictionary numbers = createTestDictionary(); ReadOnlyDictionary testDictionary = makeReadOnly(numbers); - (testDictionary as IDictionary)[24] = "twenty-four"; + Assert.Throws( + delegate() { (testDictionary as IDictionary)[24] = "twenty-four"; } + ); } /// /// Checks whether the read only dictionary will throw an exception if its /// Add() method is used via the generic ICollection<> interface /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnAddViaGenericICollection() { Dictionary numbers = createTestDictionary(); ReadOnlyDictionary testDictionary = makeReadOnly(numbers); - (testDictionary as ICollection>).Add( - new KeyValuePair(24, "twenty-four") + Assert.Throws( + delegate() { + (testDictionary as ICollection>).Add( + new KeyValuePair(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<> interface /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnClearViaGenericICollection() { Dictionary numbers = createTestDictionary(); ReadOnlyDictionary testDictionary = makeReadOnly(numbers); - (testDictionary as ICollection>).Clear(); + Assert.Throws( + delegate() { (testDictionary as ICollection>).Clear(); } + ); } /// /// Checks whether the read only dictionary will throw an exception if its /// Remove() method is used via the generic ICollection<> interface /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnRemoveViaGenericICollection() { Dictionary numbers = createTestDictionary(); ReadOnlyDictionary testDictionary = makeReadOnly(numbers); - (testDictionary as ICollection>).Remove( - new KeyValuePair(42, "fourty-two") + Assert.Throws( + delegate() { + (testDictionary as ICollection>).Remove( + new KeyValuePair(42, "fourty-two") + ); + } ); } diff --git a/Source/Collections/ReadOnlyList.Test.cs b/Source/Collections/ReadOnlyList.Test.cs index 91756bc..945c1b3 100644 --- a/Source/Collections/ReadOnlyList.Test.cs +++ b/Source/Collections/ReadOnlyList.Test.cs @@ -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<> interface /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnInsertViaGenericIList() { ReadOnlyList testList = new ReadOnlyList(new int[0]); - (testList as IList).Insert(0, 12345); + Assert.Throws( + delegate() { (testList as IList).Insert(0, 12345); } + ); } /// /// Checks whether the read only list will throw an exception if its RemoveAt() method /// is called via the generic IList<> interface /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnRemoveViaGenericIList() { ReadOnlyList testList = new ReadOnlyList(new int[1]); - (testList as IList).RemoveAt(0); + Assert.Throws( + delegate() { (testList as IList).RemoveAt(0); } + ); } /// @@ -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 /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnReplaceByIndexerViaGenericIList() { ReadOnlyList testList = new ReadOnlyList(new int[1]); - (testList as IList)[0] = 12345; + Assert.Throws( + delegate() { (testList as IList)[0] = 12345; } + ); } /// /// Checks whether the read only list will throw an exception if its Add() method /// is called via the generic ICollection<> interface /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnAddViaGenericICollection() { ReadOnlyList testList = new ReadOnlyList(new int[0]); - (testList as ICollection).Add(12345); + Assert.Throws( + delegate() { (testList as ICollection).Add(12345); } + ); } /// /// Checks whether the read only list will throw an exception if its Clear() method /// is called via the generic ICollection<> interface /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnClearViaGenericICollection() { ReadOnlyList testList = new ReadOnlyList(new int[1]); - (testList as ICollection).Clear(); + Assert.Throws( + delegate() { (testList as ICollection).Clear(); } + ); } /// /// Checks whether the read only list will throw an exception if its Remove() method /// is called via the generic ICollection<> interface /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnRemoveViaGenericICollection() { int[] integers = new int[] { 12, 34, 67, 89 }; ReadOnlyList testList = new ReadOnlyList(integers); - (testList as ICollection).Remove(89); + Assert.Throws( + delegate() { (testList as ICollection).Remove(89); } + ); } /// @@ -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 /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnClearViaIList() { ReadOnlyList testList = new ReadOnlyList(new int[1]); - (testList as IList).Clear(); + Assert.Throws( + delegate() { (testList as IList).Clear(); } + ); } /// /// Checks whether the read only list will throw an exception if its Add() method /// is called via the IList interface /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnAddViaIList() { ReadOnlyList testList = new ReadOnlyList(new int[0]); - (testList as IList).Add(12345); + Assert.Throws( + delegate() { (testList as IList).Add(12345); } + ); } /// @@ -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 /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnInsertViaIList() { ReadOnlyList testList = new ReadOnlyList(new int[0]); - (testList as IList).Insert(0, 12345); + Assert.Throws( + delegate() { (testList as IList).Insert(0, 12345); } + ); } /// @@ -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 /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnRemoveViaIList() { int[] integers = new int[] { 1234, 6789 }; ReadOnlyList testList = new ReadOnlyList(integers); - (testList as IList).Remove(6789); + Assert.Throws( + delegate() { (testList as IList).Remove(6789); } + ); } /// /// Checks whether the read only list will throw an exception if its Remove() method /// is called via the IList interface /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnRemoveAtViaIList() { ReadOnlyList testList = new ReadOnlyList(new int[1]); - (testList as IList).RemoveAt(0); + Assert.Throws( + delegate() { (testList as IList).RemoveAt(0); } + ); } /// @@ -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 /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnReplaceByIndexerViaIList() { ReadOnlyList testList = new ReadOnlyList(new int[1]); - (testList as IList)[0] = 12345; + Assert.Throws( + delegate() { (testList as IList)[0] = 12345; } + ); } /// diff --git a/Source/Collections/TransformingReadOnlyCollection.Test.cs b/Source/Collections/TransformingReadOnlyCollection.Test.cs index a92a20c..4e4e339 100644 --- a/Source/Collections/TransformingReadOnlyCollection.Test.cs +++ b/Source/Collections/TransformingReadOnlyCollection.Test.cs @@ -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 /// - [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( + delegate() { testCollection.CopyTo(outputStrings, 0); } + ); } /// @@ -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<> interface /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnInsertViaGenericIList() { StringTransformer testCollection = new StringTransformer(new int[0]); - (testCollection as IList).Insert(0, "12345"); + Assert.Throws( + delegate() { (testCollection as IList).Insert(0, "12345"); } + ); } /// /// Checks whether the transforming read only collection will throw an exception /// if its RemoveAt() method is called via the generic IList<> interface /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnRemoveViaGenericIList() { StringTransformer testCollection = new StringTransformer(new int[1]); - (testCollection as IList).RemoveAt(0); + Assert.Throws( + delegate() { (testCollection as IList).RemoveAt(0); } + ); } /// @@ -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 /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnReplaceByIndexerViaGenericIList() { StringTransformer testCollection = new StringTransformer(new int[1]); - (testCollection as IList)[0] = "12345"; + Assert.Throws( + delegate() { (testCollection as IList)[0] = "12345"; } + ); } /// /// Checks whether the transforming read only collection will throw an exception /// if its Add() method is called via the generic ICollection<> interface /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnAddViaGenericICollection() { StringTransformer testCollection = new StringTransformer(new int[0]); - (testCollection as ICollection).Add("12345"); + Assert.Throws( + delegate() { (testCollection as ICollection).Add("12345"); } + ); } /// /// Checks whether the transforming read only collection will throw an exception /// if its Clear() method is called via the generic ICollection<> interface /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnClearViaGenericICollection() { StringTransformer testCollection = new StringTransformer(new int[1]); - (testCollection as ICollection).Clear(); + Assert.Throws( + delegate() { (testCollection as ICollection).Clear(); } + ); } /// /// Checks whether the transforming read only collection will throw an exception /// if its Remove() method is called via the generic ICollection<> interface /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnRemoveViaGenericICollection() { int[] integers = new int[] { 12, 34, 67, 89 }; StringTransformer testCollection = new StringTransformer(integers); - (testCollection as ICollection).Remove("89"); + Assert.Throws( + delegate() { (testCollection as ICollection).Remove("89"); } + ); } /// @@ -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 /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnClearViaIList() { StringTransformer testCollection = new StringTransformer(new int[1]); - (testCollection as IList).Clear(); + Assert.Throws( + delegate() { (testCollection as IList).Clear(); } + ); } /// /// Checks whether the transforming read only collection will throw an exception /// if its Add() method is called via the IList interface /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnAddViaIList() { StringTransformer testCollection = new StringTransformer(new int[0]); - (testCollection as IList).Add("12345"); + Assert.Throws( + delegate() { (testCollection as IList).Add("12345"); } + ); } /// @@ -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 /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnInsertViaIList() { StringTransformer testCollection = new StringTransformer(new int[0]); - (testCollection as IList).Insert(0, "12345"); + Assert.Throws( + delegate() { (testCollection as IList).Insert(0, "12345"); } + ); } /// @@ -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 /// - [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( + delegate() { (testCollection as IList).Remove("6789"); } + ); } /// /// Checks whether the transforming read only collection will throw an exception /// if its Remove() method is called via the IList interface /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnRemoveAtViaIList() { StringTransformer testCollection = new StringTransformer(new int[1]); - (testCollection as IList).RemoveAt(0); + Assert.Throws( + delegate() { (testCollection as IList).RemoveAt(0); } + ); } /// @@ -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 /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnReplaceByIndexerViaIList() { StringTransformer testCollection = new StringTransformer(new int[1]); - (testCollection as IList)[0] = "12345"; + Assert.Throws( + delegate() { (testCollection as IList)[0] = "12345"; } + ); } /// diff --git a/Source/Collections/WeakCollection.Test.cs b/Source/Collections/WeakCollection.Test.cs index 5e9d9b1..6547d8f 100644 --- a/Source/Collections/WeakCollection.Test.cs +++ b/Source/Collections/WeakCollection.Test.cs @@ -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 /// - [Test, ExpectedException(typeof(ArgumentException))] + [Test] public void TestThrowOnAddIncompatibleObject() { WeakCollection dummies = new WeakCollection( new List>() ); - (dummies as IList).Add(new object()); + Assert.Throws( + delegate() { (dummies as IList).Add(new object()); } + ); } /// @@ -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 /// - [Test, ExpectedException(typeof(ArgumentException))] + [Test] public void TestThrowOnIndexOfWithIncompatibleObject() { WeakCollection dummies = new WeakCollection( new List>() ); - Assert.IsNull((dummies as IList).IndexOf(new object())); + Assert.Throws( + delegate() { Assert.IsNull((dummies as IList).IndexOf(new object())); } + ); } /// Test whether the IndexOf() method can cope with null references @@ -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 /// - [Test, ExpectedException(typeof(ArgumentException))] + [Test] public void TestThrowOnCopyToTooSmallArray() { WeakCollection dummies = new WeakCollection( new List>() @@ -300,7 +304,9 @@ namespace Nuclex.Support.Collections { dummies.Add(fourFiveSixDummy); Dummy[] outputStrings = new Dummy[dummies.Count - 1]; - dummies.CopyTo(outputStrings, 0); + Assert.Throws( + delegate() { dummies.CopyTo(outputStrings, 0); } + ); } /// @@ -368,7 +374,7 @@ namespace Nuclex.Support.Collections { /// Verifies that the non-typesafe Insert() method correctly shifts items in /// the collection /// - [Test, ExpectedException(typeof(ArgumentException))] + [Test] public void TestThrowOnInsertIncompatibleObject() { WeakCollection dummies = new WeakCollection( new List>() @@ -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( + delegate() { (dummies as IList).Insert(0, new object()); } + ); } /// @@ -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 /// - [Test, ExpectedException(typeof(ArgumentException))] + [Test] public void TestThrowOnIndexerWithIncompatibleObject() { WeakCollection dummies = new WeakCollection( new List>() @@ -484,7 +492,9 @@ namespace Nuclex.Support.Collections { Dummy oneTwoThreeDummy = new Dummy(123); dummies.Add(oneTwoThreeDummy); - (dummies as IList)[0] = new object(); + Assert.Throws( + delegate() { (dummies as IList)[0] = new object(); } + ); } /// Tests the Remove() method of the weak collection @@ -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 /// - [Test, ExpectedException(typeof(ArgumentException))] + [Test] public void TestThrowOnRemoveIncompatibleObject() { WeakCollection dummies = new WeakCollection( new List>() ); - (dummies as IList).Remove(new object()); + Assert.Throws( + delegate() { (dummies as IList).Remove(new object()); } + ); } /// Tests the RemoveAt() method of the weak collection diff --git a/Source/IO/ChainStream.Test.cs b/Source/IO/ChainStream.Test.cs index 48085d9..ca67cb0 100644 --- a/Source/IO/ChainStream.Test.cs +++ b/Source/IO/ChainStream.Test.cs @@ -323,35 +323,39 @@ namespace Nuclex.Support.IO { /// /// Tests reading from a stream chainer that contains an unreadable stream /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnReadFromUnreadableStream() { MemoryStream memoryStream = new MemoryStream(); TestStream testStream = new TestStream(memoryStream, false, true, true); ChainStream chainer = new ChainStream(new Stream[] { testStream }); - - chainer.Read(new byte[5], 0, 5); + Assert.Throws( + delegate() { chainer.Read(new byte[5], 0, 5); } + ); } /// /// Tests writing to a stream chainer that contains an unwriteable stream /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnWriteToUnwriteableStream() { MemoryStream memoryStream = new MemoryStream(); TestStream testStream = new TestStream(memoryStream, true, false, true); ChainStream chainer = new ChainStream(new Stream[] { testStream }); - - chainer.Write(new byte[] { 1, 2, 3, 4, 5 }, 0, 5); + Assert.Throws( + delegate() { chainer.Write(new byte[] { 1, 2, 3, 4, 5 }, 0, 5); } + ); } /// /// Verifies that the stream chainer throws an exception if the attempt is /// made to change the length of the stream /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnLengthChange() { ChainStream chainer = chainTwoStreamsOfTenBytes(); - chainer.SetLength(123); + Assert.Throws( + delegate() { chainer.SetLength(123); } + ); } /// @@ -409,52 +413,60 @@ namespace Nuclex.Support.IO { /// Tests whether an exception is thrown if the Seek() method is called on /// a stream chainer with streams that do not support seeking /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnSeekWithUnseekableStream() { MemoryStream memoryStream = new MemoryStream(); TestStream testStream = new TestStream(memoryStream, true, true, false); ChainStream chainer = new ChainStream(new Stream[] { testStream }); - chainer.Seek(123, SeekOrigin.Begin); + Assert.Throws( + delegate() { chainer.Seek(123, SeekOrigin.Begin); } + ); } /// /// Tests whether an exception is thrown if the Position property is retrieved /// on a stream chainer with streams that do not support seeking /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnGetPositionWithUnseekableStream() { MemoryStream memoryStream = new MemoryStream(); TestStream testStream = new TestStream(memoryStream, true, true, false); ChainStream chainer = new ChainStream(new Stream[] { testStream }); - Assert.IsTrue(chainer.Position != chainer.Position); // ;-) + Assert.Throws( + delegate() { Console.WriteLine(chainer.Position); } + ); } /// /// Tests whether an exception is thrown if the Position property is set /// on a stream chainer with streams that do not support seeking /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnSetPositionWithUnseekableStream() { MemoryStream memoryStream = new MemoryStream(); TestStream testStream = new TestStream(memoryStream, true, true, false); ChainStream chainer = new ChainStream(new Stream[] { testStream }); - chainer.Position = 123; + Assert.Throws( + delegate() { chainer.Position = 123; } + ); } /// /// Tests whether an exception is thrown if the Length property is retrieved /// on a stream chainer with streams that do not support seeking /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnGetLengthWithUnseekableStream() { MemoryStream memoryStream = new MemoryStream(); TestStream testStream = new TestStream(memoryStream, true, true, false); ChainStream chainer = new ChainStream(new Stream[] { testStream }); - Assert.IsTrue(chainer.Length != chainer.Length); // ;-) + Assert.Throws( + delegate() { Assert.IsTrue(chainer.Length != chainer.Length); } + ); } /// @@ -486,10 +498,12 @@ namespace Nuclex.Support.IO { /// Tests whether the Seek() method throws an exception if an invalid /// reference point is provided /// - [Test, ExpectedException(typeof(ArgumentException))] + [Test] public void TestThrowOnInvalidSeekReferencePoint() { ChainStream chainer = chainTwoStreamsOfTenBytes(); - chainer.Seek(1, (SeekOrigin)12345); + Assert.Throws( + delegate() { chainer.Seek(1, (SeekOrigin)12345); } + ); } /// Verifies that the position property works correctly diff --git a/Source/IO/PartialStream.Test.cs b/Source/IO/PartialStream.Test.cs index 8328fa7..509befb 100644 --- a/Source/IO/PartialStream.Test.cs +++ b/Source/IO/PartialStream.Test.cs @@ -207,12 +207,13 @@ namespace Nuclex.Support.IO { /// Verifies that the partial stream constructor throws an exception if /// it's invoked with an invalid start offset /// - [Test, ExpectedException(typeof(ArgumentException))] + [Test] public void TestThrowOnInvalidStartInConstructor() { using(MemoryStream memoryStream = new MemoryStream()) { memoryStream.SetLength(123); - PartialStream partialStream = new PartialStream(memoryStream, -1, 10); - Assert.AreNotEqual(partialStream.Length, partialStream.Length); + Assert.Throws( + delegate() { Console.WriteLine(new PartialStream(memoryStream, -1, 10)); } + ); } } @@ -220,12 +221,13 @@ namespace Nuclex.Support.IO { /// Verifies that the partial stream constructor throws an exception if /// it's invoked with an invalid start offset /// - [Test, ExpectedException(typeof(ArgumentException))] + [Test] public void TestThrowOnInvalidLengthInConstructor() { using(MemoryStream memoryStream = new MemoryStream()) { memoryStream.SetLength(123); - PartialStream partialStream = new PartialStream(memoryStream, 100, 24); - Assert.AreNotEqual(partialStream.Length, partialStream.Length); + Assert.Throws( + delegate() { Console.WriteLine(new PartialStream(memoryStream, 100, 24)); } + ); } } @@ -233,13 +235,14 @@ namespace Nuclex.Support.IO { /// Verifies that the partial stream constructor throws an exception if /// it's invoked with a start offset on an unseekable stream /// - [Test, ExpectedException(typeof(ArgumentException))] + [Test] public void TestThrowOnUnseekableStreamWithOffsetInConstructor() { using(MemoryStream memoryStream = new MemoryStream()) { memoryStream.SetLength(123); TestStream testStream = new TestStream(memoryStream, true, true, false); - PartialStream partialStream = new PartialStream(testStream, 23, 100); - Assert.AreNotEqual(partialStream.Length, partialStream.Length); + Assert.Throws( + delegate() { Console.WriteLine(new PartialStream(testStream, 23, 100)); } + ); } } @@ -351,13 +354,15 @@ namespace Nuclex.Support.IO { /// Tests whether the Position property throws an exception if the stream does /// not support seeking. /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnGetPositionOnUnseekableStream() { using(MemoryStream memoryStream = new MemoryStream()) { TestStream testStream = new TestStream(memoryStream, true, true, false); PartialStream partialStream = new PartialStream(testStream, 0, 0); - Assert.AreEqual(-12345, partialStream.Position); + Assert.Throws( + delegate() { Console.WriteLine(partialStream.Position); } + ); } } @@ -365,13 +370,15 @@ namespace Nuclex.Support.IO { /// Tests whether the Position property throws an exception if the stream does /// not support seeking. /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnSetPositionOnUnseekableStream() { using(MemoryStream memoryStream = new MemoryStream()) { TestStream testStream = new TestStream(memoryStream, true, true, false); PartialStream partialStream = new PartialStream(testStream, 0, 0); - partialStream.Position = 0; + Assert.Throws( + delegate() { partialStream.Position = 0; } + ); } } @@ -379,16 +386,16 @@ namespace Nuclex.Support.IO { /// Tests whether the Read() method throws an exception if the stream does /// not support reading /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnReadFromUnreadableStream() { using(MemoryStream memoryStream = new MemoryStream()) { TestStream testStream = new TestStream(memoryStream, false, true, true); PartialStream partialStream = new PartialStream(testStream, 0, 0); byte[] test = new byte[10]; - int bytesRead = partialStream.Read(test, 0, 10); - - Assert.AreNotEqual(bytesRead, bytesRead); + Assert.Throws( + delegate() { Console.WriteLine(partialStream.Read(test, 0, 10)); } + ); } } @@ -411,11 +418,13 @@ namespace Nuclex.Support.IO { /// Tests whether the Seek() method throws an exception if an invalid /// reference point is provided /// - [Test, ExpectedException(typeof(ArgumentException))] + [Test] public void TestThrowOnInvalidSeekReferencePoint() { using(MemoryStream memoryStream = new MemoryStream()) { PartialStream partialStream = new PartialStream(memoryStream, 0, 0); - partialStream.Seek(1, (SeekOrigin)12345); + Assert.Throws( + delegate() { partialStream.Seek(1, (SeekOrigin)12345); } + ); } } @@ -423,11 +432,13 @@ namespace Nuclex.Support.IO { /// Verifies that the partial stream throws an exception if the attempt is /// made to change the length of the stream /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnLengthChange() { using(MemoryStream memoryStream = new MemoryStream()) { PartialStream partialStream = new PartialStream(memoryStream, 0, 0); - partialStream.SetLength(123); + Assert.Throws( + delegate() { partialStream.SetLength(123); } + ); } } @@ -497,14 +508,16 @@ namespace Nuclex.Support.IO { /// Verifies that an exception is thrown if the Write() method of the partial stream /// is attempted to be used to extend the partial stream's length /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnExtendPartialStream() { using(MemoryStream memoryStream = new MemoryStream()) { memoryStream.SetLength(25); PartialStream partialStream = new PartialStream(memoryStream, 10, 10); partialStream.Position = 5; - partialStream.Write(new byte[] { 1, 2, 3, 4, 5, 6 }, 0, 6); + Assert.Throws( + delegate() { partialStream.Write(new byte[] { 1, 2, 3, 4, 5, 6 }, 0, 6); } + ); } } diff --git a/Source/IO/RingMemoryStream.Test.cs b/Source/IO/RingMemoryStream.Test.cs index d68bed0..e3dc4e0 100644 --- a/Source/IO/RingMemoryStream.Test.cs +++ b/Source/IO/RingMemoryStream.Test.cs @@ -42,9 +42,11 @@ namespace Nuclex.Support.IO { /// /// Ensures that the ring buffer blocks write attempts that would exceed its capacity /// - [Test, ExpectedException(typeof(OverflowException))] + [Test] public void TestWriteTooLargeChunk() { - new RingMemoryStream(10).Write(this.testBytes, 0, 11); + Assert.Throws( + delegate() { new RingMemoryStream(10).Write(this.testBytes, 0, 11); } + ); } /// @@ -93,13 +95,15 @@ namespace Nuclex.Support.IO { /// Ensures that the ring buffer still detects write that would exceed its capacity /// if they write into the gap after the ring buffer's data has become split /// - [Test, ExpectedException(typeof(OverflowException))] + [Test] public void TestWriteSplitAndLinearTooLargeBlock() { RingMemoryStream testRing = new RingMemoryStream(10); testRing.Write(this.testBytes, 0, 8); testRing.Read(this.testBytes, 0, 5); testRing.Write(this.testBytes, 0, 5); - testRing.Write(this.testBytes, 0, 3); + Assert.Throws( + delegate() { testRing.Write(this.testBytes, 0, 3); } + ); } /// Tests whether the ring buffer correctly handles fragmentation @@ -182,12 +186,14 @@ namespace Nuclex.Support.IO { /// Checks that an exception is thrown when the ring buffer's capacity is /// reduced so much it would have to give up some of its contained data /// - [Test, ExpectedException(typeof(ArgumentOutOfRangeException))] + [Test] public void TestCapacityDecreaseException() { RingMemoryStream testRing = new RingMemoryStream(20); testRing.Write(this.testBytes, 0, 20); - testRing.Capacity = 10; + Assert.Throws( + delegate() { testRing.Capacity = 10; } + ); } /// Tests whether the Capacity property returns the current capacity @@ -238,37 +244,44 @@ namespace Nuclex.Support.IO { /// Verifies that an exception is thrown when the Position property of the ring /// memory stream is used to retrieve the current file pointer position /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnRetrievePosition() { - long position = new RingMemoryStream(10).Position; - Console.WriteLine(position.ToString()); + Assert.Throws( + delegate() { Console.WriteLine(new RingMemoryStream(10).Position); } + ); } /// /// Verifies that an exception is thrown when the Position property of the ring /// memory stream is used to modify the current file pointer position /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnAssignPosition() { - new RingMemoryStream(10).Position = 0; + Assert.Throws( + delegate() { new RingMemoryStream(10).Position = 0; } + ); } /// /// Verifies that an exception is thrown when the Seek() method of the ring memory /// stream is attempted to be used /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnSeek() { - new RingMemoryStream(10).Seek(0, SeekOrigin.Begin); + Assert.Throws( + delegate() { new RingMemoryStream(10).Seek(0, SeekOrigin.Begin); } + ); } /// /// Verifies that an exception is thrown when the SetLength() method of the ring /// memory stream is attempted to be used /// - [Test, ExpectedException(typeof(NotSupportedException))] + [Test] public void TestThrowOnSetLength() { - new RingMemoryStream(10).SetLength(10); + Assert.Throws( + delegate() { new RingMemoryStream(10).SetLength(10); } + ); } /// diff --git a/Source/Licensing/LicenseKey.Test.cs b/Source/Licensing/LicenseKey.Test.cs index d4d6316..9eeb1e7 100644 --- a/Source/Licensing/LicenseKey.Test.cs +++ b/Source/Licensing/LicenseKey.Test.cs @@ -95,30 +95,35 @@ namespace Nuclex.Support.Licensing { } /// Tests whether license keys can be modified without destroying them - [Test, ExpectedException(typeof(ArgumentException))] + [Test] public void TestParseInvalidLicenseKey() { - LicenseKey.Parse("hello world"); + Assert.Throws( + delegate() { LicenseKey.Parse("hello world"); } + ); } /// /// Tests whether an exception is thrown if the indexer of a license key is used /// with an invalid index to retrieve a component of the key /// - [Test, ExpectedException(typeof(IndexOutOfRangeException))] + [Test] public void TestGetByIndexerWithInvalidIndex() { LicenseKey key = new LicenseKey(); - int indexMinusOne = key[-1]; - Console.WriteLine(indexMinusOne.ToString()); + Assert.Throws( + delegate() { Console.WriteLine(key[-1]); } + ); } /// /// Tests whether an exception is thrown if the indexer of a license key is used /// with an invalid index to set a component of the key /// - [Test, ExpectedException(typeof(IndexOutOfRangeException))] + [Test] public void TestSetByIndexerWithInvalidIndex() { LicenseKey key = new LicenseKey(); - key[-1] = 0; + Assert.Throws( + delegate() { key[-1] = 0; } + ); } /// diff --git a/Source/Plugins/FactoryEmployer.Test.cs b/Source/Plugins/FactoryEmployer.Test.cs index 378f855..bd5a26f 100644 --- a/Source/Plugins/FactoryEmployer.Test.cs +++ b/Source/Plugins/FactoryEmployer.Test.cs @@ -73,22 +73,26 @@ namespace Nuclex.Support.Plugins { /// Tests whether the factory employer throws an exception when it is asked to /// employ an abstract class /// - [Test, ExpectedException(typeof(MissingMethodException))] + [Test] public void TestThrowOnEmployAbstractClass() { FactoryEmployer testEmployer = new FactoryEmployer(); - testEmployer.Employ(typeof(Base)); + Assert.Throws( + delegate() { testEmployer.Employ(typeof(Base)); } + ); } /// /// Tests whether the factory employer throws an exception when it is asked to /// employ a class that is not the product type or a derivative thereof /// - [Test, ExpectedException(typeof(InvalidCastException))] + [Test] public void TestThrowOnEmployUnrelatedClass() { FactoryEmployer testEmployer = new FactoryEmployer(); - testEmployer.Employ(typeof(Unrelated)); + Assert.Throws( + delegate() { testEmployer.Employ(typeof(Unrelated)); } + ); } /// diff --git a/Source/Plugins/InstanceEmployer.Test.cs b/Source/Plugins/InstanceEmployer.Test.cs index 6ac72a9..9e546b5 100644 --- a/Source/Plugins/InstanceEmployer.Test.cs +++ b/Source/Plugins/InstanceEmployer.Test.cs @@ -74,22 +74,26 @@ namespace Nuclex.Support.Plugins { /// Tests whether the instance employer throws an exception when it is asked to /// employ an abstract class /// - [Test, ExpectedException(typeof(MissingMethodException))] + [Test] public void TestThrowOnEmployAbstractClass() { InstanceEmployer testEmployer = new InstanceEmployer(); - testEmployer.Employ(typeof(Base)); + Assert.Throws( + delegate() { testEmployer.Employ(typeof(Base)); } + ); } /// /// Tests whether the instance employer throws an exception when it is asked to /// employ a class that is not the product type or a derivative thereof /// - [Test, ExpectedException(typeof(InvalidCastException))] + [Test] public void TestThrowOnEmployUnrelatedClass() { InstanceEmployer testEmployer = new InstanceEmployer(); - testEmployer.Employ(typeof(Unrelated)); + Assert.Throws( + delegate() { testEmployer.Employ(typeof(Unrelated)); } + ); } /// diff --git a/Source/Scheduling/OperationQueue.Test.cs b/Source/Scheduling/OperationQueue.Test.cs index 281de84..3dd160f 100644 --- a/Source/Scheduling/OperationQueue.Test.cs +++ b/Source/Scheduling/OperationQueue.Test.cs @@ -287,7 +287,7 @@ namespace Nuclex.Support.Scheduling { /// Validates that the operation queue delivers an exception occuring in one of the /// contained operations to the operation queue joiner /// - [Test, ExpectedException(typeof(AbortedException))] + [Test] public void TestExceptionPropagation() { TestOperation operation1 = new TestOperation(); TestOperation operation2 = new TestOperation(); @@ -307,7 +307,9 @@ namespace Nuclex.Support.Scheduling { Assert.IsFalse(testQueueOperation.Ended); operation2.SetEnded(new AbortedException("Hello World")); - testQueueOperation.Join(); + Assert.Throws( + delegate() { testQueueOperation.Join(); } + ); } /// @@ -321,7 +323,7 @@ namespace Nuclex.Support.Scheduling { ); WeightedTransaction operation2 = new WeightedTransaction( new TestOperation() - ); + ); OperationQueue testQueueOperation = new OperationQueue( diff --git a/Source/Scheduling/ThreadCallbackOperation.Test.cs b/Source/Scheduling/ThreadCallbackOperation.Test.cs index 7ff5858..9d7baa2 100644 --- a/Source/Scheduling/ThreadCallbackOperation.Test.cs +++ b/Source/Scheduling/ThreadCallbackOperation.Test.cs @@ -110,7 +110,7 @@ namespace Nuclex.Support.Scheduling { /// Verifies that the threaded operation forwards an exception that occurred in /// a thread pool thread. /// - [Test, ExpectedException(typeof(AbortedException))] + [Test] public void TestForwardExceptionFromThreadPool() { ThreadCallbackOperation test = new ThreadCallbackOperation( new ThreadStart(errorCallback), false @@ -118,14 +118,16 @@ namespace Nuclex.Support.Scheduling { Assert.IsFalse(test.Ended); test.Start(); - test.Join(); + Assert.Throws( + delegate() { test.Join(); } + ); } /// /// Verifies that the threaded operation forwards an exception that occurred in /// an explicit thread. /// - [Test, ExpectedException(typeof(AbortedException))] + [Test] public void TestForwardExceptionFromExplicitThread() { ThreadCallbackOperation test = new ThreadCallbackOperation( new ThreadStart(errorCallback), false @@ -133,7 +135,9 @@ namespace Nuclex.Support.Scheduling { Assert.IsFalse(test.Ended); test.Start(); - test.Join(); + Assert.Throws( + delegate() { test.Join(); } + ); } /// diff --git a/Source/Scheduling/ThreadOperation.Test.cs b/Source/Scheduling/ThreadOperation.Test.cs index 60895e2..191fce4 100644 --- a/Source/Scheduling/ThreadOperation.Test.cs +++ b/Source/Scheduling/ThreadOperation.Test.cs @@ -107,26 +107,30 @@ namespace Nuclex.Support.Scheduling { /// Verifies that the threaded operation forwards an exception that occurred in /// a thread pool thread. /// - [Test, ExpectedException(typeof(AbortedException))] + [Test] public void TestForwardExceptionFromThreadPool() { FailingThreadOperation test = new FailingThreadOperation(true); Assert.IsFalse(test.Ended); test.Start(); - test.Join(); + Assert.Throws( + delegate() { test.Join(); } + ); } /// /// Verifies that the threaded operation forwards an exception that occurred in /// an explicit thread. /// - [Test, ExpectedException(typeof(AbortedException))] + [Test] public void TestForwardExceptionFromExplicitThread() { FailingThreadOperation test = new FailingThreadOperation(false); Assert.IsFalse(test.Ended); test.Start(); - test.Join(); + Assert.Throws( + delegate() { test.Join(); } + ); } } diff --git a/Source/StringSegment.Test.cs b/Source/StringSegment.Test.cs index 5c7308c..8ab3c13 100644 --- a/Source/StringSegment.Test.cs +++ b/Source/StringSegment.Test.cs @@ -35,9 +35,11 @@ namespace Nuclex.Support { /// Tests whether the default constructor of the StringSegment class throws the /// right exception when being passed 'null' instead of a string /// - [Test, ExpectedException(typeof(ArgumentNullException))] + [Test] public void TestNullStringInSimpleConstructor() { - new StringSegment(null); + Assert.Throws( + delegate() { new StringSegment(null); } + ); } /// @@ -53,9 +55,11 @@ namespace Nuclex.Support { /// Tests whether the full constructor of the StringSegment class throws the /// right exception when being passed 'null' instead of a string /// - [Test, ExpectedException(typeof(ArgumentNullException))] + [Test] public void TestNullStringInFullConstructor() { - new StringSegment(null, 0, 0); + Assert.Throws( + delegate() { new StringSegment(null, 0, 0); } + ); } /// @@ -71,27 +75,33 @@ namespace Nuclex.Support { /// Tests whether the full constructor of the StringSegment class throws the /// right exception when being passed an invalid start offset /// - [Test, ExpectedException(typeof(ArgumentOutOfRangeException))] + [Test] public void TestInvalidOffsetInConstructor() { - new StringSegment(string.Empty, -1, 0); + Assert.Throws( + delegate() { new StringSegment(string.Empty, -1, 0); } + ); } /// /// Tests whether the full constructor of the StringSegment class throws the /// right exception when being passed an invalid string length /// - [Test, ExpectedException(typeof(ArgumentOutOfRangeException))] + [Test] public void TestInvalidLengthInConstructor() { - new StringSegment(string.Empty, 0, -1); + Assert.Throws( + delegate() { new StringSegment(string.Empty, 0, -1); } + ); } /// /// Tests whether the full constructor of the StringSegment class throws the /// right exception when being passed a string length that's too large /// - [Test, ExpectedException(typeof(ArgumentException))] + [Test] public void TestExcessiveLengthInConstructor() { - new StringSegment("hello", 3, 3); + Assert.Throws( + delegate() { new StringSegment("hello", 3, 3); } + ); } /// Tests whether the 'Text' property works as expected @@ -198,28 +208,31 @@ namespace Nuclex.Support { /// /// Tests the ToString() method of the string segment with an invalid string /// - [Test, ExpectedException(typeof(ArgumentNullException))] + [Test] public void TestToStringWithInvalidString() { - StringSegment helloWorldSegment = new StringSegment(null, 4, 3); - Assert.IsNotNull(helloWorldSegment.ToString()); + Assert.Throws( + delegate() { new StringSegment(null, 4, 3); } + ); } /// /// Tests the ToString() method of the string segment with an invalid offset /// - [Test, ExpectedException(typeof(ArgumentOutOfRangeException))] + [Test] public void TestToStringWithInvalidOffset() { - StringSegment helloWorldSegment = new StringSegment("hello world", -4, 3); - Assert.IsNotNull(helloWorldSegment.ToString()); + Assert.Throws( + delegate() { new StringSegment("hello world", -4, 3); } + ); } /// /// Tests the ToString() method of the string segment with an invalid count /// - [Test, ExpectedException(typeof(ArgumentOutOfRangeException))] + [Test] public void TestToStringWithInvalidCount() { - StringSegment helloWorldSegment = new StringSegment("hello world", 4, -3); - Assert.IsNotNull(helloWorldSegment.ToString()); + Assert.Throws( + delegate() { new StringSegment("hello world", 4, -3); } + ); } } diff --git a/Source/Tracking/ProgressTracker.Test.cs b/Source/Tracking/ProgressTracker.Test.cs index ef76a35..2ef8151 100644 --- a/Source/Tracking/ProgressTracker.Test.cs +++ b/Source/Tracking/ProgressTracker.Test.cs @@ -468,12 +468,14 @@ namespace Nuclex.Support.Tracking { /// Verifies that the progress tracker throws an exception if it is instructed /// to untrack a transaction it doesn't know about /// - [Test, ExpectedException(typeof(ArgumentException))] + [Test] public void TestThrowOnUntrackNonTrackedTransaction() { using(ProgressTracker tracker = new ProgressTracker()) { TestTransaction test1 = new TestTransaction(); - tracker.Untrack(test1); + Assert.Throws( + delegate() { tracker.Untrack(test1); } + ); } } diff --git a/Source/Tracking/Request.Test.cs b/Source/Tracking/Request.Test.cs index 6afc579..a1c1754 100644 --- a/Source/Tracking/Request.Test.cs +++ b/Source/Tracking/Request.Test.cs @@ -71,14 +71,16 @@ namespace Nuclex.Support.Tracking { /// Verifies that the FailedDummy request is in the ended state and throws /// an exception when Join()ing /// - [Test, ExpectedException(typeof(AbortedException))] + [Test] public void TestFailedDummy() { Request failedDummy = Request.CreateFailedDummy( new AbortedException("Hello World") ); Assert.IsTrue(failedDummy.Ended); - failedDummy.Join(); + Assert.Throws( + delegate() { failedDummy.Join(); } + ); } /// @@ -114,14 +116,16 @@ namespace Nuclex.Support.Tracking { /// Verifies that the FailedDummy request is in the ended state and throws /// an exception when Join()ing /// - [Test, ExpectedException(typeof(AbortedException))] + [Test] public void TestFailedDummy() { Request failedDummy = Request.CreateFailedDummy( new AbortedException("Hello World") ); Assert.IsTrue(failedDummy.Ended); - failedDummy.Join(); + Assert.Throws( + delegate() { failedDummy.Join(); } + ); } } diff --git a/Source/Tracking/Transaction.Test.cs b/Source/Tracking/Transaction.Test.cs index d3d0b5d..139cd75 100644 --- a/Source/Tracking/Transaction.Test.cs +++ b/Source/Tracking/Transaction.Test.cs @@ -111,11 +111,13 @@ namespace Nuclex.Support.Tracking { /// /// Verifies that the transaction throws an exception when it is ended multiple times /// - [Test, ExpectedException(typeof(InvalidOperationException))] + [Test] public void TestThrowOnRepeatedlyEndedTransaction() { TestTransaction test = new TestTransaction(); test.End(); - test.End(); + Assert.Throws( + delegate() { test.End(); } + ); } ///