forked from dotnet/corefx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetIn.cs
More file actions
65 lines (58 loc) · 1.66 KB
/
SetIn.cs
File metadata and controls
65 lines (58 loc) · 1.66 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
// 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;
//
// System.Console BCL test cases
//
public class SetIn
{
[Fact]
public static void SetInThrowsOnNull()
{
TextReader savedIn = Console.In;
try
{
Assert.Throws<ArgumentNullException>(() => Console.SetIn(null));
}
finally
{
Console.SetIn(savedIn);
}
}
[Fact]
public static void SetInReadLine()
{
const string TextStringFormat = "Test {0}";
TextReader oldInToRestore = Console.In;
try
{
using (MemoryStream memStream = new MemoryStream())
{
using (StreamWriter sw = new StreamWriter(memStream))
{
for (int i = 0; i < 20; i++)
{
sw.WriteLine(string.Format(TextStringFormat, i));
}
sw.Flush();
memStream.Seek(0, SeekOrigin.Begin);
using (StreamReader sr = new StreamReader(memStream))
{
Console.SetIn(sr);
Assert.NotNull(Console.In);
for (int i = 0; i < 20; i++)
{
Assert.Equal(string.Format(TextStringFormat, i), Console.ReadLine());
}
}
}
}
}
finally
{
Console.SetIn(oldInToRestore);
}
}
}