Skip to content

Commit f20f867

Browse files
committed
Additional unit tests.
1 parent 881a78e commit f20f867

5 files changed

Lines changed: 38 additions & 5 deletions

File tree

src/ScriptCs/Command/ExecuteReplCommand.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ internal class ExecuteReplCommand : IScriptCommand
2020
private readonly ILog _logger;
2121
private readonly IConsole _console;
2222

23+
public string[] ScriptArgs { get; private set; }
24+
2325
public ExecuteReplCommand(
2426
IFileSystem fileSystem,
2527
IScriptPackResolver scriptPackResolver,

src/ScriptCs/Command/ExecuteScriptCommand.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace ScriptCs.Command
1010
internal class ExecuteScriptCommand : IScriptCommand
1111
{
1212
private readonly string _script;
13-
private readonly string[] _scriptArgs;
1413
private readonly IFileSystem _fileSystem;
1514
private readonly IScriptExecutor _scriptExecutor;
1615
private readonly IScriptPackResolver _scriptPackResolver;
@@ -27,14 +26,16 @@ public ExecuteScriptCommand(string script,
2726
IAssemblyName assemblyName)
2827
{
2928
_script = script;
30-
_scriptArgs = scriptArgs;
29+
ScriptArgs = scriptArgs;
3130
_fileSystem = fileSystem;
3231
_scriptExecutor = scriptExecutor;
3332
_scriptPackResolver = scriptPackResolver;
3433
_logger = logger;
3534
_assemblyName = assemblyName;
3635
}
3736

37+
public string[] ScriptArgs { get; private set; }
38+
3839
public CommandResult Execute()
3940
{
4041
try
@@ -47,7 +48,7 @@ public CommandResult Execute()
4748
assemblyPaths = GetAssemblyPaths(workingDirectory);
4849
}
4950

50-
_scriptExecutor.Execute(_script, _scriptArgs, assemblyPaths, _scriptPackResolver.GetPacks());
51+
_scriptExecutor.Execute(_script, ScriptArgs, assemblyPaths, _scriptPackResolver.GetPacks());
5152
return CommandResult.Success;
5253
}
5354
catch (Exception ex)

src/ScriptCs/Command/ICommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace ScriptCs.Command
44
{
5-
public interface IScriptCommand : ICommand { }
5+
public interface IScriptCommand : ICommand {
6+
string[] ScriptArgs { get; }
7+
}
68

79
public interface IRestoreCommand : ICommand { }
810

test/ScriptCs.Core.Tests/ScriptHostTests.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,18 @@ public TheGetMethod()
2929
public void ShoulGetScriptPackFromScriptPackManagerWhenInvoked()
3030
{
3131
var result = _scriptHost.Require<IScriptPackContext>();
32-
_mockScriptPackManager.Verify(s=>s.Get<IScriptPackContext>());
32+
_mockScriptPackManager.Verify(s => s.Get<IScriptPackContext>());
33+
}
34+
}
35+
36+
public class TheConstructor
37+
{
38+
[Fact]
39+
public void ShouldSetScriptArgsWhenConstructed()
40+
{
41+
var scriptArgs = new string[0];
42+
var scriptHost = new ScriptHost(null, scriptArgs);
43+
scriptHost.ScriptArgs.ShouldEqual(scriptArgs);
3344
}
3445
}
3546
}

test/ScriptCs.Tests/CommandFactoryTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,23 @@ public void ShouldReturnHelpCommandWhenHelpIsPassed()
206206

207207
result.ShouldImplement<IHelpCommand>();
208208
}
209+
210+
[Fact]
211+
public void ShouldPassScriptArgsToExecuteCommandConstructor()
212+
{
213+
var args = new ScriptCsArgs
214+
{
215+
AllowPreRelease = false,
216+
Install = null,
217+
ScriptName = "test.csx"
218+
};
219+
220+
var scriptArgs = new string[0];
221+
var factory = new CommandFactory(CreateRoot());
222+
var result = factory.CreateCommand(args, scriptArgs) as IScriptCommand;
223+
224+
result.ScriptArgs.ShouldEqual(scriptArgs);
225+
}
209226
}
210227
}
211228
}

0 commit comments

Comments
 (0)