Skip to content

Commit 2d0a88b

Browse files
committed
added first tests
1 parent efb76d5 commit 2d0a88b

4 files changed

Lines changed: 55 additions & 4 deletions

File tree

src/ScriptCs.Contracts/ScriptPackSession.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private void AddScriptContextNamespace()
3737
}
3838
}
3939

40-
public IEnumerable<IScriptPackContext> Contexts
40+
public virtual IEnumerable<IScriptPackContext> Contexts
4141
{
4242
get { return _contexts; }
4343
}

src/ScriptCs.Core/ReplCommands/ScriptPacksCommand.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,22 @@ public string CommandName
3030
public object Execute(IRepl repl, object[] args)
3131
{
3232
var packContexts = repl.ScriptPackSession.Contexts;
33+
var originalColor = _console.ForegroundColor;
34+
_console.ForegroundColor = ConsoleColor.Yellow;
35+
3336
if (packContexts.IsNullOrEmpty())
3437
{
3538
_console.WriteLine("There are no script packs available in this REPL session");
39+
_console.ForegroundColor = originalColor;
3640
return null;
3741
}
3842

3943
var importedNamespaces = repl.Namespaces.Union(repl.ScriptPackSession.Namespaces).ToArray();
40-
var originalColor = _console.ForegroundColor;
4144

4245
foreach (var packContext in packContexts)
4346
{
4447
var contextType = packContext.GetType();
45-
46-
_console.ForegroundColor = ConsoleColor.Yellow;
48+
4749
_console.WriteLine(contextType.ToString());
4850
_console.ForegroundColor = originalColor;
4951

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Moq;
4+
using ScriptCs.Contracts;
5+
using ScriptCs.ReplCommands;
6+
using Xunit;
7+
8+
namespace ScriptCs.Tests.ReplCommands
9+
{
10+
public class ScriptPacksCommandTests
11+
{
12+
public class CommandNameProperty
13+
{
14+
[Fact]
15+
public void ReturnsScriptPacks()
16+
{
17+
// act
18+
var cmd = new ScriptPacksCommand(new Mock<IConsole>().Object);
19+
20+
// assert
21+
Assert.Equal("scriptpacks", cmd.CommandName);
22+
}
23+
}
24+
25+
public class ExecuteMethod
26+
{
27+
[Fact]
28+
public void ShouldExitIfThereAreNoScriptPacks()
29+
{
30+
// arrange
31+
var console = new Mock<IConsole>();
32+
var repl = new Mock<IRepl>();
33+
var scriptPackSession = new Mock<ScriptPackSession>(Enumerable.Empty<IScriptPack>(), new string[0]);
34+
35+
scriptPackSession.Setup(x => x.Contexts).Returns((IEnumerable<IScriptPackContext>) null);
36+
repl.Setup(x => x.ScriptPackSession).Returns(scriptPackSession.Object);
37+
38+
var cmd = new ScriptPacksCommand(console.Object);
39+
40+
// act
41+
cmd.Execute(repl.Object, null);
42+
43+
// assert
44+
console.Verify(x => x.WriteLine("There are no script packs available in this REPL session"));
45+
}
46+
}
47+
}
48+
}

test/ScriptCs.Core.Tests/ScriptCs.Core.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
<Compile Include="FileSystemMigratorTests.cs" />
5757
<Compile Include="PackageReferenceTests.cs" />
5858
<Compile Include="ReplCommands\HelpCommandTests.cs" />
59+
<Compile Include="ReplCommands\ScriptPacksCommandTests.cs" />
5960
<Compile Include="ScriptLibraryComposerTests.cs" />
6061
<Compile Include="ReferenceLineProcessorTests.cs" />
6162
<Compile Include="LoadLineProcessorTests.cs" />

0 commit comments

Comments
 (0)