-
Notifications
You must be signed in to change notification settings - Fork 558
Expand file tree
/
Copy pathFakeConsole.cs
More file actions
49 lines (39 loc) · 1.27 KB
/
FakeConsole.cs
File metadata and controls
49 lines (39 loc) · 1.27 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace BootCamp.Chapter.Tests.Utils
{
public static class FakeConsole
{
public const string TestFileExtension = "consoleStub";
/// <summary>
/// To be used only if <see cref="StreamWriter"/> for stub console was used.
/// Read file of console input by testKey.
/// </summary>
public static string ReadAllText(string testKey)
{
var output = File.ReadAllText($"{testKey}.{TestFileExtension}");
return output;
}
/// <summary>
/// To be used only if <see cref="StreamWriter"/> for stub console was used.
/// Deletes the file for console using testKey.
/// </summary>
public static void Cleanup(string testKey)
{
File.Delete($"{testKey}.{TestFileExtension}");
}
}
public static class ConsoleStub
{
public static StringWriter StubConsole(string readLineReturn)
{
var output = new StringWriter();
Console.SetOut(output);
var input = new StringReader(readLineReturn);
Console.SetIn(input);
return output;
}
}
}