forked from dotnet/corefx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNegativeTesting.cs
More file actions
83 lines (60 loc) · 3.47 KB
/
NegativeTesting.cs
File metadata and controls
83 lines (60 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using Xunit;
public class NegativeTesting
{
[Fact]
public static void OpenStandardOutNegativeTests()
{
NegativeConsoleOutputTests(Console.OpenStandardOutput());
}
[Fact]
public static void OpenStandardErrorNegativeTests()
{
NegativeConsoleOutputTests(Console.OpenStandardError());
}
private static void NegativeConsoleOutputTests(Stream stream)
{
//ConsoleStream.Length should throw NotSupportedException
Assert.Throws<NotSupportedException>(() => { long x = stream.Length; });
//ConsoleStream.get_Position should throw NotSupportedException
Assert.Throws<NotSupportedException>(() => { long x = stream.Position; });
//ConsoleStream.set_Position should throw NotSupportedException
Assert.Throws<NotSupportedException>(() => stream.Position = 50L);
//ConsoleStream.SetLength should throw NotSupportedException
Assert.Throws<NotSupportedException>(() => stream.SetLength(50L));
// Flushing a stream is fine.
stream.Flush();
//Read and write methods
//ConsoleStream.Read(null) should throw ArgumentNullException
Assert.Throws<ArgumentNullException>(() => stream.Read(null, 0, 1));
//ConsoleStream.Read() should throw ArgumentOutOfRangeException
Assert.Throws<ArgumentOutOfRangeException>(() => stream.Read(new byte[] { 0, 1 }, -1, 0));
//ConsoleStream.Read() should throw ArgumentOutOfRangeException
Assert.Throws<ArgumentOutOfRangeException>(() => stream.Read(new byte[] { 0, 1 }, 0, -1));
//ConsoleStream.Read() should throw ArgumentException
Assert.Throws<ArgumentException>(() => stream.Read(new byte[] { 0, 1 }, 0, 50));
//ConsoleStream.Read() should throw NotSupportedException
Assert.Throws<NotSupportedException>(() => stream.Read(new byte[] { 0, 1 }, 0, 2));
//ConsoleStream.Write() should throw ArgumentNullException
Assert.Throws<ArgumentNullException>(() => stream.Write(null, 0, 1));
//ConsoleStream.Write() should throw ArgumentOutOfRangeException
Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(new byte[] { 0, 1 }, -1, 0));
//ConsoleStream.Write() should throw ArgumentOutOfRangeException
Assert.Throws<ArgumentOutOfRangeException>(() => stream.Write(new byte[] { 0, 1 }, 0, -1));
//ConsoleStream.Write() should throw ArgumentException
Assert.Throws<ArgumentException>(() => stream.Write(new byte[] { 0, 1 }, 0, 50));
//ConsoleStream.Write() should throw NotSupportedException
Assert.Throws<NotSupportedException>(() => stream.Seek(0L, SeekOrigin.Begin));
// Close the stream and make sure we can no longer read, write or flush
stream.Dispose();
//ConsoleStream.Read() should throw NotSupportedException
Assert.Throws<NotSupportedException>(() => stream.Read(new byte[] { 0, 1 }, 0, 1));
//ConsoleStream.Write() should throw NotSupportedException
Assert.Throws<NotSupportedException>(() => stream.Write(new byte[] { 0, 1 }, 0, 1));
//ConsoleStream.Flush() should throw NotSupportedException
Assert.Throws<ObjectDisposedException>(() => stream.Flush());
}
}