File tree Expand file tree Collapse file tree
ScriptCs.Core/ReplCommands Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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" />
You can’t perform that action at this time.
0 commit comments