From 5e7aa67614b26477e85c1e1a0fff3fb15f4ecf69 Mon Sep 17 00:00:00 2001 From: Ivan Basov Date: Mon, 13 Mar 2017 16:43:23 -0700 Subject: [PATCH 1/5] CSharpInteractiveCommands --- .../CSharp/CSharpInteractiveDemo.cs | 97 ------------------- 1 file changed, 97 deletions(-) delete mode 100644 src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpInteractiveDemo.cs diff --git a/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpInteractiveDemo.cs b/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpInteractiveDemo.cs deleted file mode 100644 index 74ff92b267d0d..0000000000000 --- a/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpInteractiveDemo.cs +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Threading.Tasks; -using Microsoft.VisualStudio.IntegrationTest.Utilities; -using Xunit; - -namespace Roslyn.VisualStudio.IntegrationTests.CSharp -{ - [Collection(nameof(SharedIntegrationHostFixture))] - public class CSharpInteractiveDemo : AbstractInteractiveWindowTest - { - public CSharpInteractiveDemo(VisualStudioInstanceFactory instanceFactory) - : base(instanceFactory) - { - } - - [Fact] - public void BclMathCall() - { - SubmitText("Math.Sin(1)"); - VerifyLastReplOutput("0.8414709848078965"); - } - - [Fact] - public void BclConsoleCall() - { - SubmitText(@"Console.WriteLine(""Hello, World!"");"); - VerifyLastReplOutput("Hello, World!"); - } - - [Fact] - public void ForStatement() - { - SubmitText("for (int i = 0; i < 10; i++) Console.WriteLine(i * i);"); - VerifyLastReplOutputEndsWith($"{81}"); - } - - [Fact] - public void ForEachStatement() - { - SubmitText(@"foreach (var f in System.IO.Directory.GetFiles(@""c:\windows"")) Console.WriteLine($""{f}"".ToLower());"); - VerifyLastReplOutputContains(@"c:\windows\win.ini"); - } - - [Fact] - public void TopLevelMethod() - { - SubmitText(@"int Fac(int x) -{ - return x < 1 ? 1 : x * Fac(x - 1); -} -Fac(4)"); - VerifyLastReplOutput($"{24}"); - } - - [Fact] - public async Task WpfInteraction() - { - SubmitText(@"#r ""WindowsBase"" -#r ""PresentationCore"" -#r ""PresentationFramework"" -#r ""System.Xaml"""); - - SubmitText(@"using System.Windows; -using System.Windows.Controls; -using System.Windows.Media; -using System.Windows.Media.Imaging;"); - - SubmitText(@"var w = new Window(); -w.Title = ""Hello World""; -w.FontFamily = new FontFamily(""Calibri""); -w.FontSize = 24; -w.Height = 300; -w.Width = 300; -w.Topmost = true; -w.Visibility = Visibility.Visible;"); - - var testValue = Guid.NewGuid(); - - SubmitText($@"var b = new Button(); -b.Content = ""{testValue}""; -b.Margin = new Thickness(40); -b.Click += (sender, e) => Console.WriteLine(""Hello, World!""); - -var g = new Grid(); -g.Children.Add(b); -w.Content = g;"); - - await VisualStudio.Instance.ClickAutomationElementAsync(testValue.ToString(), recursive: true); - - WaitForReplOutput("Hello, World!"); - VerifyLastReplOutput("Hello, World!"); - SubmitText("b = null; w.Close(); w = null;"); - } - } -} From 06a6371e5e858faf26c6a3592a200a60a3998941 Mon Sep 17 00:00:00 2001 From: Ivan Basov Date: Mon, 13 Mar 2017 16:46:12 -0700 Subject: [PATCH 2/5] CSharpInteractiveCommands --- .../AbstractInteractiveWindowTest.cs | 27 +++ .../CSharp/CSharpInteractiveCommands.cs | 154 ++++++++++++++++++ .../VisualStudioIntegrationTests.csproj | 1 + .../InProcess/InteractiveWindow_InProc.cs | 27 +++ .../InteractiveWindow_OutOfProc.cs | 9 + 5 files changed, 218 insertions(+) create mode 100644 src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpInteractiveCommands.cs diff --git a/src/VisualStudio/IntegrationTest/IntegrationTests/AbstractInteractiveWindowTest.cs b/src/VisualStudio/IntegrationTest/IntegrationTests/AbstractInteractiveWindowTest.cs index 434947ef322f7..fcded7fe00810 100644 --- a/src/VisualStudio/IntegrationTest/IntegrationTests/AbstractInteractiveWindowTest.cs +++ b/src/VisualStudio/IntegrationTest/IntegrationTests/AbstractInteractiveWindowTest.cs @@ -44,12 +44,39 @@ protected void Reset(bool waitForPrompt = true) protected void SubmitText(string text, bool waitForPrompt = true) => InteractiveWindow.SubmitText(text, waitForPrompt); + protected void SetText(string input) + { + VisualStudio.Instance.SendKeys.Send(input); + } + + protected void SendKeys(params object[] input) + { + VisualStudio.Instance.SendKeys.Send(input); + } + + protected void ExecuteCommand(string commandName) + { + VisualStudio.Instance.ExecuteCommand(commandName); + } + protected void VerifyLastReplOutput(string expectedReplOutput) { var lastReplOutput = InteractiveWindow.GetLastReplOutput(); Assert.Equal(expectedReplOutput, lastReplOutput); } + protected void VerifyLastReplInput(string expectedReplInput) + { + var lastReplInput = InteractiveWindow.GetLastReplInput(); + Assert.Equal(expectedReplInput, lastReplInput); + } + + protected void VerifyCaretPositionColumn(int expectedCaretPosition) + { + var caretPosition = InteractiveWindow.GetCaretPositionColumn(); + Assert.Equal(expectedCaretPosition, caretPosition); + } + protected void VerifyLastReplOutputContains(string expectedReplOutput) { var lastReplOutput = InteractiveWindow.GetLastReplOutput(); diff --git a/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpInteractiveCommands.cs b/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpInteractiveCommands.cs new file mode 100644 index 0000000000000..2491d7b3c13f3 --- /dev/null +++ b/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpInteractiveCommands.cs @@ -0,0 +1,154 @@ +// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.VisualStudio.IntegrationTest.Utilities; +using Microsoft.VisualStudio.IntegrationTest.Utilities.Input; +using Xunit; + +namespace Roslyn.VisualStudio.IntegrationTests.CSharp +{ + [Collection(nameof(SharedIntegrationHostFixture))] + public class CSharpInteractiveCommands : AbstractInteractiveWindowTest + { + public CSharpInteractiveCommands(VisualStudioInstanceFactory instanceFactory) + : base(instanceFactory) + { + } + + [Fact] + public void VerifyPreviousAndNextHistory() + { + SubmitText("1 + 2"); + SubmitText("1.ToString()"); + SendKeys(new KeyPress(VirtualKey.Up, ShiftState.Alt)); + Wait(); + VerifyLastReplInput("1.ToString()"); + SendKeys(VirtualKey.Enter); + Wait(); + VerifyLastReplOutput("\"1\""); + SendKeys(new KeyPress(VirtualKey.Up, ShiftState.Alt)); + Wait(); + VerifyLastReplInput("1.ToString()"); + SendKeys(new KeyPress(VirtualKey.Up, ShiftState.Alt)); + Wait(); + VerifyLastReplInput("1 + 2"); + SendKeys(VirtualKey.Enter); + Wait(); + VerifyLastReplOutput("3"); + SendKeys(new KeyPress(VirtualKey.Down, ShiftState.Alt)); + Wait(); + VerifyLastReplInput("1.ToString()"); + SendKeys(VirtualKey.Enter); + Wait(); + VerifyLastReplOutput("\"1\""); + } + + [Fact] + public void VerifyMaybeExecuteInput() + { + SetText("2 + 3"); + SendKeys(VirtualKey.Enter); + Wait(); + VerifyLastReplOutput("5"); + } + + [Fact] + public void VerifyNewLineAndIndent() + { + SetText("3 + "); + SendKeys(VirtualKey.Enter); + SetText("4"); + SendKeys(VirtualKey.Enter); + Wait(); + VerifyLastReplOutput("7"); + } + + [Fact] + public void VerifyExecuteInput() + { + SubmitText("1 + "); + VerifyLastReplOutputContains("CS1733"); + } + + [Fact] + public void VerifyForceNewLineAndIndent() + { + SetText("1 + 2"); + SendKeys(VirtualKey.Enter); + Wait(); + SubmitText("+ 3"); + VerifyReplPromptConsistency("", "6"); + } + + [Fact] + public void VerifyCancelInput() + { + SetText("1 + 4"); + SendKeys(new KeyPress(VirtualKey.Enter, ShiftState.Shift)); + SendKeys(VirtualKey.Escape); + Wait(); + VerifyLastReplInput(string.Empty); + } + + [Fact] + public void VerifyUndoAndRedo() + { + ClearReplText(); + SetText(" 2 + 4 "); + SendKeys(new KeyPress(VirtualKey.Z, ShiftState.Ctrl)); + // < VerifyReplInput > + // < ![CDATA[]] > + // + VerifyLastReplInput(string.Empty); + SendKeys(new KeyPress(VirtualKey.Y, ShiftState.Ctrl)); + VerifyLastReplInput(" 2 + 4 "); + SendKeys(VirtualKey.Enter); + Wait(); + VerifyLastReplOutput("6"); + } + + [Fact] + public void CutDeletePasteSelectAll() + { + SetText("Text"); + ExecuteCommand("Edit.LineStart"); + ExecuteCommand("Edit.LineEnd"); + ExecuteCommand("Edit.LineStartExtend"); + ExecuteCommand("Edit.SelectionCancel"); + ExecuteCommand("Edit.LineEndExtend"); + ExecuteCommand("Edit.SelectAll"); + ExecuteCommand("Edit.SelectAll"); + ExecuteCommand("Edit.Copy"); + ExecuteCommand("Edit.Cut"); + ExecuteCommand("Edit.Paste"); + ExecuteCommand("Edit.Delete"); + ExecuteCommand("Edit.LineUp"); + ExecuteCommand("Edit.LineDown"); + ExecuteCommand("Edit.Paste"); + ExecuteCommand("Edit.Paste"); + SendKeys(VirtualKey.Escape); + } + + // + //