public void VerifyOutput(string code)
        {
            UiExecutionEntry[] executions = GetExecutions().Take(2).ToArray();

            Assert.Equal(2, executions.Length);

            UiExecutionEntry currentEntry  = executions[0];
            UiExecutionEntry lastExecution = executions[1];

            // Capture code output
            string expectedOutput;
            string expectedError;

            using (StringWriter outputWriter = new StringWriter())
                using (StringWriter errorWriter = new StringWriter())
                {
                    TextWriter originalOutput = Console.Out;
                    TextWriter originalError  = Console.Error;

                    try
                    {
                        Console.SetOut(outputWriter);
                        Console.SetError(errorWriter);

                        DebugOutput captureFlags = DebugOutput.Normal | DebugOutput.Error | DebugOutput.Warning | DebugOutput.Verbose
                                                   | DebugOutput.Prompt | DebugOutput.PromptRegisters | DebugOutput.ExtensionWarning | DebugOutput.Debuggee
                                                   | DebugOutput.DebuggeePrompt | DebugOutput.Symbols | DebugOutput.Status;
                        var callbacks = DebuggerOutputToTextWriter.Create(outputWriter, captureFlags);
                        using (OutputCallbacksSwitcher switcher = OutputCallbacksSwitcher.Create(callbacks))
                        {
                            InteractiveExecution.Interpret(code);
                        }

                        expectedOutput = outputWriter.GetStringBuilder().ToString();
                        expectedError  = errorWriter.GetStringBuilder().ToString();
                    }
                    finally
                    {
                        Console.SetOut(originalOutput);
                        Console.SetError(originalError);
                    }
                }

            // Verify that output is the same
            if (currentEntry.Code == lastExecution.Code)
            {
                Assert.Equal(FixOutput(expectedError), FixOutput(lastExecution.ResultText));
            }
            else
            {
                Assert.Equal(FixOutput(expectedOutput), FixOutput(lastExecution.ResultText));
            }
        }
        public void WaitForExecutionEnd(TimeSpan timeout)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            bool      awaited   = false;

            while (stopwatch.Elapsed < timeout)
            {
                UiExecutionEntry[] executions = GetExecutions().Take(2).ToArray();

                if (executions.Length > 0)
                {
                    UiExecutionEntry currentEntry = executions[0];

                    if (currentEntry.Code == "")
                    {
                        awaited = true;
                        break;
                    }

                    if (currentEntry.Prompt == DefaultPrompt && executions.Length > 1)
                    {
                        UiExecutionEntry lastExecution = executions[1];

                        if (lastExecution.Code == currentEntry.Code)
                        {
                            awaited = true;
                            break;
                        }
                    }
                }

                System.Threading.Thread.Sleep(100);
            }

            Assert.True(awaited, "Command didn't execute");
        }