forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExecuteReplCommandTests.cs
More file actions
93 lines (75 loc) · 2.54 KB
/
Copy pathExecuteReplCommandTests.cs
File metadata and controls
93 lines (75 loc) · 2.54 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
84
85
86
87
88
89
90
91
92
93
using System;
using System.IO;
using System.Text;
using Common.Logging;
using Moq;
using ScriptCs.Command;
using ScriptCs.Package;
using Xunit;
namespace ScriptCs.Tests
{
public class ExecuteReplCommandTests
{
public class TheExecuteMethod
{
[Fact]
public void ShouldPromptForInput()
{
var mockFileSystem = new Mock<IFileSystem>();
mockFileSystem.SetupGet(x => x.CurrentDirectory).Returns("C:\\");
var builder = new StringBuilder();
var reader = new StringReader(Environment.NewLine);
var writer = new StringWriter(builder);
var console = new FakeConsole(writer, reader);
var root = new ScriptServiceRoot(
mockFileSystem.Object,
Mock.Of<IPackageAssemblyResolver>(),
Mock.Of<IScriptExecutor>(),
Mock.Of<IScriptEngine>(),
Mock.Of<IFilePreProcessor>(),
Mock.Of<IScriptPackResolver>(),
Mock.Of<IPackageInstaller>(),
Mock.Of<ILog>(),
Mock.Of<IAssemblyName>(),
console);
var commandFactory = new CommandFactory(root);
var target = commandFactory.CreateCommand(new ScriptCsArgs { Repl = true }, new string[0]);
target.Execute();
Assert.True(builder.ToString().EndsWith("> "));
Assert.Equal(1, console.ReadLineCounter);
}
}
public class FakeConsole : IConsole
{
private readonly TextWriter writer;
private readonly TextReader reader;
public FakeConsole(TextWriter textWriter, TextReader textReader)
{
writer = textWriter;
reader = textReader;
ReadLineCounter = 0;
}
public ConsoleColor ForegroundColor { get; set; }
public int ReadLineCounter { get; set; }
public void Write(string value)
{
writer.Write(value);
}
public void WriteLine(string value)
{
writer.WriteLine(value);
}
public string ReadLine()
{
ReadLineCounter++;
return reader.ReadLine();
}
public void Exit()
{
}
public void ResetColor()
{
}
}
}
}