1313using Microsoft . PowerShell . EditorServices . Handlers ;
1414using Microsoft . PowerShell . EditorServices . Services ;
1515using Microsoft . PowerShell . EditorServices . Services . DebugAdapter ;
16+ using Microsoft . PowerShell . EditorServices . Services . PowerShell . Console ;
1617using Microsoft . PowerShell . EditorServices . Services . PowerShell . Host ;
1718using Microsoft . PowerShell . EditorServices . Services . TextDocument ;
1819using Microsoft . PowerShell . EditorServices . Test ;
2223
2324namespace PowerShellEditorServices . Test . Debugging
2425{
26+ internal class TestReadLine : IReadLine
27+ {
28+ public List < string > history = new ( ) ;
29+
30+ public string ReadLine ( CancellationToken cancellationToken ) => "" ;
31+
32+ public void AddToHistory ( string historyEntry ) => history . Add ( historyEntry ) ;
33+ }
34+
2535 [ Trait ( "Category" , "DebugService" ) ]
2636 public class DebugServiceTests : IDisposable
2737 {
@@ -32,13 +42,15 @@ public class DebugServiceTests : IDisposable
3242 private readonly WorkspaceService workspace ;
3343 private readonly ScriptFile debugScriptFile ;
3444 private readonly ScriptFile variableScriptFile ;
45+ private readonly TestReadLine testReadLine = new ( ) ;
3546
3647 public DebugServiceTests ( )
3748 {
3849 psesHost = PsesHostFactory . Create ( NullLoggerFactory . Instance ) ;
3950 // This is required for remote debugging, but we call it here to end up in the same
4051 // state as the usual startup path.
4152 psesHost . DebugContext . EnableDebugMode ( ) ;
53+ psesHost . _readLineProvider . ReadLine = testReadLine ;
4254
4355 breakpointService = new BreakpointService (
4456 NullLoggerFactory . Instance ,
@@ -558,6 +570,50 @@ await debugService.SetCommandBreakpointsAsync(
558570 Assert . Equal ( "\" . $args[0]\" " , myInvocationLine . ValueString ) ;
559571 }
560572
573+ [ Fact ]
574+ public async Task RecordsF5CommandInPowerShellHistory ( )
575+ {
576+ ConfigurationDoneHandler configurationDoneHandler = new (
577+ NullLoggerFactory . Instance , null , debugService , null , null , psesHost , workspace , null , psesHost ) ;
578+ await configurationDoneHandler . LaunchScriptAsync ( debugScriptFile . FilePath ) . ConfigureAwait ( true ) ;
579+
580+ IReadOnlyList < string > historyResult = await psesHost . ExecutePSCommandAsync < string > (
581+ new PSCommand ( ) . AddScript ( "(Get-History).CommandLine" ) ,
582+ CancellationToken . None ) . ConfigureAwait ( true ) ;
583+
584+ // Check the PowerShell history
585+ Assert . Single ( historyResult ) ;
586+ Assert . Equal ( ". \" " + debugScriptFile . FilePath + "\" " , historyResult [ 0 ] ) ;
587+
588+ // Check the stubbed PSReadLine history
589+ Assert . Single ( testReadLine . history ) ;
590+ Assert . Equal ( ". \" " + debugScriptFile . FilePath + "\" " , testReadLine . history [ 0 ] ) ;
591+ }
592+
593+ [ Fact ]
594+ public async Task RecordsF8CommandInHistory ( )
595+ {
596+ const string script = "Write-Output Hello" ;
597+ EvaluateHandler evaluateHandler = new ( psesHost ) ;
598+ EvaluateResponseBody evaluateResponseBody = await evaluateHandler . Handle (
599+ new EvaluateRequestArguments { Expression = script , Context = "repl" } ,
600+ CancellationToken . None ) . ConfigureAwait ( true ) ;
601+ // TODO: Right now this response is hard-coded, maybe it should change?
602+ Assert . Equal ( "" , evaluateResponseBody . Result ) ;
603+
604+ IReadOnlyList < string > historyResult = await psesHost . ExecutePSCommandAsync < string > (
605+ new PSCommand ( ) . AddScript ( "(Get-History).CommandLine" ) ,
606+ CancellationToken . None ) . ConfigureAwait ( true ) ;
607+
608+ // Check the PowerShell history
609+ Assert . Single ( historyResult ) ;
610+ Assert . Equal ( script , historyResult [ 0 ] ) ;
611+
612+ // Check the stubbed PSReadLine history
613+ Assert . Single ( testReadLine . history ) ;
614+ Assert . Equal ( script , testReadLine . history [ 0 ] ) ;
615+ }
616+
561617 [ Fact ]
562618 public async Task DebuggerVariableStringDisplaysCorrectly ( )
563619 {
0 commit comments