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
94 lines (77 loc) · 3.39 KB
/
ExecuteReplCommandTests.cs
File metadata and controls
94 lines (77 loc) · 3.39 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
94
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Moq;
using Ploeh.AutoFixture.Xunit;
using ScriptCs.Command;
using ScriptCs.Contracts;
using Should;
using Xunit.Extensions;
using System;
namespace ScriptCs.Tests
{
public class ExecuteReplCommandTests
{
public class TheExecuteMethod
{
[Theory, ScriptCsAutoData]
public void ShouldPromptForInput(
[Frozen] Mock<IFileSystem> fileSystem,
[Frozen] Mock<IConsole> console,
CommandFactory factory)
{
// Arrange
var readLines = 0;
var builder = new StringBuilder();
var args = new ScriptCsArgs { Repl = true };
fileSystem.SetupGet(x => x.CurrentDirectory).Returns("C:\\");
console.Setup(x => x.ReadLine()).Callback(() => readLines++).Throws(new Exception());
console.Setup(x => x.Write(It.IsAny<string>())).Callback<string>(value => builder.Append(value));
// Act
factory.CreateCommand(args, new string[0]).Execute();
// Assert
builder.ToString().EndsWith("> ").ShouldBeTrue();
readLines.ShouldEqual(1);
}
[Theory, ScriptCsAutoData]
public void WhenPassedAScript_ShouldPressedReplWithScript(
[Frozen] Mock<IScriptEngine> scriptEngine, [Frozen] Mock<IFileSystem> fileSystem, [Frozen] Mock<IConsole> console,
CommandFactory factory)
{
// Arrange
var args = new ScriptCsArgs { Repl = true, ScriptName = "test.csx" };
console.Setup(x => x.ReadLine()).Returns(() =>
{
console.Setup(x => x.ReadLine()).Throws(new Exception());
return string.Empty;
});
fileSystem.SetupGet(x => x.CurrentDirectory).Returns("C:\\");
scriptEngine.Setup(
x => x.Execute("#load test.csx", It.IsAny<string[]>(), It.IsAny<AssemblyReferences>(), It.IsAny<IEnumerable<string>>(), It.IsAny<ScriptPackSession>()));
// Act
factory.CreateCommand(args, new string[0]).Execute();
// Assert
scriptEngine.Verify();
}
[Theory, ScriptCsAutoData]
public void WhenNotPassedAScript_ShouldNotCallTheEngineAutomatically(
[Frozen] Mock<IScriptEngine> scriptEngine, [Frozen] Mock<IFileSystem> fileSystem, [Frozen] Mock<IConsole> console,
CommandFactory factory)
{
// Arrange
var args = new ScriptCsArgs { Repl = true };
console.Setup(x => x.ReadLine()).Returns(() =>
{
console.Setup(x => x.ReadLine()).Throws(new Exception());
return string.Empty;
});
fileSystem.SetupGet(x => x.CurrentDirectory).Returns("C:\\");
// Act
factory.CreateCommand(args, new string[0]).Execute();
// Assert
scriptEngine.Verify(
x => x.Execute(It.IsAny<string>(), It.IsAny<string[]>(), It.IsAny<AssemblyReferences>(), It.IsAny<IEnumerable<string>>(), It.IsAny<ScriptPackSession>()), Times.Never());
}
}
}
}