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:
parent
06749b9cbb
commit
d0fe47239e
20 changed files with 399 additions and 215 deletions
|
@ -323,35 +323,39 @@ namespace Nuclex.Support.IO {
|
|||
/// <summary>
|
||||
/// Tests reading from a stream chainer that contains an unreadable stream
|
||||
/// </summary>
|
||||
[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<NotSupportedException>(
|
||||
delegate() { chainer.Read(new byte[5], 0, 5); }
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests writing to a stream chainer that contains an unwriteable stream
|
||||
/// </summary>
|
||||
[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<NotSupportedException>(
|
||||
delegate() { chainer.Write(new byte[] { 1, 2, 3, 4, 5 }, 0, 5); }
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the stream chainer throws an exception if the attempt is
|
||||
/// made to change the length of the stream
|
||||
/// </summary>
|
||||
[Test, ExpectedException(typeof(NotSupportedException))]
|
||||
[Test]
|
||||
public void TestThrowOnLengthChange() {
|
||||
ChainStream chainer = chainTwoStreamsOfTenBytes();
|
||||
chainer.SetLength(123);
|
||||
Assert.Throws<NotSupportedException>(
|
||||
delegate() { chainer.SetLength(123); }
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -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
|
||||
/// </summary>
|
||||
[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<NotSupportedException>(
|
||||
delegate() { chainer.Seek(123, SeekOrigin.Begin); }
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests whether an exception is thrown if the Position property is retrieved
|
||||
/// on a stream chainer with streams that do not support seeking
|
||||
/// </summary>
|
||||
[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<NotSupportedException>(
|
||||
delegate() { Console.WriteLine(chainer.Position); }
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests whether an exception is thrown if the Position property is set
|
||||
/// on a stream chainer with streams that do not support seeking
|
||||
/// </summary>
|
||||
[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<NotSupportedException>(
|
||||
delegate() { chainer.Position = 123; }
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests whether an exception is thrown if the Length property is retrieved
|
||||
/// on a stream chainer with streams that do not support seeking
|
||||
/// </summary>
|
||||
[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<NotSupportedException>(
|
||||
delegate() { Assert.IsTrue(chainer.Length != chainer.Length); }
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -486,10 +498,12 @@ namespace Nuclex.Support.IO {
|
|||
/// Tests whether the Seek() method throws an exception if an invalid
|
||||
/// reference point is provided
|
||||
/// </summary>
|
||||
[Test, ExpectedException(typeof(ArgumentException))]
|
||||
[Test]
|
||||
public void TestThrowOnInvalidSeekReferencePoint() {
|
||||
ChainStream chainer = chainTwoStreamsOfTenBytes();
|
||||
chainer.Seek(1, (SeekOrigin)12345);
|
||||
Assert.Throws<ArgumentException>(
|
||||
delegate() { chainer.Seek(1, (SeekOrigin)12345); }
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the position property works correctly</summary>
|
||||
|
|
|
@ -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
|
||||
/// </summary>
|
||||
[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<ArgumentException>(
|
||||
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
|
||||
/// </summary>
|
||||
[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<ArgumentException>(
|
||||
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
|
||||
/// </summary>
|
||||
[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<ArgumentException>(
|
||||
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.
|
||||
/// </summary>
|
||||
[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<NotSupportedException>(
|
||||
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.
|
||||
/// </summary>
|
||||
[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<NotSupportedException>(
|
||||
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
|
||||
/// </summary>
|
||||
[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<NotSupportedException>(
|
||||
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
|
||||
/// </summary>
|
||||
[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<ArgumentException>(
|
||||
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
|
||||
/// </summary>
|
||||
[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<NotSupportedException>(
|
||||
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
|
||||
/// </summary>
|
||||
[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<NotSupportedException>(
|
||||
delegate() { partialStream.Write(new byte[] { 1, 2, 3, 4, 5, 6 }, 0, 6); }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,9 +42,11 @@ namespace Nuclex.Support.IO {
|
|||
/// <summary>
|
||||
/// Ensures that the ring buffer blocks write attempts that would exceed its capacity
|
||||
/// </summary>
|
||||
[Test, ExpectedException(typeof(OverflowException))]
|
||||
[Test]
|
||||
public void TestWriteTooLargeChunk() {
|
||||
new RingMemoryStream(10).Write(this.testBytes, 0, 11);
|
||||
Assert.Throws<OverflowException>(
|
||||
delegate() { new RingMemoryStream(10).Write(this.testBytes, 0, 11); }
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -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
|
||||
/// </summary>
|
||||
[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<OverflowException>(
|
||||
delegate() { testRing.Write(this.testBytes, 0, 3); }
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>Tests whether the ring buffer correctly handles fragmentation</summary>
|
||||
|
@ -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
|
||||
/// </summary>
|
||||
[Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
|
||||
[Test]
|
||||
public void TestCapacityDecreaseException() {
|
||||
RingMemoryStream testRing = new RingMemoryStream(20);
|
||||
testRing.Write(this.testBytes, 0, 20);
|
||||
|
||||
testRing.Capacity = 10;
|
||||
Assert.Throws<ArgumentOutOfRangeException>(
|
||||
delegate() { testRing.Capacity = 10; }
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>Tests whether the Capacity property returns the current capacity</summary>
|
||||
|
@ -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
|
||||
/// </summary>
|
||||
[Test, ExpectedException(typeof(NotSupportedException))]
|
||||
[Test]
|
||||
public void TestThrowOnRetrievePosition() {
|
||||
long position = new RingMemoryStream(10).Position;
|
||||
Console.WriteLine(position.ToString());
|
||||
Assert.Throws<NotSupportedException>(
|
||||
delegate() { Console.WriteLine(new RingMemoryStream(10).Position); }
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that an exception is thrown when the Position property of the ring
|
||||
/// memory stream is used to modify the current file pointer position
|
||||
/// </summary>
|
||||
[Test, ExpectedException(typeof(NotSupportedException))]
|
||||
[Test]
|
||||
public void TestThrowOnAssignPosition() {
|
||||
new RingMemoryStream(10).Position = 0;
|
||||
Assert.Throws<NotSupportedException>(
|
||||
delegate() { new RingMemoryStream(10).Position = 0; }
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that an exception is thrown when the Seek() method of the ring memory
|
||||
/// stream is attempted to be used
|
||||
/// </summary>
|
||||
[Test, ExpectedException(typeof(NotSupportedException))]
|
||||
[Test]
|
||||
public void TestThrowOnSeek() {
|
||||
new RingMemoryStream(10).Seek(0, SeekOrigin.Begin);
|
||||
Assert.Throws<NotSupportedException>(
|
||||
delegate() { new RingMemoryStream(10).Seek(0, SeekOrigin.Begin); }
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that an exception is thrown when the SetLength() method of the ring
|
||||
/// memory stream is attempted to be used
|
||||
/// </summary>
|
||||
[Test, ExpectedException(typeof(NotSupportedException))]
|
||||
[Test]
|
||||
public void TestThrowOnSetLength() {
|
||||
new RingMemoryStream(10).SetLength(10);
|
||||
Assert.Throws<NotSupportedException>(
|
||||
delegate() { new RingMemoryStream(10).SetLength(10); }
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue