public async Task ServiceExecutesReplCommandAndReceivesInputPrompt()
        {
            OutputReader outputReader = new OutputReader(this.messageHandlers);

            // Send the configuration request to initiate the command loop
            await this.SendConfigurationRequest(outputReader);

            string promptScript =
                @"
                $NameField = New-Object System.Management.Automation.Host.FieldDescription ""Name""
                $NameField.SetParameterType([System.String])
                $fields = [System.Management.Automation.Host.FieldDescription[]]($NameField)
                $host.ui.Prompt($null, $null, $fields)";

            Task <Tuple <ShowInputPromptRequest, RequestContext <ShowInputPromptResponse> > > inputPromptTask =
                this.WaitForRequest(ShowInputPromptRequest.Type);

            // Execute the script but don't await the task yet because
            // the choice prompt will block execution from completing
            Task <EvaluateResponseBody> evaluateTask =
                this.SendRequest(
                    EvaluateRequest.Type,
                    new EvaluateRequestArguments
            {
                Expression = promptScript,
                Context    = "repl"
            });

            // Wait for the input prompt request and check expected values
            Tuple <ShowInputPromptRequest, RequestContext <ShowInputPromptResponse> > requestResponseContext = await inputPromptTask;
            ShowInputPromptRequest showInputPromptRequest           = requestResponseContext.Item1;
            RequestContext <ShowInputPromptResponse> requestContext = requestResponseContext.Item2;

            Assert.Equal("Name", showInputPromptRequest.Name);

            // Respond to the prompt request
            await requestContext.SendResult(
                new ShowInputPromptResponse
            {
                ResponseText = "John"
            });

            // Skip the initial 4 script lines
            string[] scriptLines = await outputReader.ReadLines(4);

            // Verify the first line
            Assert.Equal("Name: John", await outputReader.ReadLine());

            // Verify the rest of the output
            string[] outputLines = await outputReader.ReadLines(4);

            Assert.Equal("", outputLines[0]);
            Assert.Equal("Key  Value", outputLines[1]);
            Assert.Equal("---  -----", outputLines[2]);
            Assert.Equal("Name John ", outputLines[3]);

            // Wait for execution to complete
            await evaluateTask;
        }
        public async Task ServiceExecutesReplCommandAndReceivesChoicePrompt()
        {
            OutputReader outputReader = new OutputReader(this.messageHandlers);

            // Send the configuration request to initiate the command loop
            await this.SendConfigurationRequest(outputReader);

            string choiceScript =
                @"
                $caption = ""Test Choice"";
                $message = ""Make a selection"";
                $choiceA = New-Object System.Management.Automation.Host.ChoiceDescription ""&Apple"",""Help for Apple"";
                $choiceB = New-Object System.Management.Automation.Host.ChoiceDescription ""Banana"",""Help for Banana"";
                $choices = [System.Management.Automation.Host.ChoiceDescription[]]($choiceA,$choiceB);
                $host.ui.PromptForChoice($caption, $message, $choices, 1)";

            Task <Tuple <ShowChoicePromptRequest, RequestContext <ShowChoicePromptResponse> > > choicePromptTask =
                this.WaitForRequest(ShowChoicePromptRequest.Type);

            // Execute the script but don't await the task yet because
            // the choice prompt will block execution from completing
            Task <EvaluateResponseBody> evaluateTask =
                this.SendRequest(
                    EvaluateRequest.Type,
                    new EvaluateRequestArguments
            {
                Expression = choiceScript,
                Context    = "repl"
            });

            // Wait for the choice prompt request and check expected values
            Tuple <ShowChoicePromptRequest, RequestContext <ShowChoicePromptResponse> > requestResponseContext = await choicePromptTask;
            ShowChoicePromptRequest showChoicePromptRequest          = requestResponseContext.Item1;
            RequestContext <ShowChoicePromptResponse> requestContext = requestResponseContext.Item2;

            Assert.Equal(1, showChoicePromptRequest.DefaultChoices[0]);

            // Respond to the prompt request
            await requestContext.SendResult(
                new ShowChoicePromptResponse
            {
                ResponseText = "a"
            });

            // Skip the initial script and prompt lines (6 script lines plus 3 prompt lines)
            string[] outputLines = await outputReader.ReadLines(9);

            // Wait for the selection to appear as output
            await evaluateTask;

            Assert.Equal("0", await outputReader.ReadLine());
        }
        public async Task DebugAdapterReceivesOutputEvents()
        {
            OutputReader outputReader = new OutputReader(this.debugAdapterClient);

            await this.LaunchScript(DebugScriptPath);

            // Skip the first 2 lines which just report the script
            // that is being executed
            await outputReader.ReadLines(2);

            // Make sure we're getting output from the script
            Assert.Equal("Output 1", await outputReader.ReadLine());

            // Abort script execution
            await this.SendRequest(DisconnectRequest.Type, new object());
        }
        public async Task ServiceExecutesNativeCommandAndReceivesCommand()
        {
            OutputReader outputReader = new OutputReader(this.messageHandlers);

            // Execute the script but don't await the task yet because
            // the choice prompt will block execution from completing
            Task <EvaluateResponseBody> evaluateTask =
                this.SendRequest(
                    EvaluateRequest.Type,
                    new EvaluateRequestArguments
            {
                Expression = "cmd.exe /c 'echo Test Output'",
                Context    = "repl"
            });

            // Skip the command line and the following newline
            await outputReader.ReadLines(2);

            // Wait for the selection to appear as output
            await evaluateTask;

            Assert.Equal("Test Output", await outputReader.ReadLine());
        }
        public async Task ServiceExecutesNativeCommandAndReceivesCommand()
        {
            OutputReader outputReader = new OutputReader(this.protocolClient);

            // Execute the script but don't await the task yet because
            // the choice prompt will block execution from completing
            Task<EvaluateResponseBody> evaluateTask =
                this.SendRequest(
                    EvaluateRequest.Type,
                    new EvaluateRequestArguments
                    {
                        Expression = "cmd.exe /c 'echo Test Output'",
                        Context = "repl"
                    });

            // Skip the command line and the following newline
            await outputReader.ReadLines(2);

            // Wait for the selection to appear as output
            await evaluateTask;
            Assert.Equal("Test Output", await outputReader.ReadLine());
        }
        public async Task ServiceExecutesReplCommandAndReceivesInputPrompt()
        {
            OutputReader outputReader = new OutputReader(this.protocolClient);

            string promptScript =
                @"
                $NameField = New-Object System.Management.Automation.Host.FieldDescription ""Name""
                $NameField.SetParameterType([System.String])
                $fields = [System.Management.Automation.Host.FieldDescription[]]($NameField)
                $host.ui.Prompt($null, $null, $fields)";

            Task<Tuple<ShowInputPromptRequest, RequestContext<ShowInputPromptResponse>>> inputPromptTask =
                this.WaitForRequest(ShowInputPromptRequest.Type);

            // Execute the script but don't await the task yet because
            // the choice prompt will block execution from completing
            Task<EvaluateResponseBody> evaluateTask =
                this.SendRequest(
                    EvaluateRequest.Type,
                    new EvaluateRequestArguments
                    {
                        Expression = promptScript,
                        Context = "repl"
                    });
            
            // Wait for the input prompt request and check expected values
            Tuple<ShowInputPromptRequest, RequestContext<ShowInputPromptResponse>> requestResponseContext = await inputPromptTask;
            ShowInputPromptRequest showInputPromptRequest = requestResponseContext.Item1;
            RequestContext<ShowInputPromptResponse> requestContext = requestResponseContext.Item2;

            Assert.Equal("Name", showInputPromptRequest.Name);

            // Respond to the prompt request
            await requestContext.SendResult(
                new ShowInputPromptResponse
                {
                    ResponseText = "John"
                });

            // Skip the initial script lines (4 script lines plus 2 blank lines)
            string[] scriptLines = await outputReader.ReadLines(6);

            // In some cases an extra newline appears after the script lines.
            // I have no idea why this happens, but it normally seems to occur
            // on my local machine and not the CI server.  For now, adjust for
            // it here.
            string outputLine = await outputReader.ReadLine();
            if (string.IsNullOrEmpty(outputLine))
            {
                outputLine = await outputReader.ReadLine();
            }

            // Verify the first line
            Assert.Equal("Name: John", outputLine);

            // Verify the rest of the output
            string[] outputLines = await outputReader.ReadLines(4);
            Assert.Equal("", outputLines[0]);
            Assert.Equal("Key  Value", outputLines[1]);
            Assert.Equal("---  -----", outputLines[2]);
            Assert.Equal("Name John ", outputLines[3]);

            // Wait for execution to complete
            await evaluateTask;
        }
        public async Task ServiceExecutesReplCommandAndReceivesChoicePrompt()
        {
            OutputReader outputReader = new OutputReader(this.protocolClient);

            string choiceScript =
                @"
                $caption = ""Test Choice"";
                $message = ""Make a selection"";
                $choiceA = New-Object System.Management.Automation.Host.ChoiceDescription ""&Apple"",""Help for Apple"";
                $choiceB = New-Object System.Management.Automation.Host.ChoiceDescription ""Banana"",""Help for Banana"";
                $choices = [System.Management.Automation.Host.ChoiceDescription[]]($choiceA,$choiceB);
                $host.ui.PromptForChoice($caption, $message, $choices, 1)";

            Task<Tuple<ShowChoicePromptRequest, RequestContext<ShowChoicePromptResponse>>> choicePromptTask =
                this.WaitForRequest(ShowChoicePromptRequest.Type);

            // Execute the script but don't await the task yet because
            // the choice prompt will block execution from completing
            Task<EvaluateResponseBody> evaluateTask =
                this.SendRequest(
                    EvaluateRequest.Type,
                    new EvaluateRequestArguments
                    {
                        Expression = choiceScript,
                        Context = "repl"
                    });

            // Wait for the choice prompt request and check expected values
            Tuple<ShowChoicePromptRequest, RequestContext<ShowChoicePromptResponse>> requestResponseContext = await choicePromptTask;
            ShowChoicePromptRequest showChoicePromptRequest = requestResponseContext.Item1;
            RequestContext<ShowChoicePromptResponse> requestContext = requestResponseContext.Item2;

            Assert.Equal(1, showChoicePromptRequest.DefaultChoice);

            // Respond to the prompt request
            await requestContext.SendResult(
                new ShowChoicePromptResponse
                {
                    ChosenItem = "a"
                });

            // Skip the initial script lines (6 script lines plus 3 blank lines)
            await outputReader.ReadLines(9);

            // Wait for the selection to appear as output
            await evaluateTask;
            Assert.Equal("0", await outputReader.ReadLine());
        }
        public async Task ServiceExecutesReplCommandAndReceivesInputPrompt()
        {
            OutputReader outputReader = new OutputReader(this.protocolClient);

            string promptScript =
                @"
                $NameField = New-Object System.Management.Automation.Host.FieldDescription ""Name""
                $NameField.SetParameterType([System.String])
                $fields = [System.Management.Automation.Host.FieldDescription[]]($NameField)
                $host.ui.Prompt($null, $null, $fields)";

            Task <Tuple <ShowInputPromptRequest, RequestContext <ShowInputPromptResponse> > > inputPromptTask =
                this.WaitForRequest(ShowInputPromptRequest.Type);

            // Execute the script but don't await the task yet because
            // the choice prompt will block execution from completing
            Task <EvaluateResponseBody> evaluateTask =
                this.SendRequest(
                    EvaluateRequest.Type,
                    new EvaluateRequestArguments
            {
                Expression = promptScript,
                Context    = "repl"
            });

            // Wait for the input prompt request and check expected values
            Tuple <ShowInputPromptRequest, RequestContext <ShowInputPromptResponse> > requestResponseContext = await inputPromptTask;
            ShowInputPromptRequest showInputPromptRequest           = requestResponseContext.Item1;
            RequestContext <ShowInputPromptResponse> requestContext = requestResponseContext.Item2;

            Assert.Equal("Name", showInputPromptRequest.Name);

            // Respond to the prompt request
            await requestContext.SendResult(
                new ShowInputPromptResponse
            {
                ResponseText = "John"
            });

            // Skip the initial script lines (4 script lines plus 2 blank lines)
            string[] scriptLines = await outputReader.ReadLines(6);

            // In some cases an extra newline appears after the script lines.
            // I have no idea why this happens, but it normally seems to occur
            // on my local machine and not the CI server.  For now, adjust for
            // it here.
            string outputLine = await outputReader.ReadLine();

            if (string.IsNullOrEmpty(outputLine))
            {
                outputLine = await outputReader.ReadLine();
            }

            // Verify the first line
            Assert.Equal("Name: John", outputLine);

            // Verify the rest of the output
            string[] outputLines = await outputReader.ReadLines(4);

            Assert.Equal("", outputLines[0]);
            Assert.Equal("Key  Value", outputLines[1]);
            Assert.Equal("---  -----", outputLines[2]);
            Assert.Equal("Name John ", outputLines[3]);

            // Wait for execution to complete
            await evaluateTask;
        }