Skip to content

Commit

Permalink
Ivanbasov/integration tests (#17885)
Browse files Browse the repository at this point in the history
Integration tests for CSharpInteractiveCommands
  • Loading branch information
ivanbasov authored Mar 16, 2017
1 parent 8e5a0b0 commit 2ba0d8f
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Common;
using Microsoft.VisualStudio.IntegrationTest.Utilities.InProcess;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Microsoft.VisualStudio.IntegrationTest.Utilities.OutOfProcess;
using Roslyn.Test.Utilities;
Expand Down Expand Up @@ -138,15 +137,6 @@ protected int GetErrorListErrorCount()
protected void SendKeys(params object[] keys)
=> Editor.SendKeys(keys);

protected KeyPress KeyPress(VirtualKey virtualKey, ShiftState shiftState)
=> new KeyPress(virtualKey, shiftState);

protected KeyPress Ctrl(VirtualKey virtualKey)
=> new KeyPress(virtualKey, ShiftState.Ctrl);

protected KeyPress Shift(VirtualKey virtualKey)
=> new KeyPress(virtualKey, ShiftState.Shift);

protected void DisableSuggestionMode()
=> VisualStudioWorkspaceOutOfProc.SetUseSuggestionMode(false);

Expand Down Expand Up @@ -175,9 +165,6 @@ protected void InvokeCodeActionList()
WaitForAsyncOperations(FeatureAttribute.LightBulb);
}

protected void ExecuteCommand(string commandName, string argument = "")
=> VisualStudio.Instance.ExecuteCommand(commandName, argument);

private void VerifyCurrentLineTextAndAssertCaretPosition(string expectedText, bool trimWhitespace)
{
var caretStartIndex = expectedText.IndexOf("$$");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Threading;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;

namespace Roslyn.VisualStudio.IntegrationTests
{
Expand All @@ -24,5 +25,20 @@ protected void Wait(double seconds)
var timeout = TimeSpan.FromMilliseconds(seconds * 1000);
Thread.Sleep(timeout);
}

protected KeyPress KeyPress(VirtualKey virtualKey, ShiftState shiftState)
=> new KeyPress(virtualKey, shiftState);

protected KeyPress Ctrl(VirtualKey virtualKey)
=> new KeyPress(virtualKey, ShiftState.Ctrl);

protected KeyPress Shift(VirtualKey virtualKey)
=> new KeyPress(virtualKey, ShiftState.Shift);

protected KeyPress Alt(VirtualKey virtualKey)
=> new KeyPress(virtualKey, ShiftState.Alt);

protected void ExecuteCommand(string commandName, string argument = "")
=> VisualStudio.Instance.ExecuteCommand(commandName, argument);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected AbstractInteractiveWindowTest(VisualStudioInstanceFactory instanceFact
protected void ClearInteractiveWindow()
{
InteractiveWindow.Initialize();
InteractiveWindow.ClearScreen();
InteractiveWindow.ShowWindow();
InteractiveWindow.Reset();
}
Expand All @@ -44,12 +45,32 @@ protected void Reset(bool waitForPrompt = true)
protected void SubmitText(string text, bool waitForPrompt = true)
=> InteractiveWindow.SubmitText(text, waitForPrompt);

protected void SendKeys(params object[] input)
{
VisualStudio.Instance.SendKeys.Send(input);
}

protected void InsertCode(string text)
=> InteractiveWindow.InsertCode(text);

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 VerifyCaretPosition(int expectedCaretPosition)
{
var position = InteractiveWindow.GetCaretPosition();
Assert.Equal(expectedCaretPosition, position);
}

protected void VerifyLastReplOutputContains(string expectedReplOutput)
{
var lastReplOutput = InteractiveWindow.GetLastReplOutput();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// 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(Alt(VirtualKey.Up));
VerifyLastReplInput("1.ToString()");
SendKeys(VirtualKey.Enter);
WaitForReplOutput("\"1\"");
SendKeys(Alt(VirtualKey.Up));
VerifyLastReplInput("1.ToString()");
SendKeys(Alt(VirtualKey.Up));
VerifyLastReplInput("1 + 2");
SendKeys(VirtualKey.Enter);
WaitForReplOutput("3");
SendKeys(Alt(VirtualKey.Down));
VerifyLastReplInput("1.ToString()");
SendKeys(VirtualKey.Enter);
WaitForReplOutput("\"1\"");
}

[Fact]
public void VerifyMaybeExecuteInput()
{
InsertCode("2 + 3");
SendKeys(VirtualKey.Enter);
WaitForReplOutput("5");
}

[Fact]
public void VerifyNewLineAndIndent()
{
InsertCode("3 + ");
SendKeys(VirtualKey.Enter);
InsertCode("4");
SendKeys(VirtualKey.Enter);
WaitForReplOutput("7");
}

[Fact]
public void VerifyExecuteInput()
{
SubmitText("1 + ");
VerifyLastReplOutputContains("CS1733");
}

[Fact]
public void VerifyForceNewLineAndIndent()
{
InsertCode("1 + 2");
SendKeys(VirtualKey.Enter);
SubmitText("+ 3");
VerifyReplPromptConsistency("<![CDATA[1 + 2 + 3]]>", "6");
}

[Fact]
public void VerifyCancelInput()
{
InsertCode("1 + 4");
SendKeys(Shift(VirtualKey.Enter));
SendKeys(VirtualKey.Escape);
VerifyLastReplInput(string.Empty);
}

[Fact]
public void VerifyUndoAndRedo()
{
ClearReplText();
InsertCode(" 2 + 4 ");
SendKeys(Ctrl(VirtualKey.Z));
VerifyReplPromptConsistency("< ![CDATA[]] >", string.Empty);
SendKeys(Ctrl(VirtualKey.Y));
VerifyLastReplInput(" 2 + 4 ");
SendKeys(VirtualKey.Enter);
WaitForReplOutput("6");
}

[Fact]
public void CutDeletePasteSelectAll()
{
SendKeys("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);
}

//<!-- Regression test for bug 13731.
// Unfortunately we don't have good unit-test infrastructure to test InteractiveWindow.cs.
// For now, since we don't have coverage of InteractiveWindow.IndentCurrentLine at all,
// I'd rather have a quick integration test scenario rather than no coverage at all.
// At some point when we start investing in Interactive work again, we'll go through some
// of these tests and convert them to unit-tests.
// -->
//<!-- TODO(https://github.com/dotnet/roslyn/issues/4235)
[Fact]
public void VerifyReturnIndentCurrentLine()
{
InteractiveWindow.ClearScreen();
SendKeys(" (");
SendKeys(")");
SendKeys(VirtualKey.Left);
SendKeys(VirtualKey.Enter);
VerifyCaretPosition(12);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<Compile Include="CSharp\CSharpIntelliSense.cs" />
<Compile Include="CSharp\CSharpInteractive.cs" />
<Compile Include="AbstractEditorTest.cs" />
<Compile Include="CSharp\CSharpInteractiveCommands.cs" />
<Compile Include="CSharp\CSharpSignatureHelp.cs" />
<Compile Include="CSharp\CSharpWinForms.cs" />
<Compile Include="CSharp\CSharpAddMissingReference.cs" />
Expand Down
Loading

0 comments on commit 2ba0d8f

Please sign in to comment.