提交 e699bb78 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge branch 'master' into camelCaseMatching

......@@ -359,6 +359,136 @@ void Main(string s, string y)
{
Expression<Func<string>> e = () => {|Warning:s ?? y|};
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseCoalesceExpression)]
public async Task TestUnconstrainedTypeParameter()
{
await TestMissingInRegularAndScriptAsync(
@"
class C<T>
{
void Main(T t)
{
var v = [||]t == null ? throw new Exception() : t;
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseCoalesceExpression)]
public async Task TestStructConstrainedTypeParameter()
{
await TestMissingInRegularAndScriptAsync(
@"
class C<T> where T : struct
{
void Main(T t)
{
var v = [||]t == null ? throw new Exception() : t;
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseCoalesceExpression)]
public async Task TestClassConstrainedTypeParameter()
{
await TestInRegularAndScriptAsync(
@"
class C<T> where T : class
{
void Main(T t)
{
var v = [||]t == null ? throw new Exception() : t;
}
}",
@"
class C<T> where T : class
{
void Main(T t)
{
var v = t ?? throw new Exception();
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseCoalesceExpression)]
public async Task TestNotOnNullable()
{
await TestMissingInRegularAndScriptAsync(
@"
class C
{
void Main(int? t)
{
var v = [||]t == null ? throw new Exception() : t;
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseCoalesceExpression)]
public async Task TestOnArray()
{
await TestInRegularAndScriptAsync(
@"
class C
{
void Main(int[] t)
{
var v = [||]t == null ? throw new Exception() : t;
}
}",
@"
class C
{
void Main(int[] t)
{
var v = t ?? throw new Exception();
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseCoalesceExpression)]
public async Task TestOnInterface()
{
await TestInRegularAndScriptAsync(
@"
class C
{
void Main(System.ICloneable t)
{
var v = [||]t == null ? throw new Exception() : t;
}
}",
@"
class C
{
void Main(System.ICloneable t)
{
var v = t ?? throw new Exception();
}
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseCoalesceExpression)]
public async Task TestOnDynamic()
{
await TestInRegularAndScriptAsync(
@"
class C
{
void Main(dynamic t)
{
var v = [||]t == null ? throw new Exception() : t;
}
}",
@"
class C
{
void Main(dynamic t)
{
var v = t ?? throw new Exception();
}
}");
}
}
......
// 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.Collections.Immutable;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.Diagnostics;
......@@ -8,6 +7,9 @@
namespace Microsoft.CodeAnalysis.UseCoalesceExpression
{
/// <summary>
/// Looks for code of the form "x == null ? y : x" and offers to convert it to "x ?? y";
/// </summary>
internal abstract class AbstractUseCoalesceExpressionDiagnosticAnalyzer<
TSyntaxKind,
TExpressionSyntax,
......@@ -95,12 +97,30 @@ private void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
}
if (!syntaxFacts.AreEquivalent(
conditionRightIsNull ? conditionLeftLow : conditionRightLow,
conditionRightIsNull ? conditionLeftLow : conditionRightLow,
isEquals ? whenFalseNodeLow : whenTrueNodeLow))
{
return;
}
var semanticModel = context.SemanticModel;
var conditionType = semanticModel.GetTypeInfo(
conditionLeftIsNull ? conditionRightLow : conditionLeftLow, cancellationTokan).Type;
if (conditionType != null &&
!conditionType.IsReferenceType)
{
// Note: it is intentional that we do not support nullable types here. If you have:
//
// int? x;
// var z = x == null ? y : x;
//
// then that's not the same as: x ?? y. ?? will unwrap the nullable, producing a
// int and not an int? like we have in the above code.
//
// Note: we could look for: x == null ? y : x.Value, and simplify that in the future.
return;
}
var conditionPartToCheck = conditionRightIsNull ? conditionLeftHigh : conditionRightHigh;
var whenPartToCheck = isEquals ? whenTrueNodeHigh : whenFalseNodeHigh;
var locations = ImmutableArray.Create(
......
......@@ -9,10 +9,12 @@
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Common;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Microsoft.VisualStudio.IntegrationTest.Utilities.OutOfProcess;
using Roslyn.Test.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions;
using Roslyn.VisualStudio.IntegrationTests.Extensions.SolutionExplorer;
using Xunit;
using ProjectUtils = Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils;
namespace Roslyn.VisualStudio.IntegrationTests
{
......@@ -39,8 +41,8 @@ protected AbstractEditorTest(VisualStudioInstanceFactory instanceFactory, string
string projectTemplate)
: base(instanceFactory, visualStudio => visualStudio.Instance.Editor)
{
VisualStudio.Instance.SolutionExplorer.CreateSolution(solutionName);
VisualStudio.Instance.SolutionExplorer.AddProject(ProjectName, projectTemplate, LanguageName);
this.CreateSolution(solutionName);
this.AddProject(projectTemplate, new ProjectUtils.Project(ProjectName), LanguageName);
Editor = (Editor_OutOfProc)TextViewWindow;
......@@ -76,363 +78,5 @@ protected void SetUpEditor(string markupCode)
VisualStudioWorkspaceOutOfProc.SetPrettyListing(LanguageName, originalValue);
}
}
protected void AddFile(string fileName, string contents = null, bool open = false)
=> VisualStudio.Instance.SolutionExplorer.AddFile(ProjectName, fileName, contents, open);
protected void OpenFile(string projectName, string fileName)
=> VisualStudio.Instance.SolutionExplorer.OpenFile(projectName, fileName);
protected void OpenFileWithDesigner(string projectName, string fileName)
=> VisualStudio.Instance.SolutionExplorer.OpenFileWithDesigner(projectName, fileName);
protected void CloseFile(string projectName, string fileName, bool saveFile = true)
=> VisualStudio.Instance.SolutionExplorer.CloseFile(projectName, fileName, saveFile);
protected void SaveFile(string projectName, string fileName)
=> VisualStudio.Instance.SolutionExplorer.SaveFile(projectName, fileName);
protected void AddWinFormButton(string buttonName)
=> VisualStudio.Instance.Editor.AddWinFormButton(buttonName);
protected void DeleteWinFormButton(string buttonName)
=> VisualStudio.Instance.Editor.DeleteWinFormButton(buttonName);
protected void EditWinFormButtonProperty(string buttonName, string propertyName, string propertyValue, string propertyTypeName = null)
=> VisualStudio.Instance.Editor.EditWinFormButtonProperty(buttonName, propertyName, propertyValue, propertyTypeName);
protected void EditWinFormsButtonEvent(string buttonName, string eventName, string eventHandlerName)
=> VisualStudio.Instance.Editor.EditWinFormButtonEvent(buttonName, eventName, eventHandlerName);
protected string GetWinFormButtonPropertyValue(string buttonName, string propertyName)
=> VisualStudio.Instance.Editor.GetWinFormButtonPropertyValue(buttonName, propertyName);
protected void SelectTextInCurrentDocument(string text)
{
VisualStudio.Instance.Editor.PlaceCaret(text, charsOffset: -1, occurrence: 0, extendSelection: false, selectBlock: false);
VisualStudio.Instance.Editor.PlaceCaret(text, charsOffset: 0, occurrence: 0, extendSelection: true, selectBlock: false);
}
protected void DeleteText(string text)
{
SelectTextInCurrentDocument(text);
SendKeys(VirtualKey.Delete);
}
protected void PlaceCaret(string text, int charsOffset = 0)
=> VisualStudio.Instance.Editor.PlaceCaret(text, charsOffset: charsOffset, occurrence: 0, extendSelection: false, selectBlock: false);
protected void BuildSolution(bool waitForBuildToFinish)
=> VisualStudio.Instance.SolutionExplorer.BuildSolution(waitForBuildToFinish);
protected int GetErrorListErrorCount()
=> VisualStudio.Instance.SolutionExplorer.ErrorListErrorCount;
protected void SendKeys(params object[] keys)
=> Editor.SendKeys(keys);
protected void DisableSuggestionMode()
=> VisualStudioWorkspaceOutOfProc.SetUseSuggestionMode(false);
protected void EnableSuggestionMode()
=> VisualStudioWorkspaceOutOfProc.SetUseSuggestionMode(true);
protected void InvokeSignatureHelp()
{
ExecuteCommand(WellKnownCommandNames.Edit_ParameterInfo);
WaitForAsyncOperations(FeatureAttribute.SignatureHelp);
}
protected void InvokeQuickInfo()
{
ExecuteCommand(WellKnownCommandNames.Edit_QuickInfo);
WaitForAsyncOperations(FeatureAttribute.QuickInfo);
}
protected void InvokeCodeActionList()
{
WaitForAsyncOperations(FeatureAttribute.SolutionCrawler);
WaitForAsyncOperations(FeatureAttribute.DiagnosticService);
Editor.ShowLightBulb();
Editor.WaitForLightBulbSession();
WaitForAsyncOperations(FeatureAttribute.LightBulb);
}
private void VerifyCurrentLineTextAndAssertCaretPosition(string expectedText, bool trimWhitespace)
{
var caretStartIndex = expectedText.IndexOf("$$");
if (caretStartIndex < 0)
{
throw new ArgumentException("Expected caret position to be specified with $$", nameof(expectedText));
}
var caretEndIndex = caretStartIndex + "$$".Length;
var expectedTextBeforeCaret = expectedText.Substring(0, caretStartIndex);
var expectedTextAfterCaret = expectedText.Substring(caretEndIndex);
var lineText = Editor.GetCurrentLineText();
if (trimWhitespace)
{
if (caretStartIndex == 0)
{
lineText = lineText.TrimEnd();
}
else if (caretEndIndex == expectedText.Length)
{
lineText = lineText.TrimStart();
}
else
{
lineText = lineText.Trim();
}
}
var lineTextBeforeCaret = caretStartIndex < lineText.Length
? lineText.Substring(0, caretStartIndex)
: lineText;
var lineTextAfterCaret = caretStartIndex < lineText.Length
? lineText.Substring(caretStartIndex)
: string.Empty;
Assert.Equal(expectedTextBeforeCaret, lineTextBeforeCaret);
Assert.Equal(expectedTextAfterCaret, lineTextAfterCaret);
Assert.Equal(expectedTextBeforeCaret.Length + expectedTextAfterCaret.Length, lineText.Length);
}
protected void VerifyCurrentLineText(string expectedText, bool assertCaretPosition = false, bool trimWhitespace = true)
{
if (assertCaretPosition)
{
VerifyCurrentLineTextAndAssertCaretPosition(expectedText, trimWhitespace);
}
else
{
var lineText = Editor.GetCurrentLineText();
if (trimWhitespace)
{
lineText = lineText.Trim();
}
Assert.Equal(expectedText, lineText);
}
}
private void VerifyTextContainsAndAssertCaretPosition(string expectedText)
{
var caretStartIndex = expectedText.IndexOf("$$");
if (caretStartIndex < 0)
{
throw new ArgumentException("Expected caret position to be specified with $$", nameof(expectedText));
}
var caretEndIndex = caretStartIndex + "$$".Length;
var expectedTextBeforeCaret = expectedText.Substring(0, caretStartIndex);
var expectedTextAfterCaret = expectedText.Substring(caretEndIndex);
var expectedTextWithoutCaret = expectedTextBeforeCaret + expectedTextAfterCaret;
var editorText = Editor.GetText();
Assert.Contains(expectedTextWithoutCaret, editorText);
var index = editorText.IndexOf(expectedTextWithoutCaret);
var caretPosition = Editor.GetCaretPosition();
Assert.Equal(caretStartIndex + index, caretPosition);
}
protected void VerifyTextContains(string expectedText, bool assertCaretPosition = false)
{
if (assertCaretPosition)
{
VerifyTextContainsAndAssertCaretPosition(expectedText);
}
else
{
var editorText = Editor.GetText();
Assert.Contains(expectedText, editorText);
}
}
protected void VerifyTextDoesNotContain(string expectedText)
{
var editorText = Editor.GetText();
Assert.DoesNotContain(expectedText, editorText);
}
protected void VerifyCompletionItemDoesNotExist(params string[] expectedItems)
{
var completionItems = Editor.GetCompletionItems();
foreach (var expectedItem in expectedItems)
{
Assert.DoesNotContain(expectedItem, completionItems);
}
}
protected void VerifyCurrentCompletionItem(string expectedItem)
{
var currentItem = Editor.GetCurrentCompletionItem();
Assert.Equal(expectedItem, currentItem);
}
protected void VerifyCurrentSignature(Signature expectedSignature)
{
var currentSignature = Editor.GetCurrentSignature();
Assert.Equal(expectedSignature, currentSignature);
}
protected void VerifyCurrentSignature(string content)
{
var currentSignature = Editor.GetCurrentSignature();
Assert.Equal(content, currentSignature.Content);
}
protected void VerifyCurrentParameter(string name, string documentation)
{
var currentParameter = Editor.GetCurrentSignature().CurrentParameter;
Assert.Equal(name, currentParameter.Name);
Assert.Equal(documentation, currentParameter.Documentation);
}
protected void VerifyParameters(params (string name, string documentation)[] parameters)
{
var currentParameters = Editor.GetCurrentSignature().Parameters;
for (var i = 0; i < parameters.Length; i++)
{
var (expectedName, expectedDocumentation) = parameters[i];
Assert.Equal(expectedName, currentParameters[i].Name);
Assert.Equal(expectedDocumentation, currentParameters[i].Documentation);
}
}
protected void VerifyCaretIsOnScreen()
=> Assert.True(Editor.IsCaretOnScreen());
protected void VerifyCompletionListIsActive(bool expected)
=> Assert.Equal(expected, Editor.IsCompletionActive());
protected void VerifyFileContents(string fileName, string expectedContents)
{
var actualContents = VisualStudio.Instance.SolutionExplorer.GetFileContents(ProjectName, fileName);
Assert.Equal(expectedContents, actualContents);
}
public void VerifyCodeActionsNotShowing()
{
if (Editor.IsLightBulbSessionExpanded())
{
throw new InvalidOperationException("Expected no light bulb session, but one was found.");
}
}
public void VerifyNoBuildErrors()
{
BuildSolution(waitForBuildToFinish: true);
Assert.Equal(0, GetErrorListErrorCount());
}
public void VerifyCodeAction(
string expectedItem,
bool applyFix = false,
bool verifyNotShowing = false,
bool ensureExpectedItemsAreOrdered = false,
FixAllScope? fixAllScope = null,
bool blockUntilComplete = true)
{
var expectedItems = new[] { expectedItem };
VerifyCodeActions(
expectedItems, applyFix ? expectedItem : null, verifyNotShowing,
ensureExpectedItemsAreOrdered, fixAllScope, blockUntilComplete);
}
public void VerifyCodeActions(
IEnumerable<string> expectedItems,
string applyFix = null,
bool verifyNotShowing = false,
bool ensureExpectedItemsAreOrdered = false,
FixAllScope? fixAllScope = null,
bool blockUntilComplete = true)
{
Editor.ShowLightBulb();
Editor.WaitForLightBulbSession();
if (verifyNotShowing)
{
VerifyCodeActionsNotShowing();
return;
}
var actions = Editor.GetLightBulbActions();
if (expectedItems != null && expectedItems.Any())
{
if (ensureExpectedItemsAreOrdered)
{
TestUtilities.ThrowIfExpectedItemNotFoundInOrder(
actions,
expectedItems);
}
else
{
TestUtilities.ThrowIfExpectedItemNotFound(
actions,
expectedItems);
}
}
if (!string.IsNullOrEmpty(applyFix) || fixAllScope.HasValue)
{
Editor.ApplyLightBulbAction(applyFix, fixAllScope, blockUntilComplete);
if (blockUntilComplete)
{
// wait for action to complete
WaitForAsyncOperations(FeatureAttribute.LightBulb);
}
}
}
public void VerifyDialog(string dialogName, bool isOpen)
{
Editor.VerifyDialog(dialogName, isOpen);
}
public void PressDialogButton(string dialogAutomationName, string buttonAutomationName)
{
Editor.PressDialogButton(dialogAutomationName, buttonAutomationName);
}
public AutomationElement GetDialog(string dialogAutomationId)
{
var dialog = DialogHelpers.FindDialog(VisualStudio.Instance.Shell.GetHWnd(), dialogAutomationId, isOpen: true);
Assert.NotNull(dialog);
return dialog;
}
public void VerifyAssemblyReferencePresent(string projectName, string assemblyName, string assemblyVersion, string assemblyPublicKeyToken)
{
var assemblyReferences = VisualStudio.Instance.SolutionExplorer.GetAssemblyReferences(projectName);
var expectedAssemblyReference = assemblyName + "," + assemblyVersion + "," + assemblyPublicKeyToken.ToUpper();
Assert.Contains(expectedAssemblyReference, assemblyReferences);
}
public void VerifyProjectReferencePresent(string projectName, string referencedProjectName)
{
var projectReferences = VisualStudio.Instance.SolutionExplorer.GetProjectReferences(projectName);
Assert.Contains(referencedProjectName, projectReferences);
}
protected void InvokeNavigateToAndPressEnter(string text)
{
ExecuteCommand(WellKnownCommandNames.Edit_GoToAll);
Editor.NavigateToSendKeys(text);
WaitForAsyncOperations(FeatureAttribute.NavigateTo);
Editor.NavigateToSendKeys("{ENTER}");
}
}
}
\ No newline at end of file
......@@ -6,6 +6,7 @@
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Microsoft.VisualStudio.IntegrationTest.Utilities.OutOfProcess;
using Roslyn.VisualStudio.IntegrationTests.Extensions;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests
......@@ -13,12 +14,12 @@ namespace Roslyn.VisualStudio.IntegrationTests
[CaptureTestName]
public abstract class AbstractIntegrationTest : IDisposable
{
protected readonly VisualStudioInstanceContext VisualStudio;
public readonly VisualStudioInstanceContext VisualStudio;
protected readonly VisualStudioWorkspace_OutOfProc VisualStudioWorkspaceOutOfProc;
protected readonly TextViewWindow_OutOfProc TextViewWindow;
protected AbstractIntegrationTest(
VisualStudioInstanceFactory instanceFactory,
VisualStudioInstanceFactory instanceFactory,
Func<VisualStudioInstanceContext, TextViewWindow_OutOfProc> textViewWindowBuilder)
{
VisualStudio = instanceFactory.GetNewOrUsedInstance(SharedIntegrationHostFixture.RequiredPackageIds);
......@@ -29,18 +30,6 @@ public abstract class AbstractIntegrationTest : IDisposable
public void Dispose()
=> VisualStudio.Dispose();
public void VerifyCurrentTokenType(string tokenType)
{
WaitForAsyncOperations(
FeatureAttribute.SolutionCrawler,
FeatureAttribute.DiagnosticService,
FeatureAttribute.Classification);
var actualTokenTypes = TextViewWindow.GetCurrentClassifications();
Assert.Equal(actualTokenTypes.Length, 1);
Assert.Contains(tokenType, actualTokenTypes[0]);
Assert.NotEqual("text", tokenType);
}
protected void Wait(double seconds)
{
var timeout = TimeSpan.FromMilliseconds(seconds * 1000);
......@@ -58,32 +47,5 @@ protected KeyPress Shift(VirtualKey virtualKey)
protected KeyPress Alt(VirtualKey virtualKey)
=> new KeyPress(virtualKey, ShiftState.Alt);
protected void ExecuteCommand(string commandName, string argument = "")
=> VisualStudio.Instance.ExecuteCommand(commandName, argument);
protected void InvokeCompletionList()
{
ExecuteCommand(WellKnownCommandNames.Edit_ListMembers);
WaitForAsyncOperations(FeatureAttribute.CompletionSet);
}
protected void VerifyCompletionItemExists(params string[] expectedItems)
{
var completionItems = TextViewWindow.GetCompletionItems();
foreach (var expectedItem in expectedItems)
{
Assert.Contains(expectedItem, completionItems);
}
}
protected void VerifyCaretPosition(int expectedCaretPosition)
{
var position = TextViewWindow.GetCaretPosition();
Assert.Equal(expectedCaretPosition, position);
}
protected void WaitForAsyncOperations(params string[] featuresToWaitFor)
=> VisualStudioWorkspaceOutOfProc.WaitForAsyncOperations(string.Join(";", featuresToWaitFor));
}
}
......@@ -62,10 +62,10 @@ protected void InsertCode(string text)
protected void PlaceCaret(string text, int charsOffset = 0)
=> InteractiveWindow.PlaceCaret(
text,
charsOffset: charsOffset,
occurrence: 0,
extendSelection: false,
text,
charsOffset: charsOffset,
occurrence: 0,
extendSelection: false,
selectBlock: false);
protected void VerifyLastReplOutput(string expectedReplOutput)
......
using System.Xml.Linq;
// 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.Xml.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Roslyn.VisualStudio.IntegrationTests.Extensions.SolutionExplorer;
using Xunit;
using ProjectUtils = Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils;
namespace Roslyn.VisualStudio.IntegrationTests.Other
{
......@@ -126,37 +131,39 @@ public CSharpAddMissingReference(VisualStudioInstanceFactory instanceFactory)
}
[Fact, Trait(Traits.Feature, Traits.Features.AddMissingReference)]
public void Verify_Available_Code_Actions()
public void VerifyAvailableCodeActions()
{
OpenFile(ConsoleProjectName, "Program.cs");
PlaceCaret("y.foo", charsOffset: 1);
InvokeCodeActionList();
VerifyCodeAction("Add reference to 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.", applyFix: false);
PlaceCaret("y.ee", charsOffset: 1);
InvokeCodeActionList();
VerifyCodeAction("Add reference to 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.", applyFix: false);
PlaceCaret("a.bar", charsOffset: 1);
InvokeCodeActionList();
VerifyCodeAction("Add project reference to 'ClassLibrary3'.", applyFix: false);
var consoleProject = new ProjectUtils.Project(ConsoleProjectName);
this.OpenFile("Program.cs", consoleProject);
this.PlaceCaret("y.foo", charsOffset: 1);
this.InvokeCodeActionList();
this.VerifyCodeAction("Add reference to 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.", applyFix: false);
this.PlaceCaret("y.ee", charsOffset: 1);
this.InvokeCodeActionList();
this.VerifyCodeAction("Add reference to 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.", applyFix: false);
this.PlaceCaret("a.bar", charsOffset: 1);
this.InvokeCodeActionList();
this.VerifyCodeAction("Add project reference to 'ClassLibrary3'.", applyFix: false);
}
[Fact, Trait(Traits.Feature, Traits.Features.AddMissingReference)]
public void Invoke_Some_Fixes_In_CSharp_Then_Verify_References()
public void InvokeSomeFixesInCSharpThenVerifyReferences()
{
OpenFile(ConsoleProjectName, "Program.cs");
PlaceCaret("y.foo", charsOffset: 1);
InvokeCodeActionList();
VerifyCodeAction("Add reference to 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.", applyFix: true);
VerifyAssemblyReferencePresent(
projectName: ConsoleProjectName,
var consoleProject = new ProjectUtils.Project(ConsoleProjectName);
this.OpenFile("Program.cs", consoleProject);
this.PlaceCaret("y.foo", charsOffset: 1);
this.InvokeCodeActionList();
this.VerifyCodeAction("Add reference to 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.", applyFix: true);
this.VerifyAssemblyReferencePresent(
project: consoleProject,
assemblyName: "System.Windows.Forms",
assemblyVersion: "4.0.0.0",
assemblyPublicKeyToken: "b77a5c561934e089");
PlaceCaret("a.bar", charsOffset: 1);
InvokeCodeActionList();
VerifyCodeAction("Add project reference to 'ClassLibrary3'.", applyFix: true);
VerifyProjectReferencePresent(
projectName: ConsoleProjectName,
this.PlaceCaret("a.bar", charsOffset: 1);
this.InvokeCodeActionList();
this.VerifyCodeAction("Add project reference to 'ClassLibrary3'.", applyFix: true);
this.VerifyProjectReferencePresent(
project: consoleProject,
referencedProjectName: ClassLibrary3Name);
}
}
......
......@@ -4,6 +4,7 @@
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Roslyn.Test.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.CSharp
......@@ -28,11 +29,11 @@ class C {
}
}");
SendKeys("if (true) {");
VerifyCurrentLineText("if (true) { $$}", assertCaretPosition: true);
this.SendKeys("if (true) {");
this.VerifyCurrentLineText("if (true) { $$}", assertCaretPosition: true);
SendKeys(VirtualKey.Tab);
VerifyCurrentLineText("if (true) { }$$", assertCaretPosition: true);
this.SendKeys(VirtualKey.Tab);
this.VerifyCurrentLineText("if (true) { }$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -45,11 +46,11 @@ class C {
}
}");
SendKeys("if (true) {");
VerifyCurrentLineText("if (true) { $$}", assertCaretPosition: true);
this.SendKeys("if (true) {");
this.VerifyCurrentLineText("if (true) { $$}", assertCaretPosition: true);
SendKeys("}");
VerifyCurrentLineText("if (true) { }$$", assertCaretPosition: true);
this.SendKeys("}");
this.VerifyCurrentLineText("if (true) { }$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -62,12 +63,12 @@ class C {
}
}");
SendKeys(
this.SendKeys(
"if (true) {",
VirtualKey.Enter,
"var a = 1;");
VerifyTextContains(@"
this.VerifyTextContains(@"
class C {
void Foo() {
if (true)
......@@ -89,13 +90,13 @@ class C {
}
}");
SendKeys(
this.SendKeys(
"if (true) {",
VirtualKey.Enter,
"var a = 1;",
'}');
VerifyTextContains(@"
this.VerifyTextContains(@"
class C {
void Foo() {
if (true)
......@@ -111,11 +112,11 @@ class C {
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
public void Braces_OnReturnWithNonWhitespaceSpanInside()
{
SendKeys(
this.SendKeys(
"class A { int i;",
VirtualKey.Enter);
VerifyTextContains(@"class A { int i;
this.VerifyTextContains(@"class A { int i;
$$}",
assertCaretPosition: true);
}
......@@ -128,11 +129,11 @@ class C {
$$
}");
SendKeys("void Foo(");
VerifyCurrentLineText("void Foo($$)", assertCaretPosition: true);
this.SendKeys("void Foo(");
this.VerifyCurrentLineText("void Foo($$)", assertCaretPosition: true);
SendKeys("int x", VirtualKey.Tab);
VerifyCurrentLineText("void Foo(int x)$$", assertCaretPosition: true);
this.SendKeys("int x", VirtualKey.Tab);
this.VerifyCurrentLineText("void Foo(int x)$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -143,12 +144,12 @@ class C {
$$
}");
SendKeys(
this.SendKeys(
"void Foo(",
VirtualKey.Escape,
")");
VerifyCurrentLineText("void Foo()$$", assertCaretPosition: true);
this.VerifyCurrentLineText("void Foo()$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -159,8 +160,8 @@ class C {
$$
}");
SendKeys("int [");
VerifyCurrentLineText("int [$$]", assertCaretPosition: true);
this.SendKeys("int [");
this.VerifyCurrentLineText("int [$$]", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -171,8 +172,8 @@ class C {
$$
}");
SendKeys("int [", ']');
VerifyCurrentLineText("int []$$", assertCaretPosition: true);
this.SendKeys("int [", ']');
this.VerifyCurrentLineText("int []$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -183,8 +184,8 @@ class C {
$$
}");
SendKeys("string str = \"", VirtualKey.Tab);
VerifyCurrentLineText("string str = \"\"$$", assertCaretPosition: true);
this.SendKeys("string str = \"", VirtualKey.Tab);
this.VerifyCurrentLineText("string str = \"\"$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -195,8 +196,8 @@ class C {
$$
}");
SendKeys("string str = \"Hi Roslyn!", '"');
VerifyCurrentLineText("string str = \"Hi Roslyn!\"$$", assertCaretPosition: true);
this.SendKeys("string str = \"Hi Roslyn!", '"');
this.VerifyCurrentLineText("string str = \"Hi Roslyn!\"$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -208,8 +209,8 @@ class C {
$$
}");
SendKeys("System.Action<", VirtualKey.Tab);
VerifyCurrentLineText("System.Action<>$$", assertCaretPosition: true);
this.SendKeys("System.Action<", VirtualKey.Tab);
this.VerifyCurrentLineText("System.Action<>$$", assertCaretPosition: true);
SetUpEditor(@"
class C {
......@@ -217,8 +218,8 @@ class C {
$$
}");
SendKeys("void GenericMethod<", VirtualKey.Tab);
VerifyCurrentLineText("void GenericMethod<>$$", assertCaretPosition: true);
this.SendKeys("void GenericMethod<", VirtualKey.Tab);
this.VerifyCurrentLineText("void GenericMethod<>$$", assertCaretPosition: true);
SetUpEditor(@"
class C {
......@@ -226,24 +227,24 @@ class C {
$$
}");
SendKeys("delegate void Del<");
VerifyCurrentLineText("delegate void Del<$$>", assertCaretPosition: true);
this.SendKeys("delegate void Del<");
this.VerifyCurrentLineText("delegate void Del<$$>", assertCaretPosition: true);
SetUpEditor(@"
//using directive
$$
");
SendKeys("using ActionOfT = System.Action<");
VerifyCurrentLineText("using ActionOfT = System.Action<$$>", assertCaretPosition: true);
this.SendKeys("using ActionOfT = System.Action<");
this.VerifyCurrentLineText("using ActionOfT = System.Action<$$>", assertCaretPosition: true);
SetUpEditor(@"
//class
$$
");
SendKeys("class GenericClass<", '>');
VerifyCurrentLineText("class GenericClass<>$$", assertCaretPosition: true);
this.SendKeys("class GenericClass<", '>');
this.VerifyCurrentLineText("class GenericClass<>$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -254,13 +255,13 @@ class C {
$$
}");
SendKeys("char c = '");
VerifyCurrentLineText("char c = '$$'", assertCaretPosition: true);
this.SendKeys("char c = '");
this.VerifyCurrentLineText("char c = '$$'", assertCaretPosition: true);
SendKeys(VirtualKey.Delete, VirtualKey.Backspace);
SendKeys("'\u6666", "'");
this.SendKeys(VirtualKey.Delete, VirtualKey.Backspace);
this.SendKeys("'\u6666", "'");
VerifyCurrentLineText("char c = '\u6666'$$", assertCaretPosition: true);
this.VerifyCurrentLineText("char c = '\u6666'$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -276,7 +277,7 @@ void M()
}
}");
SendKeys(
this.SendKeys(
"var arr=new object[,]{{Foo(0",
VirtualKey.Tab,
VirtualKey.Tab,
......@@ -288,7 +289,7 @@ void M()
VirtualKey.Tab,
';');
VerifyCurrentLineText("var arr = new object[,] { { Foo(0) }, { Foo(Foo(\"hello\")) } };$$", assertCaretPosition: true);
this.VerifyCurrentLineText("var arr = new object[,] { { Foo(0) }, { Foo(Foo(\"hello\")) } };$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -299,8 +300,8 @@ class C {
// $$
}");
SendKeys("{([\"'");
VerifyCurrentLineText("// {([\"'$$", assertCaretPosition: true);
this.SendKeys("{([\"'");
this.VerifyCurrentLineText("// {([\"'$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -313,8 +314,8 @@ class C {
*/
}");
SendKeys("{([\"'");
VerifyCurrentLineText("{([\"'$$", assertCaretPosition: true);
this.SendKeys("{([\"'");
this.VerifyCurrentLineText("{([\"'$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -325,18 +326,18 @@ class C {
$$
}");
SendKeys("string s = \"{([<'");
VerifyCurrentLineText("string s = \"{([<'\"$$", assertCaretPosition: true);
this.SendKeys("string s = \"{([<'");
this.VerifyCurrentLineText("string s = \"{([<'\"$$", assertCaretPosition: true);
SendKeys(VirtualKey.End, ';', VirtualKey.Enter);
this.SendKeys(VirtualKey.End, ';', VirtualKey.Enter);
SendKeys("string y = @\"{([<'");
VerifyCurrentLineText("string y = @\"{([<'\"$$", assertCaretPosition: true);
this.SendKeys("string y = @\"{([<'");
this.VerifyCurrentLineText("string y = @\"{([<'\"$$", assertCaretPosition: true);
SendKeys(VirtualKey.End, ';', VirtualKey.Enter);
this.SendKeys(VirtualKey.End, ';', VirtualKey.Enter);
SendKeys("char ch = '{([<\"");
VerifyCurrentLineText("char ch = '{([<\"'$$", assertCaretPosition: true);
this.SendKeys("char ch = '{([<\"");
this.VerifyCurrentLineText("char ch = '{([<\"'$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -346,11 +347,11 @@ public void Negative_NoCompletionInXmlDocComments()
$$
class C { }");
SendKeys(
this.SendKeys(
"///",
"{([<\"'");
VerifyCurrentLineText("/// {([<\"'$$", assertCaretPosition: true);
this.VerifyCurrentLineText("/// {([<\"'$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -363,8 +364,8 @@ class C {
#endif
}");
SendKeys("void Foo(");
VerifyCurrentLineText("void Foo($$", assertCaretPosition: true);
this.SendKeys("void Foo(");
this.VerifyCurrentLineText("void Foo($$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -376,8 +377,8 @@ public void Negative_NoCompletionAfterRegionPreprocesser()
#endregion
");
SendKeys("{([<\"'");
VerifyCurrentLineText("#region {([<\"'$$", assertCaretPosition: true);
this.SendKeys("{([<\"'");
this.VerifyCurrentLineText("#region {([<\"'$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -389,8 +390,8 @@ public void Negative_NoCompletionAfterEndregionPreprocesser()
#endregion $$
");
SendKeys("{([<\"'");
VerifyCurrentLineText("#endregion {([<\"'$$", assertCaretPosition: true);
this.SendKeys("{([<\"'");
this.VerifyCurrentLineText("#endregion {([<\"'$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -400,8 +401,8 @@ public void Negative_NoCompletionAfterIfPreprocesser()
#if $$
");
SendKeys("{([<\"'");
VerifyCurrentLineText("#if {([<\"'$$", assertCaretPosition: true);
this.SendKeys("{([<\"'");
this.VerifyCurrentLineText("#if {([<\"'$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -411,8 +412,8 @@ public void Negative_NoCompletionAfterPragmaPreprocesser()
#pragma $$
");
SendKeys("{([<\"'");
VerifyCurrentLineText("#pragma {([<\"'$$", assertCaretPosition: true);
this.SendKeys("{([<\"'");
this.VerifyCurrentLineText("#pragma {([<\"'$$", assertCaretPosition: true);
}
[WorkItem(651954, "DevDiv")]
......@@ -431,9 +432,9 @@ class B : A
}
");
SendKeys("override Foo(");
VerifyTextContains(@"
this.SendKeys("override Foo(");
var actualText = Editor.GetText();
Assert.Contains(@"
class B : A
{
// type ""override Foo(""
......@@ -441,7 +442,7 @@ public override void Foo()
{
base.Foo();
}
}");
}", actualText);
}
[WorkItem(531107, "DevDiv")]
......@@ -459,8 +460,8 @@ void M()
}
");
SendKeys("new Li(", VirtualKey.Tab);
VerifyCurrentLineText("List<int> li = new List<int>($$)", assertCaretPosition: true);
this.SendKeys("new Li(", VirtualKey.Tab);
this.VerifyCurrentLineText("List<int> li = new List<int>($$)", assertCaretPosition: true);
}
[WorkItem(823958, "DevDiv")]
......@@ -477,8 +478,8 @@ void M()
}
");
SendKeys("new int[]{");
VerifyCurrentLineText("var x = new int[] {$$}", assertCaretPosition: true);
this.SendKeys("new int[]{");
this.VerifyCurrentLineText("var x = new int[] {$$}", assertCaretPosition: true);
}
[WorkItem(823958, "DevDiv")]
......@@ -495,8 +496,8 @@ void M()
}
");
SendKeys("new {");
VerifyCurrentLineText("var x = new {$$}", assertCaretPosition: true);
this.SendKeys("new {");
this.VerifyCurrentLineText("var x = new {$$}", assertCaretPosition: true);
}
[WorkItem(823958, "DevDiv")]
......@@ -507,14 +508,13 @@ public void AutoBraceCompleteFormatsBracePairInClassDeclarationAndAutoProperty()
class $$
");
SendKeys("C{");
VerifyCurrentLineText("class C { $$}", assertCaretPosition: true);
this.SendKeys("C{");
this.VerifyCurrentLineText("class C { $$}", assertCaretPosition: true);
SendKeys(
this.SendKeys(
VirtualKey.Enter,
"int Prop {");
VerifyTextContains(@"
this.VerifyTextContains(@"
class C
{
int Prop { $$}
......
// 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.Diagnostics;
using System.IO;
using Microsoft.CodeAnalysis;
......
// 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.CodeAnalysis;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.OutOfProcess;
using Roslyn.Test.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.CSharp
......@@ -31,8 +31,8 @@ class C
public void Method(int a, string b) { }
}");
InvokeCodeActionList();
VerifyCodeAction("Change signature...", applyFix: false);
this.InvokeCodeActionList();
this.VerifyCodeAction("Change signature...", applyFix: false);
}
[Fact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
......@@ -48,15 +48,15 @@ class C
ChangeSignatureDialog.VerifyOpen();
ChangeSignatureDialog.ClickCancel();
ChangeSignatureDialog.VerifyClosed();
VerifyTextContains(@"
var actuaText = Editor.GetText();
Assert.Contains(@"
class C
{
public void Method(int a, string b) { }
}");
}", actuaText);
}
[Fact (Skip = "https://github.com/dotnet/roslyn/issues/17640"),
[Fact (Skip = "https://github.com/dotnet/roslyn/issues/17640"),
Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public void VerifyReorderParameters()
{
......@@ -72,12 +72,12 @@ class C
ChangeSignatureDialog.ClickDownButton();
ChangeSignatureDialog.ClickOK();
ChangeSignatureDialog.VerifyClosed();
VerifyTextContains(@"
var actuaText = Editor.GetText();
Assert.Contains(@"
class C
{
public void Method(string b, int a) { }
}");
}", actuaText);
}
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/17680"),
......@@ -107,22 +107,22 @@ void Test()
ChangeSignatureDialog.ClickRemoveButton();
ChangeSignatureDialog.ClickOK();
ChangeSignatureDialog.VerifyClosed();
VerifyTextContains(@"
var actuaText = Editor.GetText();
Assert.Contains(@"
class C
{
/// <summary>
/// A method.
/// </summary>
/// <param name=""a""></param>
///
///
public void Method(int a) { }
void Test()
{
Method(1);
}
}");
}", actuaText);
}
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/17680"),
......@@ -159,18 +159,20 @@ End Sub
ChangeSignatureDialog.ClickUpButton();
ChangeSignatureDialog.ClickOK();
ChangeSignatureDialog.VerifyClosed();
VerifyTextContains(@"vb.Method(y: ""hello"", x: 1);");
var actuaText = Editor.GetText();
Assert.Contains(@"vb.Method(y: ""hello"", x: 1);", actuaText);
VisualStudio.Instance.SolutionExplorer.OpenFile("VBProject", "Class1.vb");
VerifyTextContains(@"Public Sub Method(y As String, x As Integer)");
actuaText = Editor.GetText();
Assert.Contains(@"Public Sub Method(y As String, x As Integer)", actuaText);
Editor.Undo();
VerifyTextContains(@"Public Sub Method(x As Integer, y As String)");
actuaText = Editor.GetText();
Assert.Contains(@"Public Sub Method(x As Integer, y As String)", actuaText);
VisualStudio.Instance.SolutionExplorer.OpenFile(ProjectName, "Class1.cs");
VerifyTextContains(@"vb.Method(2, ""world"");");
actuaText = Editor.GetText();
Assert.Contains(@"vb.Method(2, ""world"");", actuaText);
}
}
}
......@@ -3,6 +3,8 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.CSharp
......@@ -39,30 +41,30 @@ public static void Main(string[] args)
}
}");
PlaceCaret("class");
VerifyCurrentTokenType(tokenType: "keyword");
PlaceCaret("{");
VerifyCurrentTokenType(tokenType: "punctuation");
PlaceCaret("Program");
VerifyCurrentTokenType(tokenType: "class name");
PlaceCaret("Main");
VerifyCurrentTokenType(tokenType: "identifier");
PlaceCaret("Hello");
VerifyCurrentTokenType(tokenType: "string");
PlaceCaret("<summary", charsOffset: -1);
VerifyCurrentTokenType(tokenType: "xml doc comment - delimiter");
PlaceCaret("summary");
VerifyCurrentTokenType(tokenType: "xml doc comment - name");
PlaceCaret("innertext");
VerifyCurrentTokenType(tokenType: "xml doc comment - text");
PlaceCaret("comment");
VerifyCurrentTokenType(tokenType: "xml doc comment - comment");
PlaceCaret("CDATA");
VerifyCurrentTokenType(tokenType: "xml doc comment - delimiter");
PlaceCaret("cdata");
VerifyCurrentTokenType(tokenType: "xml doc comment - cdata section");
PlaceCaret("attribute");
VerifyCurrentTokenType(tokenType: "identifier");
this.PlaceCaret("class");
this.VerifyCurrentTokenType(tokenType: "keyword");
this.PlaceCaret("{");
this.VerifyCurrentTokenType(tokenType: "punctuation");
this.PlaceCaret("Program");
this.VerifyCurrentTokenType(tokenType: "class name");
this.PlaceCaret("Main");
this.VerifyCurrentTokenType(tokenType: "identifier");
this.PlaceCaret("Hello");
this.VerifyCurrentTokenType(tokenType: "string");
this.PlaceCaret("<summary", charsOffset: -1);
this.VerifyCurrentTokenType(tokenType: "xml doc comment - delimiter");
this.PlaceCaret("summary");
this.VerifyCurrentTokenType(tokenType: "xml doc comment - name");
this.PlaceCaret("innertext");
this.VerifyCurrentTokenType(tokenType: "xml doc comment - text");
this.PlaceCaret("comment");
this.VerifyCurrentTokenType(tokenType: "xml doc comment - comment");
this.PlaceCaret("CDATA");
this.VerifyCurrentTokenType(tokenType: "xml doc comment - delimiter");
this.PlaceCaret("cdata");
this.VerifyCurrentTokenType(tokenType: "xml doc comment - cdata section");
this.PlaceCaret("attribute");
this.VerifyCurrentTokenType(tokenType: "identifier");
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -79,25 +81,25 @@ static void Main(string[] args)
Program.Main(null);
}
}");
PlaceCaret("Attribute");
VerifyCurrentTokenType(tokenType: "class name");
PlaceCaret("list", charsOffset: 8);
VerifyCurrentTokenType(tokenType: "class name");
PlaceCaret("list", charsOffset: -8);
VerifyCurrentTokenType(tokenType: "class name");
PlaceCaret("null", charsOffset: -8);
VerifyCurrentTokenType(tokenType: "class name");
this.PlaceCaret("Attribute");
this.VerifyCurrentTokenType(tokenType: "class name");
this.PlaceCaret("list", charsOffset: 8);
this.VerifyCurrentTokenType(tokenType: "class name");
this.PlaceCaret("list", charsOffset: -8);
this.VerifyCurrentTokenType(tokenType: "class name");
this.PlaceCaret("null", charsOffset: -8);
this.VerifyCurrentTokenType(tokenType: "class name");
Editor.MoveCaret(0);
DeleteText(@"using System;");
DeleteText(@"using System.Collections.Generic;");
PlaceCaret("Attribute");
VerifyCurrentTokenType(tokenType: "identifier");
PlaceCaret("list", charsOffset: 8);
VerifyCurrentTokenType(tokenType: "identifier");
PlaceCaret("list", charsOffset: -8);
VerifyCurrentTokenType(tokenType: "identifier");
PlaceCaret("null", charsOffset: -8);
VerifyCurrentTokenType(tokenType: "class name");
this.DeleteText(@"using System;");
this.DeleteText(@"using System.Collections.Generic;");
this.PlaceCaret("Attribute");
this.VerifyCurrentTokenType(tokenType: "identifier");
this.PlaceCaret("list", charsOffset: 8);
this.VerifyCurrentTokenType(tokenType: "identifier");
this.PlaceCaret("list", charsOffset: -8);
this.VerifyCurrentTokenType(tokenType: "identifier");
this.PlaceCaret("null", charsOffset: -8);
this.VerifyCurrentTokenType(tokenType: "class name");
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -120,17 +122,17 @@ void Bar()
}
}
");
ExecuteCommand("Build.SolutionConfigurations", argument: "Debug");
PlaceCaret("Foo");
VerifyCurrentTokenType(tokenType: "identifier");
PlaceCaret("Bar");
VerifyCurrentTokenType(tokenType: "excluded code");
this.ExecuteCommand("Build.SolutionConfigurations", argument: "Debug");
this.PlaceCaret("Foo");
this.VerifyCurrentTokenType(tokenType: "identifier");
this.PlaceCaret("Bar");
this.VerifyCurrentTokenType(tokenType: "excluded code");
Editor.MoveCaret(0);
ExecuteCommand("Build.SolutionConfigurations", argument: "Release");
PlaceCaret("Foo");
VerifyCurrentTokenType(tokenType: "excluded code");
PlaceCaret("Bar");
VerifyCurrentTokenType(tokenType: "identifier");
this.ExecuteCommand("Build.SolutionConfigurations", argument: "Release");
this.PlaceCaret("Foo");
this.VerifyCurrentTokenType(tokenType: "excluded code");
this.PlaceCaret("Bar");
this.VerifyCurrentTokenType(tokenType: "identifier");
}
}
......
......@@ -3,7 +3,10 @@
using Microsoft.CodeAnalysis;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Roslyn.Test.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Roslyn.VisualStudio.IntegrationTests.Extensions.SolutionExplorer;
using Xunit;
using ProjectUtils = Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils;
namespace Roslyn.VisualStudio.IntegrationTests.CSharp
{
......@@ -20,12 +23,13 @@ public CSharpCodeActions(VisualStudioInstanceFactory instanceFactory)
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateMethod)]
public void GenerateMethodInClosedFile()
{
AddFile("Foo.cs", @"
var project = new ProjectUtils.Project(ProjectName);
this.AddFile("Foo.cs", project, contents: @"
public class Foo
{
}
");
SetUpEditor(@"
using System;
......@@ -39,10 +43,9 @@ public static void Main(string[] args)
}
");
InvokeCodeActionList();
VerifyCodeAction("Generate method 'Foo.Bar'", applyFix: true);
VerifyFileContents("Foo.cs", @"
this.InvokeCodeActionList();
this.VerifyCodeAction("Generate method 'Foo.Bar'", applyFix: true);
this.VerifyFileContents(project, "Foo.cs", @"
using System;
public class Foo
......
// 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.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Common;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Roslyn.Test.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.CSharp
......@@ -48,7 +44,7 @@ void M()
}
");
SendKeys(Shift(VirtualKey.F12));
this.SendKeys(Shift(VirtualKey.F12));
const string programReferencesCaption = "'Program' references";
var results = VisualStudio.Instance.FindReferencesWindow.GetContents(programReferencesCaption);
......@@ -89,7 +85,7 @@ static void Main()
}
");
SendKeys(Shift(VirtualKey.F12));
this.SendKeys(Shift(VirtualKey.F12));
const string localReferencesCaption = "'local' references";
var results = VisualStudio.Instance.FindReferencesWindow.GetContents(localReferencesCaption);
......@@ -129,7 +125,7 @@ static void Main()
}
");
SendKeys(Shift(VirtualKey.F12));
this.SendKeys(Shift(VirtualKey.F12));
const string findReferencesCaption = "'\"1\"' references";
var results = VisualStudio.Instance.FindReferencesWindow.GetContents(findReferencesCaption);
......
......@@ -4,6 +4,7 @@
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.OutOfProcess;
using Roslyn.Test.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.CSharp
......@@ -32,7 +33,7 @@ void Method()
}
");
VerifyCodeAction("Generate new type...",
this.VerifyCodeAction("Generate new type...",
applyFix: true,
blockUntilComplete: false);
......@@ -57,7 +58,7 @@ void Method()
}
");
VerifyCodeAction("Generate new type...",
this.VerifyCodeAction("Generate new type...",
applyFix: true,
blockUntilComplete: false);
......@@ -70,14 +71,14 @@ void Method()
GenerateTypeDialog.VerifyClosed();
VisualStudio.Instance.SolutionExplorer.OpenFile("VBProj", "GenerateTypeTest.vb");
VerifyTextContains(@"Public Interface A
var actualText = Editor.GetText();
Assert.Contains(@"Public Interface A
End Interface
");
", actualText);
VisualStudio.Instance.SolutionExplorer.OpenFile(ProjectName, "Class1.cs");
VerifyTextContains(@"using VBProj;
actualText = Editor.GetText();
Assert.Contains(@"using VBProj;
class C
{
......@@ -86,7 +87,7 @@ void Method()
A a;
}
}
");
", actualText);
}
......
......@@ -4,6 +4,9 @@
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Roslyn.Test.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Options;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.CSharp
......@@ -23,11 +26,11 @@ public void AtNamespaceLevel()
{
SetUpEditor(@"$$");
SendKeys("usi");
VerifyCompletionItemExists("using");
this.SendKeys("usi");
this.VerifyCompletionItemExists("using");
SendKeys(VirtualKey.Tab);
VerifyCurrentLineText("using$$", assertCaretPosition: true);
this.SendKeys(VirtualKey.Tab);
this.VerifyCurrentLineText("using$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
......@@ -39,19 +42,18 @@ class C
$$
}");
SendKeys("pub");
VerifyCompletionItemExists("public");
this.SendKeys("pub");
this.VerifyCompletionItemExists("public");
SendKeys(' ');
VerifyCurrentLineText("public $$", assertCaretPosition: true);
this.SendKeys(' ');
this.VerifyCurrentLineText("public $$", assertCaretPosition: true);
SendKeys('t');
VerifyCompletionItemExists("T");
this.SendKeys('t');
this.VerifyCompletionItemExists("T");
SendKeys(' ');
SendKeys("Foo<T>() { }");
VerifyTextContains(@"
this.SendKeys(' ');
this.SendKeys("Foo<T>() { }");
this.VerifyTextContains(@"
class C
{
public T Foo<T>() { }$$
......@@ -77,68 +79,68 @@ public static class NavigateTo
public static void Navigate(int i){ }
}");
SendKeys('.');
VerifyCompletionItemExists("Search", "Navigate");
this.SendKeys('.');
this.VerifyCompletionItemExists("Search", "Navigate");
SendKeys('S', VirtualKey.Tab);
VerifyCurrentLineText("NavigateTo.Search$$", assertCaretPosition: true);
this.SendKeys('S', VirtualKey.Tab);
this.VerifyCurrentLineText("NavigateTo.Search$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public void CtrlAltSpace()
{
DisableSuggestionMode();
SendKeys("nam Foo", VirtualKey.Enter);
SendKeys('{', VirtualKey.Enter, '}', VirtualKey.Up, VirtualKey.Enter);
SendKeys("pu cla Program", VirtualKey.Enter);
SendKeys('{', VirtualKey.Enter, '}', VirtualKey.Up, VirtualKey.Enter);
SendKeys("pub stati voi Main(string[] args)", VirtualKey.Enter);
SendKeys('{', VirtualKey.Enter, '}', VirtualKey.Up, VirtualKey.Enter);
SendKeys("System.Console.writeline();");
VerifyCurrentLineText("System.Console.WriteLine();$$", assertCaretPosition: true);
SendKeys(VirtualKey.Home, Shift(VirtualKey.End), VirtualKey.Delete);
ExecuteCommand(WellKnownCommandNames.Edit_ToggleCompletionMode);
SendKeys("System.Console.writeline();");
VerifyCurrentLineText("System.Console.writeline();$$", assertCaretPosition: true);
this.SetUseSuggestionMode(false);
this.SendKeys("nam Foo", VirtualKey.Enter);
this.SendKeys('{', VirtualKey.Enter, '}', VirtualKey.Up, VirtualKey.Enter);
this.SendKeys("pu cla Program", VirtualKey.Enter);
this.SendKeys('{', VirtualKey.Enter, '}', VirtualKey.Up, VirtualKey.Enter);
this.SendKeys("pub stati voi Main(string[] args)", VirtualKey.Enter);
this.SendKeys('{', VirtualKey.Enter, '}', VirtualKey.Up, VirtualKey.Enter);
this.SendKeys("System.Console.writeline();");
this.VerifyCurrentLineText("System.Console.WriteLine();$$", assertCaretPosition: true);
this.SendKeys(VirtualKey.Home, Shift(VirtualKey.End), VirtualKey.Delete);
this.ExecuteCommand(WellKnownCommandNames.Edit_ToggleCompletionMode);
this.SendKeys("System.Console.writeline();");
this.VerifyCurrentLineText("System.Console.writeline();$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public void CtrlAltSpaceOption()
{
DisableSuggestionMode();
this.SetUseSuggestionMode(false);
SendKeys("nam Foo");
VerifyCurrentLineText("namespace Foo$$", assertCaretPosition: true);
this.SendKeys("nam Foo");
this.VerifyCurrentLineText("namespace Foo$$", assertCaretPosition: true);
ClearEditor();
EnableSuggestionMode();
this.SetUseSuggestionMode(true);
SendKeys("nam Foo");
VerifyCurrentLineText("nam Foo$$", assertCaretPosition: true);
this.SendKeys("nam Foo");
this.VerifyCurrentLineText("nam Foo$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public void CtrlSpace()
{
SetUpEditor("class c { void M() {$$ } }");
SendKeys(Ctrl(VirtualKey.Space));
VerifyCompletionItemExists("System");
this.SendKeys(Ctrl(VirtualKey.Space));
this.VerifyCompletionItemExists("System");
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public void NavigatingWithDownKey()
{
SetUpEditor("class c { void M() {$$ } }");
SendKeys('c');
VerifyCurrentCompletionItem("c");
VerifyCompletionItemExists("c");
this.SendKeys('c');
this.VerifyCurrentCompletionItem("c");
this.VerifyCompletionItemExists("c");
SendKeys(VirtualKey.Down);
VerifyCurrentCompletionItem("char");
VerifyCompletionItemExists("char");
this.SendKeys(VirtualKey.Down);
this.VerifyCurrentCompletionItem("char");
this.VerifyCompletionItemExists("char");
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
......@@ -154,11 +156,11 @@ void Main(string[] args)
}
}");
SendKeys("<s");
VerifyCompletionItemExists("see", "seealso", "summary");
this.SendKeys("<s");
this.VerifyCompletionItemExists("see", "seealso", "summary");
SendKeys(VirtualKey.Enter);
VerifyCurrentLineText("///<see cref=\"$$\"/>", assertCaretPosition: true);
this.SendKeys(VirtualKey.Enter);
this.VerifyCurrentLineText("///<see cref=\"$$\"/>", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
......@@ -169,16 +171,16 @@ public void XmlTagCompletion()
class C { }
");
SendKeys("<summary>");
VerifyCurrentLineText("/// <summary>$$</summary>", assertCaretPosition: true);
this.SendKeys("<summary>");
this.VerifyCurrentLineText("/// <summary>$$</summary>", assertCaretPosition: true);
SetUpEditor(@"
/// <summary>$$
class C { }
");
SendKeys("</");
VerifyCurrentLineText("/// <summary></summary>$$", assertCaretPosition: true);
this.SendKeys("</");
this.VerifyCurrentLineText("/// <summary></summary>$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
......@@ -193,12 +195,12 @@ void Main(string[] args)
}
}");
DisableSuggestionMode();
this.SetUseSuggestionMode(false);
SendKeys("Mai(");
this.SendKeys("Mai(");
VerifyCurrentSignature("void Class1.Main(string[] args)");
VerifyCurrentParameter("args", "");
this.VerifyCurrentSignature("void Class1.Main(string[] args)");
this.VerifyCurrentParameter("args", "");
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
......@@ -211,18 +213,18 @@ void Main(string[] args)
$$
}");
DisableSuggestionMode();
this.SetUseSuggestionMode(false);
SendKeys(
this.SendKeys(
'{',
VirtualKey.Enter,
" ");
InvokeCompletionList();
this.InvokeCompletionList();
SendKeys('}');
this.SendKeys('}');
VerifyTextContains(@"
this.VerifyTextContains(@"
class Class1
{
void Main(string[] args)
......@@ -244,13 +246,13 @@ void Main(string[] args)
}
}");
DisableSuggestionMode();
this.SetUseSuggestionMode(false);
SendKeys(
this.SendKeys(
'M',
Shift(VirtualKey.Enter));
VerifyTextContains(@"
this.VerifyTextContains(@"
class Class1
{
void Main(string[] args)
......@@ -270,11 +272,11 @@ class Class1
$$
}");
DisableSuggestionMode();
this.SetUseSuggestionMode(false);
SendKeys("int P { g{");
this.SendKeys("int P { g{");
VerifyTextContains(@"
this.VerifyTextContains(@"
class Class1
{
int P { get { $$} }
......@@ -295,13 +297,13 @@ static void Main(string[] args)
}
}");
SendKeys(
this.SendKeys(
VirtualKey.Delete,
"aaa",
VirtualKey.Tab);
VerifyTextContains("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
VerifyCaretIsOnScreen();
var actualText = Editor.GetText();
Assert.Contains("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", actualText);
Assert.True(Editor.IsCaretOnScreen());
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
......@@ -309,11 +311,11 @@ public void DismissOnSelect()
{
SetUpEditor(@"$$");
SendKeys(Ctrl(VirtualKey.Space));
VerifyCompletionListIsActive(expected: true);
this.SendKeys(Ctrl(VirtualKey.Space));
Assert.Equal(true, Editor.IsCompletionActive());
SendKeys(Ctrl(VirtualKey.A));
VerifyCompletionListIsActive(expected: false);
this.SendKeys(Ctrl(VirtualKey.A));
Assert.Equal(false, Editor.IsCompletionActive());
}
}
}
\ No newline at end of file
......@@ -2,6 +2,8 @@
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Roslyn.VisualStudio.IntegrationTests.Extensions;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Interactive;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.CSharp
......@@ -95,25 +97,25 @@ public void VerifyUndoAndRedo()
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");
this.ExecuteCommand("Edit.LineStart");
this.ExecuteCommand("Edit.LineEnd");
this.ExecuteCommand("Edit.LineStartExtend");
this.ExecuteCommand("Edit.SelectionCancel");
this.ExecuteCommand("Edit.LineEndExtend");
this.ExecuteCommand("Edit.SelectAll");
this.ExecuteCommand("Edit.SelectAll");
this.ExecuteCommand("Edit.Copy");
this.ExecuteCommand("Edit.Cut");
this.ExecuteCommand("Edit.Paste");
this.ExecuteCommand("Edit.Delete");
this.ExecuteCommand("Edit.LineUp");
this.ExecuteCommand("Edit.LineDown");
this.ExecuteCommand("Edit.Paste");
this.ExecuteCommand("Edit.Paste");
SendKeys(VirtualKey.Escape);
}
//<!-- Regression test for bug 13731.
//<!-- 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.
......@@ -129,7 +131,7 @@ public void VerifyReturnIndentCurrentLine()
SendKeys(")");
SendKeys(VirtualKey.Left);
SendKeys(VirtualKey.Enter);
VerifyCaretPosition(12);
this.VerifyCaretPosition(12);
}
}
}
\ No newline at end of file
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Shared.TestHooks;
// 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.CodeAnalysis;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Common;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Roslyn.Test.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Roslyn.VisualStudio.IntegrationTests.Extensions.SolutionExplorer;
using Xunit;
using ProjectUtils = Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils;
namespace Roslyn.VisualStudio.IntegrationTests.CSharp
{
......@@ -21,17 +24,18 @@ public CSharpNavigateTo(VisualStudioInstanceFactory instanceFactory)
[Fact, Trait(Traits.Feature, Traits.Features.SignatureHelp)]
public void NavigateTo()
{
AddFile("test1.cs", open: false, contents: @"
var project = new ProjectUtils.Project(ProjectName);
this.AddFile("test1.cs", project: project, open: false, contents: @"
class FirstClass
{
void FirstMethod() { }
}");
AddFile("test2.cs", open: true, contents: @"
this.AddFile("test2.cs", project: project, open: true, contents: @"
");
InvokeNavigateToAndPressEnter("FirstMethod");
this.InvokeNavigateToAndPressEnter("FirstMethod");
Editor.WaitForActiveView("test1.cs");
Assert.Equal("FirstMethod", Editor.GetSelectedText());
......@@ -39,7 +43,7 @@ class FirstClass
VisualStudio.Instance.SolutionExplorer.AddProject("VBProject", WellKnownProjectTemplates.ClassLibrary, LanguageNames.VisualBasic);
VisualStudio.Instance.SolutionExplorer.AddFile("VBProject", "vbfile.vb", open: true);
InvokeNavigateToAndPressEnter("FirstClass");
this.InvokeNavigateToAndPressEnter("FirstClass");
Editor.WaitForActiveView("test1.cs");
Assert.Equal("FirstClass", Editor.GetSelectedText());
}
......
using Microsoft.CodeAnalysis;
// 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.CodeAnalysis;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Common;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Roslyn.Test.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.CSharp
......@@ -28,7 +30,7 @@ static void Main(string$$[] args)
{
}
}");
InvokeQuickInfo();
this.InvokeQuickInfo();
Assert.Equal(
"class\u200e System\u200e.String\r\nRepresents text as a sequence of UTF-16 code units.To browse the .NET Framework source code for this type, see the Reference Source.",
Editor.GetQuickInfo());
......@@ -45,7 +47,7 @@ static void Main(string[] args)
{
}
}");
InvokeQuickInfo();
this.InvokeQuickInfo();
Assert.Equal("class\u200e Program\r\nHello!", Editor.GetQuickInfo());
}
......@@ -63,7 +65,7 @@ static void Main()
العربية123$$ foo;
}
}");
InvokeQuickInfo();
this.InvokeQuickInfo();
Assert.Equal(@"class" + '\u200e' + @" العربية123
This is an XML doc comment defined in code.", Editor.GetQuickInfo());
}
......@@ -84,7 +86,7 @@ class C
}
}");
InvokeQuickInfo();
this.InvokeQuickInfo();
var expected = "\u200e(awaitable\u200e)\u200e Task\u200e<int\u200e>\u200e C\u200e.M\u200e(\u200e)\u000d\u000a\u000d\u000aUsage:\u000d\u000a int\u200e x\u200e \u200e=\u200e await\u200e M\u200e(\u200e\u200e)\u200e;\u000d\u000a\u000d\u000aExceptions:\u200e\u000d\u000a\u200e Exception";
Assert.Equal(expected, Editor.GetQuickInfo());
}
......
......@@ -2,6 +2,7 @@
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.CSharp
......@@ -30,32 +31,32 @@ public static void Main(string[] args)
}");
PlaceCaret("using");
VerifyCurrentTokenType(tokenType: "keyword");
this.VerifyCurrentTokenType(tokenType: "keyword");
PlaceCaret("{");
VerifyCurrentTokenType(tokenType: "punctuation");
this.VerifyCurrentTokenType(tokenType: "punctuation");
PlaceCaret("Main");
VerifyCurrentTokenType(tokenType: "identifier");
this.VerifyCurrentTokenType(tokenType: "identifier");
PlaceCaret("Hello");
VerifyCurrentTokenType(tokenType: "string");
this.VerifyCurrentTokenType(tokenType: "string");
PlaceCaret("<summary", charsOffset: -1);
SendKeys(new KeyPress(VirtualKey.Right, ShiftState.Alt));
VerifyCurrentTokenType(tokenType: "xml doc comment - delimiter");
this.VerifyCurrentTokenType(tokenType: "xml doc comment - delimiter");
PlaceCaret("summary");
VerifyCurrentTokenType(tokenType: "xml doc comment - name");
this.VerifyCurrentTokenType(tokenType: "xml doc comment - name");
PlaceCaret("innertext");
VerifyCurrentTokenType(tokenType: "xml doc comment - text");
this.VerifyCurrentTokenType(tokenType: "xml doc comment - text");
PlaceCaret("!--");
VerifyCurrentTokenType(tokenType: "xml doc comment - delimiter");
this.VerifyCurrentTokenType(tokenType: "xml doc comment - delimiter");
PlaceCaret("comment");
VerifyCurrentTokenType(tokenType: "xml doc comment - comment");
this.VerifyCurrentTokenType(tokenType: "xml doc comment - comment");
PlaceCaret("CDATA");
VerifyCurrentTokenType(tokenType: "xml doc comment - delimiter");
this.VerifyCurrentTokenType(tokenType: "xml doc comment - delimiter");
PlaceCaret("cdata");
VerifyCurrentTokenType(tokenType: "xml doc comment - cdata section");
this.VerifyCurrentTokenType(tokenType: "xml doc comment - cdata section");
PlaceCaret("attribute");
VerifyCurrentTokenType(tokenType: "identifier");
this.VerifyCurrentTokenType(tokenType: "identifier");
PlaceCaret("Environment");
VerifyCurrentTokenType(tokenType: "class name");
this.VerifyCurrentTokenType(tokenType: "class name");
}
}
}
\ No newline at end of file
......@@ -3,6 +3,8 @@
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Roslyn.VisualStudio.IntegrationTests.Extensions;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.CSharp
......@@ -19,24 +21,24 @@ public CSharpReplIntellisense(VisualStudioInstanceFactory instanceFactory)
[Fact]
public void VerifyCompletionListOnEmptyTextAtTopLevel()
{
InvokeCompletionList();
VerifyCompletionItemExists("var", "public", "readonly", "goto");
this.InvokeCompletionList();
this.VerifyCompletionItemExists("var", "public", "readonly", "goto");
}
[Fact]
public void VerifySharpRCompletionList()
{
InsertCode("#r \"");
InvokeCompletionList();
VerifyCompletionItemExists("System");
this.InvokeCompletionList();
this.VerifyCompletionItemExists("System");
}
[Fact]
public void VerifyCommitCompletionOnTopLevel()
{
InsertCode("pub");
InvokeCompletionList();
VerifyCompletionItemExists("public");
this.InvokeCompletionList();
this.VerifyCompletionItemExists("public");
SendKeys(VirtualKey.Tab);
VerifyLastReplInput("public");
SendKeys(VirtualKey.Escape);
......@@ -49,16 +51,16 @@ public void VerifyCompletionListForAmbiguousParsingCases()
public delegate R Del<T, R>(T arg);
Del<C, System");
SendKeys(VirtualKey.Period);
WaitForAsyncOperations(FeatureAttribute.CompletionSet);
VerifyCompletionItemExists("ArgumentException");
this.WaitForAsyncOperations(FeatureAttribute.CompletionSet);
this.VerifyCompletionItemExists("ArgumentException");
}
[Fact]
public void VerifySharpLoadCompletionList()
{
InsertCode("#load \"");
InvokeCompletionList();
VerifyCompletionItemExists("C:");
this.InvokeCompletionList();
this.VerifyCompletionItemExists("C:");
}
[Fact]
......@@ -81,13 +83,13 @@ public void VerifyCorrectIntellisenseSelectionOnEnter()
public void VerifyCompletionListForLoadMembers()
{
using (var temporaryTextFile = new TemporaryTextFile(
"c.csx",
"c.csx",
"int x = 2; class Complex { public int foo() { return 4; } }"))
{
temporaryTextFile.Create();
SubmitText(string.Format("#load \"{0}\"", temporaryTextFile.FullName));
InvokeCompletionList();
VerifyCompletionItemExists("x", "Complex");
this.InvokeCompletionList();
this.VerifyCompletionItemExists("x", "Complex");
SendKeys(VirtualKey.Escape);
}
}
......
......@@ -2,9 +2,9 @@
using Microsoft.CodeAnalysis;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Common;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Roslyn.Test.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.CSharp
......@@ -61,20 +61,20 @@ void M()
void OutAndParam(ref string[][,] strings, out string[] outArr, params dynamic d) {outArr = null;}
}");
SendKeys("var m = Method(1,");
InvokeSignatureHelp();
VerifyCurrentSignature("C C.Method(int i, int i2)\r\nHello World 2.0!");
VerifyCurrentParameter("i2", "an integer, anything you like.");
VerifyParameters(
this.SendKeys("var m = Method(1,");
this.InvokeSignatureHelp();
this.VerifyCurrentSignature("C C.Method(int i, int i2)\r\nHello World 2.0!");
this.VerifyCurrentParameter("i2", "an integer, anything you like.");
this.VerifyParameters(
("i", "an integer, preferably 42."),
("i2", "an integer, anything you like."));
SendKeys(new object[] { VirtualKey.Home, new KeyPress(VirtualKey.End, ShiftState.Shift), VirtualKey.Delete });
SendKeys("var op = OutAndParam(");
this.SendKeys(new object[] { VirtualKey.Home, new KeyPress(VirtualKey.End, ShiftState.Shift), VirtualKey.Delete });
this.SendKeys("var op = OutAndParam(");
VerifyCurrentSignature("void C.OutAndParam(ref string[][,] strings, out string[] outArr, params dynamic d)\r\nComplex Method Params");
VerifyCurrentParameter("strings", "Jagged MultiDimensional Array");
VerifyParameters(
this.VerifyCurrentSignature("void C.OutAndParam(ref string[][,] strings, out string[] outArr, params dynamic d)\r\nComplex Method Params");
this.VerifyCurrentParameter("strings", "Jagged MultiDimensional Array");
this.VerifyParameters(
("strings", "Jagged MultiDimensional Array"),
("outArr", "Out Array"),
("d", "Dynamic and Params param"));
......@@ -120,10 +120,10 @@ void M()
void OutAndParam(ref string[][,] strings, out string[] outArr, params dynamic d) {outArr = null;}
}");
InvokeSignatureHelp();
VerifyCurrentSignature("C C.GenericMethod<T1, T2>(T1 i, T2 i2)");
VerifyCurrentParameter("T1", "");
VerifyParameters(
this.InvokeSignatureHelp();
this.VerifyCurrentSignature("C C.GenericMethod<T1, T2>(T1 i, T2 i2)");
this.VerifyCurrentParameter("T1", "");
this.VerifyParameters(
("T1", ""),
("T2", ""));
}
......@@ -168,10 +168,10 @@ void M()
void OutAndParam(ref string[][,] strings, out string[] outArr, params dynamic d) {outArr = null;}
}");
InvokeSignatureHelp();
VerifyCurrentSignature("C C.GenericMethod<string, int>(string i, int i2)");
VerifyCurrentParameter("i", "");
VerifyParameters(
this.InvokeSignatureHelp();
this.VerifyCurrentSignature("C C.GenericMethod<string, int>(string i, int i2)");
this.VerifyCurrentParameter("i", "");
this.VerifyParameters(
("i", ""),
("i2", ""));
}
......
......@@ -3,7 +3,10 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Roslyn.VisualStudio.IntegrationTests.Extensions.SolutionExplorer;
using Xunit;
using ProjectUtils = Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils;
namespace Roslyn.VisualStudio.IntegrationTests.CSharp
{
......@@ -20,60 +23,69 @@ public CSharpWinForms(VisualStudioInstanceFactory instanceFactory)
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void AddControl()
{
OpenFileWithDesigner(ProjectName, "Form1.cs");
AddWinFormButton("SomeButton");
SaveFile(ProjectName, "Form1.cs");
OpenFile(ProjectName, "Form1.Designer.cs");
VerifyTextContains(@"this.SomeButton.Name = ""SomeButton""");
VerifyTextContains(@"private System.Windows.Forms.Button SomeButton;");
var project = new ProjectUtils.Project(ProjectName);
this.OpenFileWithDesigner("Form1.cs", project);
this.AddWinFormButton("SomeButton");
this.SaveFile("Form1.cs", project);
this.OpenFile("Form1.Designer.cs", project);
var actualText = Editor.GetText();
Assert.Contains(@"this.SomeButton.Name = ""SomeButton""", actualText);
Assert.Contains(@"private System.Windows.Forms.Button SomeButton;", actualText);
}
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void ChangeControlProperty()
{
OpenFileWithDesigner(ProjectName, "Form1.cs");
AddWinFormButton("SomeButton");
EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Text", propertyValue: "NewButtonText");
CloseFile(ProjectName, "Form1.cs", saveFile: true);
OpenFile(ProjectName, "Form1.Designer.cs");
VerifyTextContains(@"this.SomeButton.Text = ""NewButtonText""");
var project = new ProjectUtils.Project(ProjectName);
this.OpenFileWithDesigner("Form1.cs", project);
this.AddWinFormButton("SomeButton");
this.EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Text", propertyValue: "NewButtonText");
this.CloseFile("Form1.cs", project, saveFile: true);
this.OpenFile("Form1.Designer.cs", project);
var actualText = Editor.GetText();
Assert.Contains(@"this.SomeButton.Text = ""NewButtonText""", actualText);
}
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void ChangeControlPropertyInCode()
{
OpenFileWithDesigner(ProjectName, "Form1.cs");
AddWinFormButton("SomeButton");
EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Text", propertyValue: "ButtonTextGoesHere");
var project = new ProjectUtils.Project(ProjectName);
this.OpenFileWithDesigner("Form1.cs", project);
this.AddWinFormButton("SomeButton");
this.EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Text", propertyValue: "ButtonTextGoesHere");
var expectedPropertyValue = "ButtonTextGoesHere";
var actualPropertyValue = GetWinFormButtonPropertyValue(buttonName: "SomeButton", propertyName: "Text");
var actualPropertyValue = this.GetWinFormButtonPropertyValue(buttonName: "SomeButton", propertyName: "Text");
Assert.Equal(expectedPropertyValue, actualPropertyValue);
CloseFile(ProjectName, "Form1.cs", saveFile: true);
this.CloseFile("Form1.cs", project, saveFile: true);
// Change the control's text in designer.cs code
OpenFile(ProjectName, "Form1.Designer.cs");
this.OpenFile("Form1.Designer.cs", project);
// Verify that the control's property was set correctly. The following text should appear in InitializeComponent().
VerifyTextContains(@"this.SomeButton.Text = ""ButtonTextGoesHere"";");
var actualText = Editor.GetText();
Assert.Contains(@"this.SomeButton.Text = ""ButtonTextGoesHere"";", actualText);
// Replace text property with something else
SelectTextInCurrentDocument(@"this.SomeButton.Text = ""ButtonTextGoesHere"";");
SendKeys(@"this.SomeButton.Text = ""GibberishText"";");
CloseFile(ProjectName, "Form1.Designer.cs", saveFile: true);
this.SelectTextInCurrentDocument(@"this.SomeButton.Text = ""ButtonTextGoesHere"";");
this.SendKeys(@"this.SomeButton.Text = ""GibberishText"";");
this.CloseFile("Form1.Designer.cs", project, saveFile: true);
// Verify that the control text has changed in the designer
OpenFileWithDesigner(ProjectName, "Form1.cs");
this.OpenFileWithDesigner("Form1.cs", project);
expectedPropertyValue = "GibberishText";
actualPropertyValue = GetWinFormButtonPropertyValue(buttonName: "SomeButton", propertyName: "Text");
actualPropertyValue = this.GetWinFormButtonPropertyValue(buttonName: "SomeButton", propertyName: "Text");
Assert.Equal(expectedPropertyValue, actualPropertyValue);
}
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void AddClickHandler()
{
OpenFileWithDesigner(ProjectName, "Form1.cs");
AddWinFormButton("SomeButton");
EditWinFormsButtonEvent(buttonName: "SomeButton", eventName: "Click", eventHandlerName: "ExecuteWhenButtonClicked");
OpenFile(ProjectName, "Form1.Designer.cs");
VerifyTextContains(@"this.SomeButton.Click += new System.EventHandler(this.ExecuteWhenButtonClicked);");
OpenFile(ProjectName, "Form1.cs");
VerifyTextContains(@" public partial class Form1 : Form
var project = new ProjectUtils.Project(ProjectName);
this.OpenFileWithDesigner("Form1.cs", project);
this.AddWinFormButton("SomeButton");
this.EditWinFormsButtonEvent(buttonName: "SomeButton", eventName: "Click", eventHandlerName: "ExecuteWhenButtonClicked");
this.OpenFile("Form1.Designer.cs", project);
var designerActualText = Editor.GetText();
Assert.Contains(@"this.SomeButton.Click += new System.EventHandler(this.ExecuteWhenButtonClicked);", designerActualText);
this.OpenFile("Form1.cs", project);
var codeFileActualText = Editor.GetText();
Assert.Contains(@" public partial class Form1 : Form
{
public Form1()
{
......@@ -84,67 +96,75 @@ private void ExecuteWhenButtonClicked(object sender, EventArgs e)
{
}
}");
}", codeFileActualText);
}
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void RenameControl()
{
OpenFileWithDesigner(ProjectName, "Form1.cs");
AddWinFormButton("SomeButton");
var project = new ProjectUtils.Project(ProjectName);
this.OpenFileWithDesigner("Form1.cs", project);
this.AddWinFormButton("SomeButton");
// Add some control properties and events
EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Text", propertyValue: "ButtonTextValue");
EditWinFormsButtonEvent(buttonName: "SomeButton", eventName: "Click", eventHandlerName: "SomeButtonHandler");
this.EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Text", propertyValue: "ButtonTextValue");
this.EditWinFormsButtonEvent(buttonName: "SomeButton", eventName: "Click", eventHandlerName: "SomeButtonHandler");
// Rename the control
EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Name", propertyValue: "SomeNewButton");
VerifyNoBuildErrors();
this.EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Name", propertyValue: "SomeNewButton");
this.VerifyNoBuildErrors();
// Verify that the rename propagated in designer code
OpenFile(ProjectName, "Form1.Designer.cs");
VerifyTextContains(@"this.SomeNewButton.Name = ""SomeNewButton"";");
VerifyTextContains(@"this.SomeNewButton.Text = ""ButtonTextValue"";");
VerifyTextContains(@"this.SomeNewButton.Click += new System.EventHandler(this.SomeButtonHandler);");
VerifyTextContains(@"private System.Windows.Forms.Button SomeNewButton;");
this.OpenFile("Form1.Designer.cs", project);
var actualText = Editor.GetText();
Assert.Contains(@"this.SomeNewButton.Name = ""SomeNewButton"";", actualText);
Assert.Contains(@"this.SomeNewButton.Text = ""ButtonTextValue"";", actualText);
Assert.Contains(@"this.SomeNewButton.Click += new System.EventHandler(this.SomeButtonHandler);", actualText);
Assert.Contains(@"private System.Windows.Forms.Button SomeNewButton;", actualText);
// Verify that the old button name goes away
VerifyTextDoesNotContain(@"private System.Windows.Forms.Button SomeButton;");
Assert.DoesNotContain(@"private System.Windows.Forms.Button SomeButton;", actualText);
}
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void RemoveEventHandler()
{
OpenFileWithDesigner(ProjectName, "Form1.cs");
AddWinFormButton("SomeButton");
EditWinFormsButtonEvent(buttonName: "SomeButton", eventName: "Click", eventHandlerName: "FooHandler");
var project = new ProjectUtils.Project(ProjectName);
this.OpenFileWithDesigner("Form1.cs", project);
this.AddWinFormButton("SomeButton");
this.EditWinFormsButtonEvent(buttonName: "SomeButton", eventName: "Click", eventHandlerName: "FooHandler");
// Remove the event handler
EditWinFormsButtonEvent(buttonName: "SomeButton", eventName: "Click", eventHandlerName: "");
VerifyNoBuildErrors();
this.EditWinFormsButtonEvent(buttonName: "SomeButton", eventName: "Click", eventHandlerName: "");
this.VerifyNoBuildErrors();
// Verify that the handler is removed
OpenFile(ProjectName, "Form1.Designer.cs");
VerifyTextDoesNotContain(@"this.SomeButton.Click += new System.EventHandler(this.FooHandler);");
this.OpenFile("Form1.Designer.cs", project);
var actualText = Editor.GetText();
Assert.DoesNotContain(@"this.SomeButton.Click += new System.EventHandler(this.FooHandler);", actualText);
}
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void ChangeAccessibility()
{
OpenFileWithDesigner(ProjectName, "Form1.cs");
AddWinFormButton("SomeButton");
EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Modifiers",
var project = new ProjectUtils.Project(ProjectName);
this.OpenFileWithDesigner("Form1.cs", project);
this.AddWinFormButton("SomeButton");
this.EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Modifiers",
propertyTypeName: "System.CodeDom.MemberAttributes",
propertyValue: "Public");
VerifyNoBuildErrors();
OpenFile(ProjectName, "Form1.Designer.cs");
VerifyTextContains(@"public System.Windows.Forms.Button SomeButton;");
this.VerifyNoBuildErrors();
this.OpenFile("Form1.Designer.cs", project);
var actualText = Editor.GetText();
Assert.Contains(@"public System.Windows.Forms.Button SomeButton;", actualText);
}
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void DeleteControl()
{
OpenFileWithDesigner(ProjectName, "Form1.cs");
AddWinFormButton("SomeButton");
DeleteWinFormButton("SomeButton");
VerifyNoBuildErrors();
OpenFile(ProjectName, "Form1.Designer.cs");
VerifyTextDoesNotContain(@"this.SomeButton.Name = ""SomeButton"";");
VerifyTextDoesNotContain(@"private System.Windows.Forms.Button SomeButton;");
var project = new ProjectUtils.Project(ProjectName);
this.OpenFileWithDesigner("Form1.cs", project);
this.AddWinFormButton("SomeButton");
this.DeleteWinFormButton("SomeButton");
this.VerifyNoBuildErrors();
this.OpenFile("Form1.Designer.cs", project);
var actualText = Editor.GetText();
Assert.DoesNotContain(@"this.SomeButton.Name = ""SomeButton"";", actualText);
Assert.DoesNotContain(@"private System.Windows.Forms.Button SomeButton;", actualText);
}
}
}
// 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.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.IntegrationTest.Utilities.OutOfProcess;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.Extensions
{
public static partial class CommonExtensions
{
public static void VerifyCurrentTokenType(AbstractIntegrationTest test, string tokenType, TextViewWindow_OutOfProc window)
{
test.WaitForAsyncOperations(
FeatureAttribute.SolutionCrawler,
FeatureAttribute.DiagnosticService,
FeatureAttribute.Classification);
var actualTokenTypes = window.GetCurrentClassifications();
Assert.Equal(actualTokenTypes.Length, 1);
Assert.Contains(tokenType, actualTokenTypes[0]);
Assert.NotEqual("text", tokenType);
}
public static void VerifyCompletionItemExists(TextViewWindow_OutOfProc window, string[] expectedItems)
{
var completionItems = window.GetCompletionItems();
foreach (var expectedItem in expectedItems)
{
Assert.Contains(expectedItem, completionItems);
}
}
public static void VerifyCaretPosition(TextViewWindow_OutOfProc window, int expectedCaretPosition)
{
var position = window.GetCaretPosition();
Assert.Equal(expectedCaretPosition, position);
}
}
}
// 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.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
namespace Roslyn.VisualStudio.IntegrationTests.Extensions
{
public static partial class CommonExtensions
{
public static void ExecuteCommand(this AbstractIntegrationTest test, string commandName, string argument = "")
=> test.VisualStudio.Instance.ExecuteCommand(commandName, argument);
public static void WaitForAsyncOperations(this AbstractIntegrationTest test, params string[] featuresToWaitFor)
=> test.VisualStudio.Instance.VisualStudioWorkspace.WaitForAsyncOperations(string.Join(";", featuresToWaitFor));
public static void InvokeCompletionList(AbstractIntegrationTest test)
{
test.ExecuteCommand(WellKnownCommandNames.Edit_ListMembers);
test.WaitForAsyncOperations(FeatureAttribute.CompletionSet);
}
}
}
// 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.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Common;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.Extensions.Editor
{
public static partial class EditorExtensions
{
public static void VerifyCurrentTokenType(this AbstractIntegrationTest test, string tokenType)
{
CommonExtensions.VerifyCurrentTokenType(test, tokenType, test.VisualStudio.Instance.Editor);
}
public static void VerifyCompletionItemExists(this AbstractIntegrationTest test, params string[] expectedItems)
{
CommonExtensions.VerifyCompletionItemExists(test.VisualStudio.Instance.Editor, expectedItems);
}
public static void VerifyCaretPosition(this AbstractIntegrationTest test, int expectedCaretPosition)
{
CommonExtensions.VerifyCaretPosition(test.VisualStudio.Instance.Editor, expectedCaretPosition);
}
public static void VerifyCurrentLineText(this AbstractIntegrationTest test, string expectedText, bool assertCaretPosition = false, bool trimWhitespace = true)
{
if (assertCaretPosition)
{
VerifyCurrentLineTextAndAssertCaretPosition(test, expectedText, trimWhitespace);
}
else
{
var lineText = test.VisualStudio.Instance.Editor.GetCurrentLineText();
if (trimWhitespace)
{
lineText = lineText.Trim();
}
Assert.Equal(expectedText, lineText);
}
}
private static void VerifyCurrentLineTextAndAssertCaretPosition(AbstractIntegrationTest test, string expectedText, bool trimWhitespace)
{
var caretStartIndex = expectedText.IndexOf("$$");
if (caretStartIndex < 0)
{
throw new ArgumentException("Expected caret position to be specified with $$", nameof(expectedText));
}
var caretEndIndex = caretStartIndex + "$$".Length;
var expectedTextBeforeCaret = expectedText.Substring(0, caretStartIndex);
var expectedTextAfterCaret = expectedText.Substring(caretEndIndex);
var lineText = test.VisualStudio.Instance.Editor.GetCurrentLineText();
if (trimWhitespace)
{
if (caretStartIndex == 0)
{
lineText = lineText.TrimEnd();
}
else if (caretEndIndex == expectedText.Length)
{
lineText = lineText.TrimStart();
}
else
{
lineText = lineText.Trim();
}
}
var lineTextBeforeCaret = caretStartIndex < lineText.Length
? lineText.Substring(0, caretStartIndex)
: lineText;
var lineTextAfterCaret = caretStartIndex < lineText.Length
? lineText.Substring(caretStartIndex)
: string.Empty;
Assert.Equal(expectedTextBeforeCaret, lineTextBeforeCaret);
Assert.Equal(expectedTextAfterCaret, lineTextAfterCaret);
Assert.Equal(expectedTextBeforeCaret.Length + expectedTextAfterCaret.Length, lineText.Length);
}
public static void VerifyTextContains(this AbstractIntegrationTest test, string expectedText, bool assertCaretPosition = false)
{
if (assertCaretPosition)
{
VerifyTextContainsAndAssertCaretPosition(test, expectedText);
}
else
{
var editorText = test.VisualStudio.Instance.Editor.GetText();
Assert.Contains(expectedText, editorText);
}
}
private static void VerifyTextContainsAndAssertCaretPosition(AbstractIntegrationTest test, string expectedText)
{
var caretStartIndex = expectedText.IndexOf("$$");
if (caretStartIndex < 0)
{
throw new ArgumentException("Expected caret position to be specified with $$", nameof(expectedText));
}
var caretEndIndex = caretStartIndex + "$$".Length;
var expectedTextBeforeCaret = expectedText.Substring(0, caretStartIndex);
var expectedTextAfterCaret = expectedText.Substring(caretEndIndex);
var expectedTextWithoutCaret = expectedTextBeforeCaret + expectedTextAfterCaret;
var editorText = test.VisualStudio.Instance.Editor.GetText();
Assert.Contains(expectedTextWithoutCaret, editorText);
var index = editorText.IndexOf(expectedTextWithoutCaret);
var caretPosition = test.VisualStudio.Instance.Editor.GetCaretPosition();
Assert.Equal(caretStartIndex + index, caretPosition);
}
public static void VerifyCompletionItemDoesNotExist(this AbstractIntegrationTest test, params string[] expectedItems)
{
var completionItems = test.VisualStudio.Instance.Editor.GetCompletionItems();
foreach (var expectedItem in expectedItems)
{
Assert.DoesNotContain(expectedItem, completionItems);
}
}
public static void VerifyCurrentCompletionItem(this AbstractIntegrationTest test, string expectedItem)
{
var currentItem = test.VisualStudio.Instance.Editor.GetCurrentCompletionItem();
Assert.Equal(expectedItem, currentItem);
}
public static void VerifyCurrentSignature(this AbstractIntegrationTest test, Signature expectedSignature)
{
var currentSignature = test.VisualStudio.Instance.Editor.GetCurrentSignature();
Assert.Equal(expectedSignature, currentSignature);
}
public static void VerifyCurrentSignature(this AbstractIntegrationTest test, string content)
{
var currentSignature = test.VisualStudio.Instance.Editor.GetCurrentSignature();
Assert.Equal(content, currentSignature.Content);
}
public static void VerifyCodeAction(
this AbstractIntegrationTest test,
string expectedItem,
bool applyFix = false,
bool verifyNotShowing = false,
bool ensureExpectedItemsAreOrdered = false,
FixAllScope? fixAllScope = null,
bool blockUntilComplete = true)
{
var expectedItems = new[] { expectedItem };
test.VerifyCodeActions(
expectedItems, applyFix ? expectedItem : null, verifyNotShowing,
ensureExpectedItemsAreOrdered, fixAllScope, blockUntilComplete);
}
public static void VerifyCodeActions(
this AbstractIntegrationTest test,
IEnumerable<string> expectedItems,
string applyFix = null,
bool verifyNotShowing = false,
bool ensureExpectedItemsAreOrdered = false,
FixAllScope? fixAllScope = null,
bool blockUntilComplete = true)
{
test.VisualStudio.Instance.Editor.ShowLightBulb();
test.VisualStudio.Instance.Editor.WaitForLightBulbSession();
if (verifyNotShowing)
{
test.VerifyCodeActionsNotShowing();
return;
}
var actions = test.VisualStudio.Instance.Editor.GetLightBulbActions();
if (expectedItems != null && expectedItems.Any())
{
if (ensureExpectedItemsAreOrdered)
{
TestUtilities.ThrowIfExpectedItemNotFoundInOrder(
actions,
expectedItems);
}
else
{
TestUtilities.ThrowIfExpectedItemNotFound(
actions,
expectedItems);
}
}
if (!string.IsNullOrEmpty(applyFix) || fixAllScope.HasValue)
{
test.VisualStudio.Instance.Editor.ApplyLightBulbAction(applyFix, fixAllScope, blockUntilComplete);
if (blockUntilComplete)
{
// wait for action to complete
test.WaitForAsyncOperations(FeatureAttribute.LightBulb);
}
}
}
public static void VerifyCodeActionsNotShowing(this AbstractIntegrationTest test)
{
if (test.VisualStudio.Instance.Editor.IsLightBulbSessionExpanded())
{
throw new InvalidOperationException("Expected no light bulb session, but one was found.");
}
}
public static void VerifyCurrentParameter(this AbstractIntegrationTest test, string name, string documentation)
{
var currentParameter = test.VisualStudio.Instance.Editor.GetCurrentSignature().CurrentParameter;
Assert.Equal(name, currentParameter.Name);
Assert.Equal(documentation, currentParameter.Documentation);
}
public static void VerifyParameters(this AbstractIntegrationTest test, params (string name, string documentation)[] parameters)
{
var currentParameters = test.VisualStudio.Instance.Editor.GetCurrentSignature().Parameters;
for (var i = 0; i < parameters.Length; i++)
{
var (expectedName, expectedDocumentation) = parameters[i];
Assert.Equal(expectedName, currentParameters[i].Name);
Assert.Equal(expectedDocumentation, currentParameters[i].Documentation);
}
}
public static void VerifyDialog(this AbstractIntegrationTest test, string dialogName, bool isOpen)
{
test.VisualStudio.Instance.Editor.VerifyDialog(dialogName, isOpen);
}
}
}
// 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.Windows.Automation;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
namespace Roslyn.VisualStudio.IntegrationTests.Extensions.Editor
{
public static partial class EditorExtensions
{
public static void AddWinFormButton(this AbstractIntegrationTest test, string buttonName)
=> test.VisualStudio.Instance.Editor.AddWinFormButton(buttonName);
public static void DeleteWinFormButton(this AbstractIntegrationTest test, string buttonName)
=> test.VisualStudio.Instance.Editor.DeleteWinFormButton(buttonName);
public static void EditWinFormButtonProperty(this AbstractIntegrationTest test, string buttonName, string propertyName, string propertyValue, string propertyTypeName = null)
=> test.VisualStudio.Instance.Editor.EditWinFormButtonProperty(buttonName, propertyName, propertyValue, propertyTypeName);
public static void EditWinFormsButtonEvent(this AbstractIntegrationTest test, string buttonName, string eventName, string eventHandlerName)
=> test.VisualStudio.Instance.Editor.EditWinFormButtonEvent(buttonName, eventName, eventHandlerName);
public static string GetWinFormButtonPropertyValue(this AbstractIntegrationTest test, string buttonName, string propertyName)
=> test.VisualStudio.Instance.Editor.GetWinFormButtonPropertyValue(buttonName, propertyName);
public static void SelectTextInCurrentDocument(this AbstractIntegrationTest test, string text)
{
test.VisualStudio.Instance.Editor.PlaceCaret(text, charsOffset: -1, occurrence: 0, extendSelection: false, selectBlock: false);
test.VisualStudio.Instance.Editor.PlaceCaret(text, charsOffset: 0, occurrence: 0, extendSelection: true, selectBlock: false);
}
public static void DeleteText(this AbstractIntegrationTest test, string text)
{
test.SelectTextInCurrentDocument(text);
test.SendKeys(VirtualKey.Delete);
}
public static void PlaceCaret(this AbstractIntegrationTest test, string text, int charsOffset = 0)
=> test.VisualStudio.Instance.Editor.PlaceCaret(text, charsOffset: charsOffset, occurrence: 0, extendSelection: false, selectBlock: false);
public static void SendKeys(this AbstractIntegrationTest test, params object[] keys)
=> test.VisualStudio.Instance.Editor.SendKeys(keys);
public static void InvokeCompletionList(this AbstractIntegrationTest test)
{
CommonExtensions.InvokeCompletionList(test);
}
public static void InvokeSignatureHelp(this AbstractIntegrationTest test)
{
test.ExecuteCommand(WellKnownCommandNames.Edit_ParameterInfo);
test.WaitForAsyncOperations(FeatureAttribute.SignatureHelp);
}
public static void InvokeQuickInfo(this AbstractIntegrationTest test)
{
test.ExecuteCommand(WellKnownCommandNames.Edit_QuickInfo);
test.WaitForAsyncOperations(FeatureAttribute.QuickInfo);
}
public static void InvokeCodeActionList(this AbstractIntegrationTest test)
{
test.WaitForAsyncOperations(FeatureAttribute.SolutionCrawler);
test.WaitForAsyncOperations(FeatureAttribute.DiagnosticService);
test.VisualStudio.Instance.Editor.ShowLightBulb();
test.VisualStudio.Instance.Editor.WaitForLightBulbSession();
test.WaitForAsyncOperations(FeatureAttribute.LightBulb);
}
public static void InvokeNavigateToAndPressEnter(this AbstractIntegrationTest test, string text)
{
test.ExecuteCommand(WellKnownCommandNames.Edit_GoToAll);
test.VisualStudio.Instance.Editor.NavigateToSendKeys(text);
test.WaitForAsyncOperations(FeatureAttribute.NavigateTo);
test.VisualStudio.Instance.Editor.NavigateToSendKeys("{ENTER}");
}
public static void PressDialogButton(this AbstractIntegrationTest test, string dialogAutomationName, string buttonAutomationName)
{
test.VisualStudio.Instance.Editor.PressDialogButton(dialogAutomationName, buttonAutomationName);
}
public static AutomationElement GetDialog(this AbstractIntegrationTest test, string dialogAutomationId)
{
var dialog = DialogHelpers.FindDialog(test.VisualStudio.Instance.Shell.GetHWnd(), dialogAutomationId, isOpen: true);
return dialog;
}
}
}
// 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.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
namespace Roslyn.VisualStudio.IntegrationTests.Extensions.Interactive
{
public static class InteractiveExtensions
{
public static void VerifyCurrentTokenType(this AbstractIntegrationTest test, string tokenType)
{
CommonExtensions.VerifyCurrentTokenType(test, tokenType, test.VisualStudio.Instance.CSharpInteractiveWindow);
}
public static void VerifyCompletionItemExists(this AbstractIntegrationTest test, params string[] expectedItems)
{
CommonExtensions.VerifyCompletionItemExists(test.VisualStudio.Instance.CSharpInteractiveWindow, expectedItems);
}
public static void VerifyCaretPosition(this AbstractIntegrationTest test, int expectedCaretPosition)
{
CommonExtensions.VerifyCaretPosition(test.VisualStudio.Instance.CSharpInteractiveWindow, expectedCaretPosition);
}
public static void InvokeCompletionList(this AbstractIntegrationTest test)
{
CommonExtensions.InvokeCompletionList(test);
}
}
}
// 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.CodeAnalysis;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using ProjectUtils = Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils;
namespace Roslyn.VisualStudio.IntegrationTests.Extensions.Options
{
public static class SetOptionsExtensions
{
public static void SetUseSuggestionMode(this AbstractIntegrationTest test, bool value)
=> test.VisualStudio.Instance.VisualStudioWorkspace.SetUseSuggestionMode(value);
public static void SetQuickInfo(this AbstractIntegrationTest test, bool value)
{
test.VisualStudio.Instance.VisualStudioWorkspace.SetQuickInfo(value);
test.WaitForAsyncOperations(FeatureAttribute.Workspace);
}
public static void SetOptionInfer(this AbstractIntegrationTest test, ProjectUtils.Project project, bool value)
{
test.VisualStudio.Instance.VisualStudioWorkspace.SetOptionInfer(project.Name, value);
test.WaitForAsyncOperations(FeatureAttribute.Workspace);
}
public static void SetPersistenceOption(this AbstractIntegrationTest test, bool value)
{
test.VisualStudio.Instance.VisualStudioWorkspace.SetPersistenceOption(value);
test.WaitForAsyncOperations(FeatureAttribute.Workspace);
}
public static void SetFullSolutionAnalysis(this AbstractIntegrationTest test, bool value)
{
test.VisualStudio.Instance.VisualStudioWorkspace.SetPerLanguageOption(
optionName: "Closed File Diagnostic",
feature: "ServiceFeaturesOnOff",
language: LanguageNames.CSharp,
value: value ? "true" : "false");
test.VisualStudio.Instance.VisualStudioWorkspace.SetPerLanguageOption(
optionName: "Closed File Diagnostic",
feature: "ServiceFeaturesOnOff",
language: LanguageNames.VisualBasic,
value: value ? "true" : "false");
}
}
}
// 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 Xunit;
using ProjectUtils = Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils;
namespace Roslyn.VisualStudio.IntegrationTests.Extensions.SolutionExplorer
{
public static partial class SolutionExplorerExtensions
{
public static void VerifyAssemblyReferencePresent(this AbstractIntegrationTest test, ProjectUtils.Project project, string assemblyName, string assemblyVersion, string assemblyPublicKeyToken)
{
var assemblyReferences = test.VisualStudio.Instance.SolutionExplorer.GetAssemblyReferences(project.Name);
var expectedAssemblyReference = assemblyName + "," + assemblyVersion + "," + assemblyPublicKeyToken.ToUpper();
Assert.Contains(expectedAssemblyReference, assemblyReferences);
}
public static void VerifyProjectReferencePresent(this AbstractIntegrationTest test, ProjectUtils.Project project, string referencedProjectName)
{
var projectReferences = test.VisualStudio.Instance.SolutionExplorer.GetProjectReferences(project.Name);
Assert.Contains(referencedProjectName, projectReferences);
}
public static void VerifyNoBuildErrors(this AbstractIntegrationTest test)
{
test.BuildSolution(waitForBuildToFinish: true);
Assert.Equal(0, test.GetErrorListErrorCount());
}
public static void VerifyFileContents(this AbstractIntegrationTest test, ProjectUtils.Project project, string fileName, string expectedContents)
{
var actualContents = test.VisualStudio.Instance.SolutionExplorer.GetFileContents(project.Name, fileName);
Assert.Equal(expectedContents, actualContents);
}
}
}
// 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.CodeAnalysis.Shared.TestHooks;
using ProjectUtils = Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils;
namespace Roslyn.VisualStudio.IntegrationTests.Extensions.SolutionExplorer
{
public static partial class SolutionExplorerExtensions
{
public static void CreateSolution(this AbstractIntegrationTest test, string solutionName, bool saveExistingSolutionIfExists = false)
=> test.VisualStudio.Instance.SolutionExplorer.CreateSolution(solutionName, saveExistingSolutionIfExists);
public static void CloseSolution(this AbstractIntegrationTest test, bool saveFirst = false)
=> test.VisualStudio.Instance.SolutionExplorer.CloseSolution(saveFirst);
public static void AddProject(this AbstractIntegrationTest test, string projectTemplate, ProjectUtils.Project project, string languageName)
=> test.VisualStudio.Instance.SolutionExplorer.AddProject(project.Name, projectTemplate, languageName);
public static void AddFile(this AbstractIntegrationTest test, string fileName, ProjectUtils.Project project, string contents = null, bool open = false)
=> test.VisualStudio.Instance.SolutionExplorer.AddFile(project.Name, fileName, contents, open);
public static void AddMetadataReference(this AbstractIntegrationTest test, ProjectUtils.AssemblyReference referenceName, ProjectUtils.Project projectName)
{
test.VisualStudio.Instance.SolutionExplorer.AddMetadataReference(referenceName.Name, projectName.Name);
test.WaitForAsyncOperations(FeatureAttribute.Workspace);
}
public static void RemoveMetadataReference(this AbstractIntegrationTest test, ProjectUtils.AssemblyReference referenceName, ProjectUtils.Project projectName)
{
test.VisualStudio.Instance.SolutionExplorer.RemoveMetadataReference(referenceName.Name, projectName.Name);
test.WaitForAsyncOperations(FeatureAttribute.Workspace);
}
public static void AddProjectReference(this AbstractIntegrationTest test, ProjectUtils.Project fromProjectName, ProjectUtils.ProjectReference toProjectName)
{
test.VisualStudio.Instance.SolutionExplorer.AddProjectReference(fromProjectName.Name, toProjectName.Name);
test.WaitForAsyncOperations(FeatureAttribute.Workspace);
}
public static void RemoveProjectReference(this AbstractIntegrationTest test, ProjectUtils.ProjectReference projectReferenceName, ProjectUtils.Project projectName)
{
test.VisualStudio.Instance.SolutionExplorer.RemoveProjectReference(projectName.Name, projectReferenceName.Name);
test.WaitForAsyncOperations(FeatureAttribute.Workspace);
}
public static void OpenFile(this AbstractIntegrationTest test, string fileName, ProjectUtils.Project project)
=> test.VisualStudio.Instance.SolutionExplorer.OpenFile(project.Name, fileName);
public static void OpenFileWithDesigner(this AbstractIntegrationTest test, string fileName, ProjectUtils.Project project)
=> test.VisualStudio.Instance.SolutionExplorer.OpenFileWithDesigner(project.Name, fileName);
public static void CloseFile(this AbstractIntegrationTest test, string fileName, ProjectUtils.Project project, bool saveFile = true)
=> test.VisualStudio.Instance.SolutionExplorer.CloseFile(project.Name, fileName, saveFile);
public static void SaveFile(this AbstractIntegrationTest test, string fileName, ProjectUtils.Project project)
=> test.VisualStudio.Instance.SolutionExplorer.SaveFile(project.Name, fileName);
public static void SaveAll(this AbstractIntegrationTest test)
=> test.VisualStudio.Instance.SolutionExplorer.SaveAll();
public static void BuildSolution(this AbstractIntegrationTest test, bool waitForBuildToFinish)
=> test.VisualStudio.Instance.SolutionExplorer.BuildSolution(waitForBuildToFinish);
public static int GetErrorListErrorCount(this AbstractIntegrationTest test)
=> test.VisualStudio.Instance.SolutionExplorer.ErrorListErrorCount;
public static void EditProjectFile(this AbstractIntegrationTest test, ProjectUtils.Project project)
=> test.VisualStudio.Instance.SolutionExplorer.EditProjectFile(project.Name);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// 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.Xml.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Roslyn.VisualStudio.IntegrationTests.Extensions.SolutionExplorer;
using Xunit;
using ProjectUtils = Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils;
namespace Roslyn.VisualStudio.IntegrationTests.VisualBasic
{
......@@ -141,38 +141,40 @@ public BasicAddMissingReference(VisualStudioInstanceFactory instanceFactory)
[Fact, Trait(Traits.Feature, Traits.Features.AddMissingReference)]
public void VerifyAvailableCodeActions()
{
OpenFile(ConsoleProjectName, "Module1.vb");
PlaceCaret("y.foo", charsOffset: 1);
InvokeCodeActionList();
VerifyCodeAction("Add reference to 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.", applyFix: false);
PlaceCaret("x.foo", charsOffset: 1);
InvokeCodeActionList();
VerifyCodeAction("Add reference to 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.", applyFix: false);
PlaceCaret("z.DialogResult", charsOffset: 1);
InvokeCodeActionList();
VerifyCodeAction("Add reference to 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.", applyFix: false);
PlaceCaret("a.bar", charsOffset: 1);
InvokeCodeActionList();
VerifyCodeAction("Add project reference to 'ClassLibrary3'.", applyFix: false);
var consoleProject = new ProjectUtils.Project(ConsoleProjectName);
this.OpenFile("Module1.vb", consoleProject);
this.PlaceCaret("y.foo", charsOffset: 1);
this.InvokeCodeActionList();
this.VerifyCodeAction("Add reference to 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.", applyFix: false);
this.PlaceCaret("x.foo", charsOffset: 1);
this.InvokeCodeActionList();
this.VerifyCodeAction("Add reference to 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.", applyFix: false);
this.PlaceCaret("z.DialogResult", charsOffset: 1);
this.InvokeCodeActionList();
this.VerifyCodeAction("Add reference to 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.", applyFix: false);
this.PlaceCaret("a.bar", charsOffset: 1);
this.InvokeCodeActionList();
this.VerifyCodeAction("Add project reference to 'ClassLibrary3'.", applyFix: false);
}
[Fact, Trait(Traits.Feature, Traits.Features.AddMissingReference)]
public void InvokeSomeFixesInVisualBasicThenVerifyReferences()
{
OpenFile(ConsoleProjectName, "Module1.vb");
PlaceCaret("y.foo", charsOffset: 1);
InvokeCodeActionList();
VerifyCodeAction("Add reference to 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.", applyFix: true);
VerifyAssemblyReferencePresent(
projectName: ConsoleProjectName,
var consoleProject = new ProjectUtils.Project(ConsoleProjectName);
this.OpenFile("Module1.vb", consoleProject);
this.PlaceCaret("y.foo", charsOffset: 1);
this.InvokeCodeActionList();
this.VerifyCodeAction("Add reference to 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.", applyFix: true);
this.VerifyAssemblyReferencePresent(
project: consoleProject,
assemblyName: "System.Windows.Forms",
assemblyVersion: "4.0.0.0",
assemblyPublicKeyToken: "b77a5c561934e089");
PlaceCaret("a.bar", charsOffset: 1);
InvokeCodeActionList();
VerifyCodeAction("Add project reference to 'ClassLibrary3'.", applyFix: true);
VerifyProjectReferencePresent(
projectName: ConsoleProjectName,
this.PlaceCaret("a.bar", charsOffset: 1);
this.InvokeCodeActionList();
this.VerifyCodeAction("Add project reference to 'ClassLibrary3'.", applyFix: true);
this.VerifyProjectReferencePresent(
project: consoleProject,
referencedProjectName: ClassLibrary3Name);
}
}
......
......@@ -4,6 +4,7 @@
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Roslyn.Test.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.VisualBasic
......@@ -28,15 +29,15 @@ Sub Foo()
End Sub
End Class");
SendKeys("Dim x = {");
VerifyCurrentLineText("Dim x = {$$}", assertCaretPosition: true);
this.SendKeys("Dim x = {");
this.VerifyCurrentLineText("Dim x = {$$}", assertCaretPosition: true);
SendKeys(
this.SendKeys(
"New Object",
VirtualKey.Escape,
VirtualKey.Tab);
VerifyCurrentLineText("Dim x = {New Object}$$", assertCaretPosition: true);
this.VerifyCurrentLineText("Dim x = {New Object}$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -49,9 +50,9 @@ Sub Foo()
End Sub
End Class");
SendKeys("Dim x = {");
SendKeys('}');
VerifyCurrentLineText("Dim x = {}$$", assertCaretPosition: true);
this.SendKeys("Dim x = {");
this.SendKeys('}');
this.VerifyCurrentLineText("Dim x = {}$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -64,17 +65,17 @@ Sub Foo()
End Sub
End Class");
SendKeys("Console.Write(");
VerifyCurrentLineText("Console.Write($$)", assertCaretPosition: true);
this.SendKeys("Console.Write(");
this.VerifyCurrentLineText("Console.Write($$)", assertCaretPosition: true);
SendKeys('"');
VerifyCurrentLineText("Console.Write(\"$$\")", assertCaretPosition: true);
this.SendKeys('"');
this.VerifyCurrentLineText("Console.Write(\"$$\")", assertCaretPosition: true);
SendKeys('"');
VerifyCurrentLineText("Console.Write(\"\"$$)", assertCaretPosition: true);
this.SendKeys('"');
this.VerifyCurrentLineText("Console.Write(\"\"$$)", assertCaretPosition: true);
SendKeys(')');
VerifyCurrentLineText("Console.Write(\"\")$$", assertCaretPosition: true);
this.SendKeys(')');
this.VerifyCurrentLineText("Console.Write(\"\")$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -87,11 +88,10 @@ Sub Foo()
End Sub
End Class");
SendKeys("Dim x = {");
SendKeys(VirtualKey.Enter);
VerifyCurrentLineText(" $$}", assertCaretPosition: true, trimWhitespace: false);
VerifyTextContains(@"
this.SendKeys("Dim x = {");
this.SendKeys(VirtualKey.Enter);
this.VerifyCurrentLineText(" $$}", assertCaretPosition: true, trimWhitespace: false);
this.VerifyTextContains(@"
Class C
Sub Foo()
Dim x = {
......@@ -109,13 +109,13 @@ Class C
$$
End Class");
SendKeys("Sub Foo(");
VerifyCurrentLineText("Sub Foo($$)", assertCaretPosition: true);
this.SendKeys("Sub Foo(");
this.VerifyCurrentLineText("Sub Foo($$)", assertCaretPosition: true);
SendKeys("x As Long");
SendKeys(VirtualKey.Escape);
SendKeys(VirtualKey.Tab);
VerifyCurrentLineText("Sub Foo(x As Long)$$", assertCaretPosition: true);
this.SendKeys("x As Long");
this.SendKeys(VirtualKey.Escape);
this.SendKeys(VirtualKey.Tab);
this.VerifyCurrentLineText("Sub Foo(x As Long)$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -126,12 +126,12 @@ Class C
$$
End Class");
SendKeys("Sub Foo(");
VerifyCurrentLineText("Sub Foo($$)", assertCaretPosition: true);
this.SendKeys("Sub Foo(");
this.VerifyCurrentLineText("Sub Foo($$)", assertCaretPosition: true);
SendKeys(VirtualKey.Escape);
SendKeys(')');
VerifyCurrentLineText("Sub Foo()$$", assertCaretPosition: true);
this.SendKeys(VirtualKey.Escape);
this.SendKeys(')');
this.VerifyCurrentLineText("Sub Foo()$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -144,8 +144,8 @@ Sub Foo()
End Sub
End Class");
SendKeys("Dim [Dim");
VerifyCurrentLineText("Dim [Dim$$]", assertCaretPosition: true);
this.SendKeys("Dim [Dim");
this.VerifyCurrentLineText("Dim [Dim$$]", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -158,11 +158,11 @@ Sub Foo()
End Sub
End Class");
SendKeys("Dim [Dim");
VerifyCurrentLineText("Dim [Dim$$]", assertCaretPosition: true);
this.SendKeys("Dim [Dim");
this.VerifyCurrentLineText("Dim [Dim$$]", assertCaretPosition: true);
SendKeys("] As Long");
VerifyCurrentLineText("Dim [Dim] As Long$$", assertCaretPosition: true);
this.SendKeys("] As Long");
this.VerifyCurrentLineText("Dim [Dim] As Long$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -175,11 +175,11 @@ Sub Foo()
End Sub
End Class");
SendKeys("Dim str = \"");
VerifyCurrentLineText("Dim str = \"$$\"", assertCaretPosition: true);
this.SendKeys("Dim str = \"");
this.VerifyCurrentLineText("Dim str = \"$$\"", assertCaretPosition: true);
SendKeys(VirtualKey.Tab);
VerifyCurrentLineText("Dim str = \"\"$$", assertCaretPosition: true);
this.SendKeys(VirtualKey.Tab);
this.VerifyCurrentLineText("Dim str = \"\"$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -195,13 +195,13 @@ Sub Foo()
End Sub
End Class");
SendKeys(
this.SendKeys(
"Dim y = {New C([dim",
VirtualKey.Escape,
"]:=\"hello({[\")}",
VirtualKey.Enter);
VerifyTextContains("Dim y = {New C([dim]:=\"hello({[\")}");
var actualText = Editor.GetText();
Assert.Contains("Dim y = {New C([dim]:=\"hello({[\")}", actualText);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -217,7 +217,7 @@ Sub Foo()
End Sub
End Class");
SendKeys(
this.SendKeys(
"Dim y = {New C([dim",
VirtualKey.Escape,
VirtualKey.Tab,
......@@ -226,8 +226,8 @@ End Sub
VirtualKey.Tab,
VirtualKey.Tab,
VirtualKey.Enter);
VerifyTextContains("Dim y = {New C([dim]:=\"hello({[\")}");
var actualText = Editor.GetText();
Assert.Contains("Dim y = {New C([dim]:=\"hello({[\")}", actualText);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -240,8 +240,8 @@ Sub Foo()
End Sub
End Class");
SendKeys("{([\"");
VerifyCurrentLineText("' {([\"$$", assertCaretPosition: true);
this.SendKeys("{([\"");
this.VerifyCurrentLineText("' {([\"$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -254,8 +254,8 @@ Sub Foo()
End Sub
End Class");
SendKeys("Dim s = \"{([");
VerifyCurrentLineText("Dim s = \"{([$$\"", assertCaretPosition: true);
this.SendKeys("Dim s = \"{([");
this.VerifyCurrentLineText("Dim s = \"{([$$\"", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -266,12 +266,12 @@ public void Negative_NoCompletionInXmlDocComment()
Class C
End Class");
SendKeys("'''");
SendKeys('{');
SendKeys('(');
SendKeys('[');
SendKeys('"');
VerifyCurrentLineText("''' {([\"$$", assertCaretPosition: true);
this.SendKeys("'''");
this.SendKeys('{');
this.SendKeys('(');
this.SendKeys('[');
this.SendKeys('"');
this.VerifyCurrentLineText("''' {([\"$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.AutomaticCompletion)]
......@@ -286,8 +286,8 @@ Sub Foo()
End Sub
End Class");
SendKeys("(");
VerifyCurrentLineText("''' <see></see>($$", assertCaretPosition: true);
this.SendKeys("(");
this.VerifyCurrentLineText("''' <see></see>($$", assertCaretPosition: true);
}
[WorkItem(652015, "DevDiv")]
......@@ -301,8 +301,8 @@ Sub Foo()
End Sub
End Class");
SendKeys("Dim x=\"\" '");
VerifyCurrentLineText("Dim x=\"\" '$$", assertCaretPosition: true);
this.SendKeys("Dim x=\"\" '");
this.VerifyCurrentLineText("Dim x=\"\" '$$", assertCaretPosition: true);
}
[WorkItem(653399, "DevDiv")]
......@@ -315,11 +315,11 @@ Class C
End Sub
End Class");
SendKeys(VirtualKey.Enter);
SendKeys('(');
SendKeys(VirtualKey.Backspace);
this.SendKeys(VirtualKey.Enter);
this.SendKeys('(');
this.SendKeys(VirtualKey.Backspace);
VerifyCurrentLineText(" $$", assertCaretPosition: true, trimWhitespace: false);
this.VerifyCurrentLineText(" $$", assertCaretPosition: true, trimWhitespace: false);
}
[WorkItem(659684, "DevDiv")]
......@@ -335,8 +335,8 @@ Sub Test()
End Sub
End Class");
SendKeys("Foo(");
VerifyCurrentLineText("Foo($$)", assertCaretPosition: true);
this.SendKeys("Foo(");
this.VerifyCurrentLineText("Foo($$)", assertCaretPosition: true);
}
[WorkItem(657451, "DevDiv")]
......@@ -347,8 +347,8 @@ public void CompletionAtTheEndOfFile()
Class C
$$");
SendKeys("Sub Foo(");
VerifyCurrentLineText("Sub Foo($$)", assertCaretPosition: true);
this.SendKeys("Sub Foo(");
this.VerifyCurrentLineText("Sub Foo($$)", assertCaretPosition: true);
}
}
}
......@@ -5,7 +5,11 @@
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.OutOfProcess;
using Roslyn.Test.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Roslyn.VisualStudio.IntegrationTests.Extensions.SolutionExplorer;
using Xunit;
using ProjectUtils = Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils;
namespace Roslyn.VisualStudio.IntegrationTests.VisualBasic
{
......@@ -20,7 +24,7 @@ public BasicChangeSignatureDialog(VisualStudioInstanceFactory instanceFactory)
: base(instanceFactory, nameof(BasicChangeSignatureDialog))
{
}
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/17393"),
Trait(Traits.Feature, Traits.Features.ChangeSignature)]
public void VerifyCodeRefactoringOffered()
......@@ -31,8 +35,8 @@ Class C
End Sub
End Class");
InvokeCodeActionList();
VerifyCodeAction("Change signature...", applyFix: false);
this.InvokeCodeActionList();
this.VerifyCodeAction("Change signature...", applyFix: false);
}
[Fact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
......@@ -48,12 +52,12 @@ End Sub
ChangeSignatureDialog.VerifyOpen();
ChangeSignatureDialog.ClickCancel();
ChangeSignatureDialog.VerifyClosed();
VerifyTextContains(@"
var actualText = Editor.GetText();
Assert.Contains(@"
Class C
Sub Method(a As Integer, b As String)
End Sub
End Class");
End Class", actualText);
}
[Fact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
......@@ -71,12 +75,12 @@ End Sub
ChangeSignatureDialog.ClickDownButton();
ChangeSignatureDialog.ClickOK();
ChangeSignatureDialog.VerifyClosed();
VerifyTextContains(@"
var actualText = Editor.GetText();
Assert.Contains(@"
Class C
Sub Method(b As String, a As Integer)
End Sub
End Class");
End Class", actualText);
}
[Fact, Trait(Traits.Feature, Traits.Features.ChangeSignature)]
......@@ -89,8 +93,8 @@ Sub TestMethod()
x.Method$$(0, ""str"", 3.0)
End Sub
End Class");
VisualStudio.Instance.SolutionExplorer.AddProject("CSharpProject", WellKnownProjectTemplates.ClassLibrary, LanguageNames.CSharp);
var csharpProject = new ProjectUtils.Project("CSharpProject");
this.AddProject(WellKnownProjectTemplates.ClassLibrary, csharpProject, LanguageNames.CSharp);
Editor.SetText(@"
public class CSharpClass
{
......@@ -106,11 +110,13 @@ public int Method(int a, string b, double c)
return 1;
}
}");
VisualStudio.Instance.SolutionExplorer.SaveAll();
VisualStudio.Instance.SolutionExplorer.AddProjectReference(ProjectName, "CSharpProject");
VisualStudio.Instance.SolutionExplorer.OpenFile(ProjectName, "Class1.vb");
this.SaveAll();
var project = new ProjectUtils.Project(ProjectName);
var csharpProjectReference = new ProjectUtils.ProjectReference("CSharpProject");
this.AddProjectReference(project, csharpProjectReference);
this.OpenFile("Class1.vb", project);
WaitForAsyncOperations(FeatureAttribute.Workspace);
this.WaitForAsyncOperations(FeatureAttribute.Workspace);
ChangeSignatureDialog.Invoke();
ChangeSignatureDialog.VerifyOpen();
......@@ -125,11 +131,11 @@ public int Method(int a, string b, double c)
ChangeSignatureDialog.ClickRestoreButton();
ChangeSignatureDialog.ClickOK();
ChangeSignatureDialog.VerifyClosed();
VerifyTextContains(@"x.Method(""str"")");
VisualStudio.Instance.SolutionExplorer.OpenFile("CSharpProject", "Class1.cs");
VerifyTextContains(@"
var actualText = Editor.GetText();
Assert.Contains(@"x.Method(""str"")", actualText);
this.OpenFile("Class1.cs", csharpProject);
actualText = Editor.GetText();
var expectedText = @"
public class CSharpClass
{
/// <summary>
......@@ -143,7 +149,8 @@ public int Method(string b)
{
return 1;
}
}");
}";
Assert.Contains(expectedText, actualText);
}
}
}
......@@ -3,6 +3,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.VisualBasic
......@@ -35,32 +36,32 @@ End Sub
End Class
End Namespace");
PlaceCaret("MathAlias");
VerifyCurrentTokenType(tokenType: "identifier");
PlaceCaret("Namespace");
VerifyCurrentTokenType(tokenType: "keyword");
PlaceCaret("summary");
VerifyCurrentTokenType(tokenType: "xml doc comment - name");
PlaceCaret("innertext");
VerifyCurrentTokenType(tokenType: "xml doc comment - text");
PlaceCaret("!--");
VerifyCurrentTokenType(tokenType: "xml doc comment - delimiter");
PlaceCaret("comment");
VerifyCurrentTokenType(tokenType: "xml doc comment - comment");
PlaceCaret("CDATA");
VerifyCurrentTokenType(tokenType: "xml doc comment - delimiter");
PlaceCaret("cdata");
VerifyCurrentTokenType(tokenType: "xml doc comment - cdata section");
PlaceCaret("attribute");
VerifyCurrentTokenType(tokenType: "identifier");
PlaceCaret("Class");
VerifyCurrentTokenType(tokenType: "keyword");
PlaceCaret("Program");
VerifyCurrentTokenType(tokenType: "class name");
PlaceCaret("Hello");
VerifyCurrentTokenType(tokenType: "string");
PlaceCaret("comment");
VerifyCurrentTokenType(tokenType: "comment");
this.PlaceCaret("MathAlias");
this.VerifyCurrentTokenType(tokenType: "identifier");
this.PlaceCaret("Namespace");
this.VerifyCurrentTokenType(tokenType: "keyword");
this.PlaceCaret("summary");
this.VerifyCurrentTokenType(tokenType: "xml doc comment - name");
this.PlaceCaret("innertext");
this.VerifyCurrentTokenType(tokenType: "xml doc comment - text");
this.PlaceCaret("!--");
this.VerifyCurrentTokenType(tokenType: "xml doc comment - delimiter");
this.PlaceCaret("comment");
this.VerifyCurrentTokenType(tokenType: "xml doc comment - comment");
this.PlaceCaret("CDATA");
this.VerifyCurrentTokenType(tokenType: "xml doc comment - delimiter");
this.PlaceCaret("cdata");
this.VerifyCurrentTokenType(tokenType: "xml doc comment - cdata section");
this.PlaceCaret("attribute");
this.VerifyCurrentTokenType(tokenType: "identifier");
this.PlaceCaret("Class");
this.VerifyCurrentTokenType(tokenType: "keyword");
this.PlaceCaret("Program");
this.VerifyCurrentTokenType(tokenType: "class name");
this.PlaceCaret("Hello");
this.VerifyCurrentTokenType(tokenType: "string");
this.PlaceCaret("comment");
this.VerifyCurrentTokenType(tokenType: "comment");
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -71,10 +72,10 @@ Imports System
Class Foo
Inherits Attribute
End Class");
PlaceCaret("Foo");
VerifyCurrentTokenType(tokenType: "class name");
PlaceCaret("Attribute");
VerifyCurrentTokenType(tokenType: "class name");
this.PlaceCaret("Foo");
this.VerifyCurrentTokenType(tokenType: "class name");
this.PlaceCaret("Attribute");
this.VerifyCurrentTokenType(tokenType: "class name");
}
}
}
// 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.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Common;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Roslyn.Test.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.VisualBasic
......@@ -34,7 +33,7 @@ End Sub
End Class
");
SendKeys(Shift(VirtualKey.F12));
this.SendKeys(Shift(VirtualKey.F12));
const string localReferencesCaption = "'local' references";
var results = VisualStudio.Instance.FindReferencesWindow.GetContents(localReferencesCaption);
......@@ -81,7 +80,7 @@ End Sub
End Class
");
SendKeys(Shift(VirtualKey.F12));
this.SendKeys(Shift(VirtualKey.F12));
const string alphaReferencesCaption = "'Alpha' references";
var results = VisualStudio.Instance.FindReferencesWindow.GetContents(alphaReferencesCaption);
......
......@@ -3,8 +3,9 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Roslyn.Test.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.VisualBasic
......@@ -33,11 +34,12 @@ Class C
$$
End Class");
InvokeCodeActionList();
VerifyCodeAction("Generate constructor...", applyFix: true, blockUntilComplete: false);
this.InvokeCodeActionList();
this.VerifyCodeAction("Generate constructor...", applyFix: true, blockUntilComplete: false);
VerifyDialog(isOpen: true);
Dialog_ClickCancel();
VerifyTextContains(
var actualText = Editor.GetText();
Assert.Contains(
@"
Class C
Dim i as Integer
......@@ -45,7 +47,7 @@ Class C
Dim k as Boolean
End Class");
End Class", actualText);
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateConstructorFromMembers)]
......@@ -61,12 +63,13 @@ Class C
$$
End Class");
InvokeCodeActionList();
VerifyCodeAction("Generate constructor...", applyFix: true, blockUntilComplete: false);
this.InvokeCodeActionList();
this.VerifyCodeAction("Generate constructor...", applyFix: true, blockUntilComplete: false);
VerifyDialog(isOpen: true);
Dialog_ClickOk();
WaitForAsyncOperations(FeatureAttribute.LightBulb);
VerifyTextContains(
this.WaitForAsyncOperations(FeatureAttribute.LightBulb);
var actualText = Editor.GetText();
Assert.Contains(
@"
Class C
Dim i as Integer
......@@ -78,7 +81,7 @@ Class C
Me.j = j
Me.k = k
End Sub
End Class");
End Class", actualText);
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateConstructorFromMembers)]
......@@ -94,14 +97,15 @@ Class C
$$
End Class");
InvokeCodeActionList();
VerifyCodeAction("Generate constructor...", applyFix: true, blockUntilComplete: false);
this.InvokeCodeActionList();
this.VerifyCodeAction("Generate constructor...", applyFix: true, blockUntilComplete: false);
VerifyDialog(isOpen: true);
Editor.DialogSendKeys(DialogName, "{TAB}");
PressDialogButton(DialogName, "Down");
this.PressDialogButton(DialogName, "Down");
Dialog_ClickOk();
WaitForAsyncOperations(FeatureAttribute.LightBulb);
VerifyTextContains(
this.WaitForAsyncOperations(FeatureAttribute.LightBulb);
var actualText = Editor.GetText();
Assert.Contains(
@"
Class C
Dim i as Integer
......@@ -113,7 +117,7 @@ Class C
Me.i = i
Me.k = k
End Sub
End Class");
End Class", actualText);
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateConstructorFromMembers)]
......@@ -129,14 +133,15 @@ Class C
$$
End Class");
InvokeCodeActionList();
VerifyCodeAction("Generate constructor...", applyFix: true, blockUntilComplete: false);
this.InvokeCodeActionList();
this.VerifyCodeAction("Generate constructor...", applyFix: true, blockUntilComplete: false);
VerifyDialog(isOpen: true);
Editor.DialogSendKeys(DialogName, "{TAB}");
Editor.DialogSendKeys(DialogName, " ");
Dialog_ClickOk();
WaitForAsyncOperations(FeatureAttribute.LightBulb);
VerifyTextContains(
this.WaitForAsyncOperations(FeatureAttribute.LightBulb);
var actualText = Editor.GetText();
Assert.Contains(
@"
Class C
Dim i as Integer
......@@ -147,16 +152,16 @@ Class C
Me.j = j
Me.k = k
End Sub
End Class");
End Class", actualText);
}
private void VerifyDialog(bool isOpen)
=> VerifyDialog(DialogName, isOpen);
=> this.VerifyDialog(DialogName, isOpen);
private void Dialog_ClickCancel()
=> PressDialogButton(DialogName, "CancelButton");
=> this.PressDialogButton(DialogName, "CancelButton");
private void Dialog_ClickOk()
=> PressDialogButton(DialogName, "OkButton");
=> this.PressDialogButton(DialogName, "OkButton");
}
}
\ No newline at end of file
......@@ -3,8 +3,9 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Roslyn.Test.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.VisualBasic
......@@ -33,19 +34,20 @@ Class C
$$
End Class");
InvokeCodeActionList();
VerifyCodeAction("Generate Equals(object)...", applyFix: true, blockUntilComplete: false);
this.InvokeCodeActionList();
this.VerifyCodeAction("Generate Equals(object)...", applyFix: true, blockUntilComplete: false);
VerifyDialog(isOpen: true);
Dialog_ClickCancel();
VerifyTextContains(
@"
var actualText = Editor.GetText();
var expectedText = @"
Class C
Dim i as Integer
Dim j as String
Dim k as Boolean
End Class");
End Class";
Assert.Contains(expectedText, actualText);
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)]
......@@ -62,13 +64,13 @@ Class C
$$
End Class");
InvokeCodeActionList();
VerifyCodeAction("Generate Equals(object)...", applyFix: true, blockUntilComplete: false);
this.InvokeCodeActionList();
this.VerifyCodeAction("Generate Equals(object)...", applyFix: true, blockUntilComplete: false);
VerifyDialog(isOpen: true);
Dialog_ClickOk();
WaitForAsyncOperations(FeatureAttribute.LightBulb);
VerifyTextContains(
@"
this.WaitForAsyncOperations(FeatureAttribute.LightBulb);
var actualText = Editor.GetText();
var expectedText = @"
Imports TestProj
Class C
......@@ -83,16 +85,17 @@ Class C
j = c.j AndAlso
k = c.k
End Function
End Class");
End Class";
Assert.Contains(expectedText, actualText);
}
private void VerifyDialog(bool isOpen)
=> VerifyDialog(DialogName, isOpen);
=> this.VerifyDialog(DialogName, isOpen);
private void Dialog_ClickCancel()
=> PressDialogButton(DialogName, "CancelButton");
=> this.PressDialogButton(DialogName, "CancelButton");
private void Dialog_ClickOk()
=> PressDialogButton(DialogName, "OkButton");
=> this.PressDialogButton(DialogName, "OkButton");
}
}
\ No newline at end of file
// 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.CodeAnalysis;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.OutOfProcess;
using Roslyn.Test.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.VisualBasic
......@@ -35,7 +35,7 @@ Sub Method()
End Sub
End Class
");
VerifyCodeAction("Generate new type...",
this.VerifyCodeAction("Generate new type...",
applyFix: true,
blockUntilComplete: false);
......@@ -46,23 +46,24 @@ End Class
GenerateTypeDialog.SetTargetFileToNewName("GenerateTypeTest.cs");
GenerateTypeDialog.ClickOK();
GenerateTypeDialog.VerifyClosed();
VerifyTextContains(@"Imports CSProj
var actualText = Editor.GetText();
Assert.Contains(@"Imports CSProj
Class C
Sub Method()
Dim _A As A
End Sub
End Class
");
", actualText);
VisualStudio.Instance.SolutionExplorer.OpenFile("CSProj", "GenerateTypeTest.cs");
VerifyTextContains(@"namespace CSProj
actualText = Editor.GetText();
Assert.Contains(@"namespace CSProj
{
public struct A
{
}
}");
}", actualText);
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateType)]
......@@ -76,7 +77,7 @@ End Sub
End Class
");
VerifyCodeAction("Generate new type...",
this.VerifyCodeAction("Generate new type...",
applyFix: true,
blockUntilComplete: false);
......@@ -88,20 +89,22 @@ End Class
GenerateTypeDialog.VerifyClosed();
VisualStudio.Instance.SolutionExplorer.OpenFile(ProjectName, "GenerateTypeTest.vb");
VerifyTextContains(@"Public Structure A
var actualText = Editor.GetText();
Assert.Contains(@"Public Structure A
End Structure
");
", actualText);
VisualStudio.Instance.SolutionExplorer.OpenFile(ProjectName, "Class1.vb");
VerifyTextContains(@"Class C
actualText = Editor.GetText();
Assert.Contains(@"Class C
Sub Method()
Dim _A As A
End Sub
End Class
");
", actualText);
}
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/17680"),
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/17680"),
Trait(Traits.Feature, Traits.Features.CodeActionsGenerateType)]
public void CheckFoldersPopulateComboBox()
{
......@@ -113,7 +116,7 @@ Sub Method()
End Sub
End Class
");
VerifyCodeAction("Generate new type...",
this.VerifyCodeAction("Generate new type...",
applyFix: true,
blockUntilComplete: false);
......
......@@ -4,6 +4,9 @@
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Roslyn.Test.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Options;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.VisualBasic
......@@ -28,12 +31,12 @@ Sub Main()
End Sub
End Module");
DisableSuggestionMode();
this.SetUseSuggestionMode(false);
SendKeys("dim q as lis(");
VerifyCompletionItemExists("Of");
this.SendKeys("dim q as lis(");
this.VerifyCompletionItemExists("Of");
VerifyTextContains(@"
this.VerifyTextContains(@"
Module Module1
Sub Main()
Dim q As List($$)
......@@ -41,11 +44,11 @@ End Sub
End Module",
assertCaretPosition: true);
SendKeys(
this.SendKeys(
VirtualKey.Down,
VirtualKey.Tab);
VerifyTextContains(@"
this.VerifyTextContains(@"
Module Module1
Sub Main()
Dim q As List(Of$$)
......@@ -53,12 +56,12 @@ End Sub
End Module",
assertCaretPosition: true);
SendKeys(" inte");
VerifyCompletionItemExists("Integer");
this.SendKeys(" inte");
this.VerifyCompletionItemExists("Integer");
SendKeys(')');
this.SendKeys(')');
VerifyTextContains(@"
this.VerifyTextContains(@"
Module Module1
Sub Main()
Dim q As List(Of Integer)$$
......@@ -66,9 +69,9 @@ End Sub
End Module",
assertCaretPosition: true);
SendKeys(Ctrl(VirtualKey.Z));
this.SendKeys(Ctrl(VirtualKey.Z));
VerifyTextContains(@"
this.VerifyTextContains(@"
Module Module1
Sub Main()
Dim q As List(Of inte)$$
......@@ -76,9 +79,9 @@ End Sub
End Module",
assertCaretPosition: true);
SendKeys(Ctrl(VirtualKey.Z));
this.SendKeys(Ctrl(VirtualKey.Z));
VerifyTextContains(@"
this.VerifyTextContains(@"
Module Module1
Sub Main()
Dim q As List(Of inte$$)
......@@ -86,9 +89,9 @@ End Sub
End Module",
assertCaretPosition: true);
SendKeys(Ctrl(VirtualKey.Z));
this.SendKeys(Ctrl(VirtualKey.Z));
VerifyTextContains(@"
this.VerifyTextContains(@"
Module Module1
Sub Main()
Dim q As List(Of$$)
......@@ -96,9 +99,9 @@ End Sub
End Module",
assertCaretPosition: true);
SendKeys(Ctrl(VirtualKey.Z));
this.SendKeys(Ctrl(VirtualKey.Z));
VerifyTextContains(@"
this.VerifyTextContains(@"
Module Module1
Sub Main()
Dim q As lis($$)
......@@ -106,9 +109,9 @@ End Sub
End Module",
assertCaretPosition: true);
SendKeys(Ctrl(VirtualKey.Z));
this.SendKeys(Ctrl(VirtualKey.Z));
VerifyTextContains(@"
this.VerifyTextContains(@"
Module Module1
Sub Main()
Dim q As lis($$
......@@ -127,49 +130,49 @@ Sub Main()
End Sub
End Module");
DisableSuggestionMode();
this.SetUseSuggestionMode(false);
SendKeys("dim");
VerifyCompletionItemExists("Dim", "ReDim");
this.SendKeys("dim");
this.VerifyCompletionItemExists("Dim", "ReDim");
SendKeys(' ');
VerifyCompletionListIsActive(expected: false);
this.SendKeys(' ');
Assert.Equal(false, Editor.IsCompletionActive());
SendKeys('i');
VerifyCompletionListIsActive(expected: false);
this.SendKeys('i');
Assert.Equal(false, Editor.IsCompletionActive());
SendKeys(' ');
VerifyCompletionItemExists("As");
this.SendKeys(' ');
this.VerifyCompletionItemExists("As");
SendKeys("a ");
SendKeys("intege");
VerifyCompletionItemExists("Integer", "UInteger");
this.SendKeys("a ");
this.SendKeys("intege");
this.VerifyCompletionItemExists("Integer", "UInteger");
SendKeys(' ');
VerifyCompletionListIsActive(expected: false);
this.SendKeys(' ');
Assert.Equal(false, Editor.IsCompletionActive());
SendKeys('=');
VerifyCompletionListIsActive(expected: true);
this.SendKeys('=');
Assert.Equal(true, Editor.IsCompletionActive());
SendKeys(' ');
VerifyCompletionListIsActive(expected: true);
this.SendKeys(' ');
Assert.Equal(true, Editor.IsCompletionActive());
SendKeys("fooo");
VerifyCompletionListIsActive(expected: false);
this.SendKeys("fooo");
Assert.Equal(false, Editor.IsCompletionActive());
SendKeys(' ');
VerifyCompletionListIsActive(expected: true);
this.SendKeys(' ');
Assert.Equal(true, Editor.IsCompletionActive());
SendKeys(VirtualKey.Backspace);
VerifyCompletionListIsActive(expected: false);
this.SendKeys(VirtualKey.Backspace);
Assert.Equal(false, Editor.IsCompletionActive());
SendKeys(VirtualKey.Backspace);
VerifyCompletionListIsActive(expected: true);
this.SendKeys(VirtualKey.Backspace);
Assert.Equal(true, Editor.IsCompletionActive());
SendKeys(
this.SendKeys(
VirtualKey.Left,
VirtualKey.Delete);
VerifyCompletionListIsActive(expected: true);
Assert.Equal(true, Editor.IsCompletionActive());
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
......@@ -182,19 +185,19 @@ Sub Main()
End Sub
End Module");
DisableSuggestionMode();
this.SetUseSuggestionMode(false);
SendKeys("dim q as ");
VerifyCompletionItemExists("_AppDomain");
this.SendKeys("dim q as ");
this.VerifyCompletionItemExists("_AppDomain");
SendKeys("'");
VerifyCompletionListIsActive(expected: false);
VerifyTextContains(@"Module Module1
this.SendKeys("'");
Assert.Equal(false, Editor.IsCompletionActive());
var actualText = Editor.GetText();
Assert.Contains(@"Module Module1
Sub Main()
Dim q As '
End Sub
End Module");
End Module", actualText);
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
......@@ -203,13 +206,13 @@ public void TypeLeftAngleAfterImports()
SetUpEditor(@"
Imports$$");
DisableSuggestionMode();
this.SetUseSuggestionMode(false);
SendKeys(' ');
VerifyCompletionItemExists("Microsoft", "System");
this.SendKeys(' ');
this.VerifyCompletionItemExists("Microsoft", "System");
SendKeys('<');
VerifyCompletionListIsActive(expected: false);
this.SendKeys('<');
Assert.Equal(false, Editor.IsCompletionActive());
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
......@@ -222,16 +225,16 @@ Module Module1
End Function
End Module");
DisableSuggestionMode();
this.SetUseSuggestionMode(false);
SendKeys('M');
VerifyCompletionItemExists("M");
this.SendKeys('M');
this.VerifyCompletionItemExists("M");
SendKeys("=v");
VerifyCompletionItemExists("val");
this.SendKeys("=v");
this.VerifyCompletionItemExists("val");
SendKeys(' ');
VerifyTextContains(@"
this.SendKeys(' ');
this.VerifyTextContains(@"
Module Module1
Function M(val As Integer) As Integer
M=val $$
......@@ -243,17 +246,17 @@ End Function
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public void CtrlAltSpaceOption()
{
DisableSuggestionMode();
this.SetUseSuggestionMode(false);
SendKeys("Nam Foo");
VerifyCurrentLineText("Namespace Foo$$", assertCaretPosition: true);
this.SendKeys("Nam Foo");
this.VerifyCurrentLineText("Namespace Foo$$", assertCaretPosition: true);
ClearEditor();
ExecuteCommand(WellKnownCommandNames.Edit_ToggleCompletionMode);
this.ExecuteCommand(WellKnownCommandNames.Edit_ToggleCompletionMode);
SendKeys("Nam Foo");
VerifyCurrentLineText("Nam Foo$$", assertCaretPosition: true);
this.SendKeys("Nam Foo");
this.VerifyCurrentLineText("Nam Foo$$", assertCaretPosition: true);
}
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
......@@ -269,15 +272,15 @@ End Interface
End Class");
DisableSuggestionMode();
this.SetUseSuggestionMode(false);
SendKeys(" UF");
VerifyCompletionItemExists("UFoo");
this.SendKeys(" UF");
this.VerifyCompletionItemExists("UFoo");
SendKeys(VirtualKey.Enter);
VerifyCompletionListIsActive(expected: false);
VerifyTextContains(@"
this.SendKeys(VirtualKey.Enter);
Assert.Equal(false, Editor.IsCompletionActive());
var actualText = Editor.GetText();
Assert.Contains(@"
Interface UFoo
Sub FooBar()
End Interface
......@@ -288,7 +291,7 @@ Implements UFoo
Public Sub FooBar() Implements UFoo.FooBar
Throw New NotImplementedException()
End Sub
End Class");
End Class", actualText);
}
}
}
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Shared.TestHooks;
// 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.CodeAnalysis;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Common;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Roslyn.Test.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Roslyn.VisualStudio.IntegrationTests.Extensions.SolutionExplorer;
using Xunit;
using ProjectUtils = Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils;
namespace Roslyn.VisualStudio.IntegrationTests.VisualBasic
{
......@@ -21,17 +23,18 @@ public BasicNavigateTo(VisualStudioInstanceFactory instanceFactory)
[Fact, Trait(Traits.Feature, Traits.Features.SignatureHelp)]
public void NavigateTo()
{
AddFile("test1.vb", open: false, contents: @"
var project = new ProjectUtils.Project(ProjectName);
this.AddFile("test1.vb", project: project, open: false, contents: @"
Class FirstClass
Sub FirstMethod()
End Sub
End Class");
AddFile("test2.vb", open: true, contents: @"
this.AddFile("test2.vb", project: project, open: true, contents: @"
");
InvokeNavigateToAndPressEnter("FirstMethod");
this.InvokeNavigateToAndPressEnter("FirstMethod");
Editor.WaitForActiveView("test1.vb");
Assert.Equal("FirstMethod", Editor.GetSelectedText());
......@@ -39,7 +42,7 @@ End Sub
VisualStudio.Instance.SolutionExplorer.AddProject("CSProject", WellKnownProjectTemplates.ClassLibrary, LanguageNames.CSharp);
VisualStudio.Instance.SolutionExplorer.AddFile("CSProject", "csfile.cs", open: true);
InvokeNavigateToAndPressEnter("FirstClass");
this.InvokeNavigateToAndPressEnter("FirstClass");
Editor.WaitForActiveView("test1.vb");
Assert.Equal("FirstClass", Editor.GetSelectedText());
}
......
using Microsoft.CodeAnalysis;
// 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.CodeAnalysis;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Common;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Roslyn.Test.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.VisualBasic
......@@ -26,9 +27,8 @@ Class Program
Sub Main(ByVal args As String$$())
End Sub
End Class");
InvokeQuickInfo();
Assert.Equal("Class\u200e System.String\r\nRepresents text as a sequence of UTF-16 code units.To browse the .NET Framework source code for this type, see the Reference Source.",
Editor.GetQuickInfo());
this.InvokeQuickInfo();
Assert.Equal("Class\u200e System.String\r\nRepresents text as a sequence of UTF-16 code units.To browse the .NET Framework source code for this type, see the Reference Source.", Editor.GetQuickInfo());
}
[Fact, Trait(Traits.Feature, Traits.Features.QuickInfo)]
......@@ -43,7 +43,7 @@ public void International()
Dim foo as العربية123$$
End Sub
End Class");
InvokeQuickInfo();
this.InvokeQuickInfo();
Assert.Equal(@"Class" + '\u200e' + @" TestProj.العربية123
This is an XML doc comment defined in code.", Editor.GetQuickInfo());
}
......
using Microsoft.CodeAnalysis;
// 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.CodeAnalysis;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Common;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Roslyn.Test.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.CSharp
......@@ -71,11 +73,11 @@ public void MethodSignatureHelp()
{
SetUpEditor(Baseline);
SendKeys("Dim m=Method(1,");
InvokeSignatureHelp();
VerifyCurrentSignature("C.Method(i As Integer, i2 As Integer) As C\r\nHello World 2.0!");
VerifyCurrentParameter("i2", "an integer, anything you like.");
VerifyParameters(
this.SendKeys("Dim m=Method(1,");
this.InvokeSignatureHelp();
this.VerifyCurrentSignature("C.Method(i As Integer, i2 As Integer) As C\r\nHello World 2.0!");
this.VerifyCurrentParameter("i2", "an integer, anything you like.");
this.VerifyParameters(
("i", "an integer, preferably 42."),
("i2", "an integer, anything you like."));
}
......@@ -85,12 +87,12 @@ public void GenericMethodSignatureHelp1()
{
SetUpEditor(Baseline);
SendKeys("Dim gm = GenericMethod");
SendKeys(VirtualKey.Escape);
SendKeys("(");
VerifyCurrentSignature("C.GenericMethod(Of T1)(i As T1) As C\r\nHello Generic World!");
VerifyCurrentParameter("i", "Param 1 of type T1");
VerifyParameters(
this.SendKeys("Dim gm = GenericMethod");
this.SendKeys(VirtualKey.Escape);
this.SendKeys("(");
this.VerifyCurrentSignature("C.GenericMethod(Of T1)(i As T1) As C\r\nHello Generic World!");
this.VerifyCurrentParameter("i", "Param 1 of type T1");
this.VerifyParameters(
("i", "Param 1 of type T1"));
}
......@@ -126,12 +128,12 @@ Return Nothing
End Function
End Class");
SendKeys("GenericMethod");
SendKeys(VirtualKey.Escape);
SendKeys("(Of ");
VerifyCurrentSignature("C(Of T, R).GenericMethod(Of T1)(i As T1)\r\nGeneric Method with 1 Type Param");
VerifyCurrentParameter("T1", "Type Parameter");
VerifyParameters(
this.SendKeys("GenericMethod");
this.SendKeys(VirtualKey.Escape);
this.SendKeys("(Of ");
this.VerifyCurrentSignature("C(Of T, R).GenericMethod(Of T1)(i As T1)\r\nGeneric Method with 1 Type Param");
this.VerifyCurrentParameter("T1", "Type Parameter");
this.VerifyParameters(
("T1", "Type Parameter"));
}
......@@ -154,10 +156,10 @@ Return Nothing
End Function
End Class");
InvokeSignatureHelp();
VerifyCurrentSignature("C.GenericMethod(Of T1, T2)(i As T1, i2 As T2) As C");
VerifyCurrentParameter("T2", "");
VerifyParameters(
this.InvokeSignatureHelp();
this.VerifyCurrentSignature("C.GenericMethod(Of T1, T2)(i As T1, i2 As T2) As C");
this.VerifyCurrentParameter("T2", "");
this.VerifyParameters(
("T1", ""),
("T2", ""));
}
......@@ -172,11 +174,11 @@ Sub Method(a As Integer, b As Integer)
End Sub
End Module");
SendKeys("Method(");
VerifyCurrentSignature("M.Method(a As Integer, b As Integer)");
VerifyCurrentParameter("a", "");
SendKeys("1, ");
VerifyCurrentParameter("b", "");
this.SendKeys("Method(");
this.VerifyCurrentSignature("M.Method(a As Integer, b As Integer)");
this.VerifyCurrentParameter("a", "");
this.SendKeys("1, ");
this.VerifyCurrentParameter("b", "");
}
[Fact, Trait(Traits.Feature, Traits.Features.SignatureHelp)]
......@@ -191,8 +193,8 @@ Sub Test()
End Sub
End Class");
SendKeys("Foo(");
VerifyCurrentSignature("C.Foo()");
this.SendKeys("Foo(");
this.VerifyCurrentSignature("C.Foo()");
Editor.SetText(@"
Class C
......@@ -206,10 +208,10 @@ public void JaggedMultidimensionalArray()
{
SetUpEditor(Baseline);
SendKeys("Dim op = OutAndParam(");
VerifyCurrentSignature("C.OutAndParam(ByRef strings As String()(,), ByRef outArr As String(), ParamArray d As Object)\r\nComplex Method Params");
VerifyCurrentParameter("strings", "Jagged MultiDimensional Array");
VerifyParameters(
this.SendKeys("Dim op = OutAndParam(");
this.VerifyCurrentSignature("C.OutAndParam(ByRef strings As String()(,), ByRef outArr As String(), ParamArray d As Object)\r\nComplex Method Params");
this.VerifyCurrentParameter("strings", "Jagged MultiDimensional Array");
this.VerifyParameters(
("strings", "Jagged MultiDimensional Array"),
("outArr", "Out Array"),
("d", "Dynamic and Params param"));
......
......@@ -4,7 +4,11 @@
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.Input;
using Roslyn.VisualStudio.IntegrationTests.Extensions;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Roslyn.VisualStudio.IntegrationTests.Extensions.SolutionExplorer;
using Xunit;
using ProjectUtils = Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils;
namespace Roslyn.VisualStudio.IntegrationTests.VisualBasic
{
......@@ -19,157 +23,177 @@ public BasicWinForms(VisualStudioInstanceFactory instanceFactory)
}
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void Test_My_IntelliSense()
public void TestMyIntelliSense()
{
OpenFile(ProjectName, "Form1.vb");
var project = new ProjectUtils.Project(ProjectName);
this.OpenFile("Form1.vb", project);
SetUpEditor(@"Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
$$
End Sub
End Class");
SendKeys("My.");
VerifyCompletionItemExists("Application");
VerifyCompletionItemExists("Computer");
VerifyCompletionItemExists("Forms");
VerifyCompletionItemExists("MySettings");
VerifyCompletionItemExists("Resources");
VerifyCompletionItemExists("Settings");
VerifyCompletionItemExists("User");
VerifyCompletionItemExists("WebServices");
VerifyCompletionItemDoesNotExist("Equals");
VerifyCompletionItemDoesNotExist("MyApplication");
this.SendKeys("My.");
this.VerifyCompletionItemExists("Application");
this.VerifyCompletionItemExists("Computer");
this.VerifyCompletionItemExists("Forms");
this.VerifyCompletionItemExists("MySettings");
this.VerifyCompletionItemExists("Resources");
this.VerifyCompletionItemExists("Settings");
this.VerifyCompletionItemExists("User");
this.VerifyCompletionItemExists("WebServices");
this.VerifyCompletionItemDoesNotExist("Equals");
this.VerifyCompletionItemDoesNotExist("MyApplication");
SendKeys("Forms.");
VerifyCompletionItemExists("Form1");
VerifyCompletionItemDoesNotExist("Equals");
VerifyCompletionItemDoesNotExist("GetHashCode");
VerifyCompletionItemDoesNotExist("ToString");
this.SendKeys("Forms.");
this.VerifyCompletionItemExists("Form1");
this.VerifyCompletionItemDoesNotExist("Equals");
this.VerifyCompletionItemDoesNotExist("GetHashCode");
this.VerifyCompletionItemDoesNotExist("ToString");
}
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void Add_Control()
public void AddControl()
{
OpenFileWithDesigner(ProjectName, "Form1.vb");
AddWinFormButton("SomeButton");
CloseFile(ProjectName, "Form1.vb", saveFile: true);
OpenFile(ProjectName, "Form1.Designer.vb");
VerifyTextContains(@"Me.SomeButton.Name = ""SomeButton""");
VerifyTextContains(@"Friend WithEvents SomeButton As Button");
var project = new ProjectUtils.Project(ProjectName);
this.OpenFileWithDesigner("Form1.vb", project);
this.AddWinFormButton("SomeButton");
this.CloseFile("Form1.vb", project, saveFile: true);
this.OpenFile("Form1.Designer.vb", project);
var actualText = Editor.GetText();
Assert.Contains(@"Me.SomeButton.Name = ""SomeButton""", actualText);
Assert.Contains(@"Friend WithEvents SomeButton As Button", actualText);
}
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void Change_Control_Property()
public void ChangeControlProperty()
{
OpenFileWithDesigner(ProjectName, "Form1.vb");
AddWinFormButton("SomeButton");
EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Text", propertyValue: "NewButtonText");
CloseFile(ProjectName, "Form1.vb", saveFile: true);
OpenFile(ProjectName, "Form1.Designer.vb");
VerifyTextContains(@"Me.SomeButton.Text = ""NewButtonText""");
var project = new ProjectUtils.Project(ProjectName);
this.OpenFileWithDesigner("Form1.vb", project);
this.AddWinFormButton("SomeButton");
this.EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Text", propertyValue: "NewButtonText");
this.CloseFile("Form1.vb", project, saveFile: true);
this.OpenFile("Form1.Designer.vb", project);
var actualText = Editor.GetText();
Assert.Contains(@"Me.SomeButton.Text = ""NewButtonText""", actualText);
}
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void Change_Control_Property_In_Code()
public void ChangeControlPropertyInCode()
{
OpenFileWithDesigner(ProjectName, "Form1.vb");
AddWinFormButton("SomeButton");
EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Text", propertyValue: "ButtonTextGoesHere");
var project = new ProjectUtils.Project(ProjectName);
this.OpenFileWithDesigner("Form1.vb", project);
this.AddWinFormButton("SomeButton");
this.EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Text", propertyValue: "ButtonTextGoesHere");
var expectedPropertyValue = "ButtonTextGoesHere";
var actualPropertyValue = GetWinFormButtonPropertyValue(buttonName: "SomeButton", propertyName: "Text");
var actualPropertyValue = this.GetWinFormButtonPropertyValue(buttonName: "SomeButton", propertyName: "Text");
Assert.Equal(expectedPropertyValue, actualPropertyValue);
CloseFile(ProjectName, "Form1.vb", saveFile: true);
this.CloseFile("Form1.vb", project, saveFile: true);
// Change the control's text in designer.vb code
OpenFile(ProjectName, "Form1.Designer.vb");
this.OpenFile("Form1.Designer.vb", project);
// Verify that the control's property was set correctly. The following text should appear in InitializeComponent().
VerifyTextContains(@"Me.SomeButton.Text = ""ButtonTextGoesHere""");
var actualText = Editor.GetText();
Assert.Contains(@"Me.SomeButton.Text = ""ButtonTextGoesHere""", actualText);
// Replace text property with something else
SelectTextInCurrentDocument(@"Me.SomeButton.Text = ""ButtonTextGoesHere""");
SendKeys(@"Me.SomeButton.Text = ""GibberishText""");
CloseFile(ProjectName, "Form1.Designer.vb", saveFile: true);
this.SelectTextInCurrentDocument(@"Me.SomeButton.Text = ""ButtonTextGoesHere""");
this.SendKeys(@"Me.SomeButton.Text = ""GibberishText""");
this.CloseFile("Form1.Designer.vb", project, saveFile: true);
// Verify that the control text has changed in the designer
OpenFileWithDesigner(ProjectName, "Form1.vb");
this.OpenFileWithDesigner("Form1.vb", project);
expectedPropertyValue = "GibberishText";
actualPropertyValue = GetWinFormButtonPropertyValue(buttonName: "SomeButton", propertyName: "Text");
actualPropertyValue = this.GetWinFormButtonPropertyValue(buttonName: "SomeButton", propertyName: "Text");
Assert.Equal(expectedPropertyValue, actualPropertyValue);
}
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void Add_Click_Handler()
public void AddClickHandler()
{
OpenFileWithDesigner(ProjectName, "Form1.vb");
AddWinFormButton("SomeButton");
EditWinFormsButtonEvent(buttonName: "SomeButton", eventName: "Click", eventHandlerName: "ExecuteWhenButtonClicked");
OpenFile(ProjectName, "Form1.vb");
VerifyTextContains(@"Private Sub ExecuteWhenButtonClicked(sender As Object, e As EventArgs) Handles SomeButton.Click");
SaveFile(ProjectName, "Form1.vb");
var project = new ProjectUtils.Project(ProjectName);
this.OpenFileWithDesigner("Form1.vb", project);
this.AddWinFormButton("SomeButton");
this.EditWinFormsButtonEvent(buttonName: "SomeButton", eventName: "Click", eventHandlerName: "ExecuteWhenButtonClicked");
this.OpenFile("Form1.vb", project);
var actualText = Editor.GetText();
Assert.Contains(@"Private Sub ExecuteWhenButtonClicked(sender As Object, e As EventArgs) Handles SomeButton.Click", actualText);
this.SaveFile("Form1.vb", project);
}
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void Rename_Control()
public void RenameControl()
{
OpenFileWithDesigner(ProjectName, "Form1.vb");
AddWinFormButton("SomeButton");
var project = new ProjectUtils.Project(ProjectName);
this.OpenFileWithDesigner("Form1.vb", project);
this.AddWinFormButton("SomeButton");
// Add some control properties and events
EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Text", propertyValue: "ButtonTextValue");
EditWinFormsButtonEvent(buttonName: "SomeButton", eventName: "Click", eventHandlerName: "SomeButtonHandler");
this.EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Text", propertyValue: "ButtonTextValue");
this.EditWinFormsButtonEvent(buttonName: "SomeButton", eventName: "Click", eventHandlerName: "SomeButtonHandler");
// Rename the control
EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Name", propertyValue: "SomeNewButton");
VerifyNoBuildErrors();
this.EditWinFormButtonProperty(buttonName: "SomeButton", propertyName: "Name", propertyValue: "SomeNewButton");
this.VerifyNoBuildErrors();
// Verify that the rename propagated in designer code
OpenFile(ProjectName, "Form1.Designer.vb");
VerifyTextContains(@"Me.SomeNewButton.Name = ""SomeNewButton""");
VerifyTextContains(@"Me.SomeNewButton.Text = ""ButtonTextValue""");
VerifyTextContains(@"Friend WithEvents SomeNewButton As Button");
this.OpenFile("Form1.Designer.vb", project);
var formDesignerActualText = Editor.GetText();
Assert.Contains(@"Me.SomeNewButton.Name = ""SomeNewButton""", formDesignerActualText);
Assert.Contains(@"Me.SomeNewButton.Text = ""ButtonTextValue""", formDesignerActualText);
Assert.Contains(@"Friend WithEvents SomeNewButton As Button", formDesignerActualText);
// Verify that the old button name goes away
VerifyTextDoesNotContain(@"Friend WithEvents SomeButton As Button");
OpenFile(ProjectName, "Form1.vb");
VerifyTextContains(@"Private Sub SomeButtonHandler(sender As Object, e As EventArgs) Handles SomeNewButton.Click");
var actualText = Editor.GetText();
Assert.DoesNotContain(@"Friend WithEvents SomeButton As Button", actualText);
this.OpenFile("Form1.vb", project);
var formActualText = Editor.GetText();
Assert.Contains(@"Private Sub SomeButtonHandler(sender As Object, e As EventArgs) Handles SomeNewButton.Click", formActualText);
// Rename control from the code behind file (bug 784595)
SelectTextInCurrentDocument(@"SomeNewButton");
ExecuteCommand("Refactor.Rename");
SendKeys("AnotherNewButton", VirtualKey.Enter);
VerifyTextContains(@"Private Sub SomeButtonHandler(sender As Object, e As EventArgs) Handles AnotherNewButton.Click");
this.SelectTextInCurrentDocument(@"SomeNewButton");
this.ExecuteCommand("Refactor.Rename");
this.SendKeys("AnotherNewButton", VirtualKey.Enter);
formActualText = Editor.GetText();
Assert.Contains(@"Private Sub SomeButtonHandler(sender As Object, e As EventArgs) Handles AnotherNewButton.Click", formActualText);
}
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void Remove_Event_Handler()
public void RemoveEventHandler()
{
OpenFileWithDesigner(ProjectName, "Form1.vb");
AddWinFormButton("SomeButton");
EditWinFormsButtonEvent(buttonName: "SomeButton", eventName: "Click", eventHandlerName: "FooHandler");
var project = new ProjectUtils.Project(ProjectName);
this.OpenFileWithDesigner("Form1.vb", project);
this.AddWinFormButton("SomeButton");
this.EditWinFormsButtonEvent(buttonName: "SomeButton", eventName: "Click", eventHandlerName: "FooHandler");
// Remove the event handler
EditWinFormsButtonEvent(buttonName: "SomeButton", eventName: "Click", eventHandlerName: "");
VerifyNoBuildErrors();
this.EditWinFormsButtonEvent(buttonName: "SomeButton", eventName: "Click", eventHandlerName: "");
this.VerifyNoBuildErrors();
// Verify that the handler is removed
OpenFile(ProjectName, "Form1.Designer.vb");
VerifyTextDoesNotContain(@"Private Sub FooHandler(sender As Object, e As EventArgs) Handles SomeButton.Click");
this.OpenFile("Form1.Designer.vb", project);
var actualText = Editor.GetText();
Assert.DoesNotContain(@"Private Sub FooHandler(sender As Object, e As EventArgs) Handles SomeButton.Click", actualText);
}
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void Change_Accessibility()
public void ChangeAccessibility()
{
OpenFileWithDesigner(ProjectName, "Form1.vb");
AddWinFormButton("SomeButton");
EditWinFormButtonProperty(
var project = new ProjectUtils.Project(ProjectName);
this.OpenFileWithDesigner("Form1.vb", project);
this.AddWinFormButton("SomeButton");
this.EditWinFormButtonProperty(
buttonName: "SomeButton",
propertyName: "Modifiers",
propertyTypeName: "System.CodeDom.MemberAttributes",
propertyValue: "Public");
VerifyNoBuildErrors();
OpenFile(ProjectName, "Form1.Designer.vb");
VerifyTextContains(@"Public WithEvents SomeButton As Button");
this.VerifyNoBuildErrors();
this.OpenFile("Form1.Designer.vb", project);
var actualText = Editor.GetText();
Assert.Contains(@"Public WithEvents SomeButton As Button", actualText);
}
[Fact, Trait(Traits.Feature, Traits.Features.WinForms)]
public void Delete_Control()
public void DeleteControl()
{
OpenFileWithDesigner(ProjectName, "Form1.vb");
AddWinFormButton("SomeButton");
DeleteWinFormButton("SomeButton");
VerifyNoBuildErrors();
OpenFile(ProjectName, "Form1.Designer.vb");
VerifyTextDoesNotContain(@"Me.SomeButton.Name = ""SomeButton""");
VerifyTextDoesNotContain(@"Friend WithEvents SomeButton As Button");
var project = new ProjectUtils.Project(ProjectName);
this.OpenFileWithDesigner("Form1.vb", project);
this.AddWinFormButton("SomeButton");
this.DeleteWinFormButton("SomeButton");
this.VerifyNoBuildErrors();
this.OpenFile("Form1.Designer.vb", project);
var actualText = Editor.GetText();
Assert.DoesNotContain(@"Me.SomeButton.Name = ""SomeButton""", actualText);
Assert.DoesNotContain(@"Friend WithEvents SomeButton As Button", actualText);
}
}
}
......@@ -40,6 +40,17 @@
<Compile Include="CSharp\CSharpSignatureHelp.cs" />
<Compile Include="CSharp\CSharpWinForms.cs" />
<Compile Include="CSharp\CSharpAddMissingReference.cs" />
<Compile Include="Extensions\CommonExtensions.cs" />
<Compile Include="Extensions\CommonExtensions.Verifiers.cs" />
<Compile Include="Extensions\EditorExtensions.cs" />
<Compile Include="Extensions\EditorExtensions.Verifiers.cs" />
<Compile Include="Extensions\InteractiveExtensions.cs" />
<Compile Include="Extensions\SolutionExplorerExtensions.Verifiers.cs" />
<Compile Include="Extensions\SolutionExplorerExtensions.cs" />
<Compile Include="Extensions\SetOptionsExtensions.cs" />
<Compile Include="Workspace\WorkspaceBase.cs" />
<Compile Include="Workspace\WorkspacesDesktop.cs" />
<Compile Include="Workspace\WorkspacesNetCore.cs" />
<Compile Include="SharedIntegrationHostFixture.cs" />
<Compile Include="VisualBasic\BasicAddMissingReference.cs" />
<Compile Include="VisualBasic\BasicAutomaticBraceCompletion.cs" />
......
// 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.CodeAnalysis;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Options;
using Roslyn.VisualStudio.IntegrationTests.Extensions.SolutionExplorer;
using Xunit;
using ProjectUtils = Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils;
namespace Roslyn.VisualStudio.IntegrationTests.Workspace
{
public abstract class WorkspaceBase : AbstractEditorTest
{
public WorkspaceBase(VisualStudioInstanceFactory instanceFactory, string projectTemplate)
: base(instanceFactory, nameof(WorkspaceBase), projectTemplate)
{
DefaultProjectTemplate = projectTemplate;
this.SetFullSolutionAnalysis(true);
}
protected override string LanguageName => LanguageNames.CSharp;
protected string DefaultProjectTemplate { get; }
public virtual void OpenCSharpThenVBSolution()
{
Editor.SetText(@"using System; class Program { Exception e; }");
this.PlaceCaret("Exception");
this.VerifyCurrentTokenType(tokenType: "class name");
this.CloseSolution();
this.CreateSolution(nameof(WorkspacesDesktop));
var testProj = new ProjectUtils.Project("TestProj");
this.AddProject(WellKnownProjectTemplates.ClassLibrary, project: testProj, languageName: LanguageNames.VisualBasic);
Editor.SetText(@"Imports System
Class Program
Private e As Exception
End Class");
this.PlaceCaret("Exception");
this.VerifyCurrentTokenType(tokenType: "class name");
}
public virtual void MetadataReference()
{
var windowsBase = new ProjectUtils.AssemblyReference("WindowsBase");
var project = new ProjectUtils.Project(ProjectName);
this.AddMetadataReference(windowsBase, project);
Editor.SetText("class C { System.Windows.Point p; }");
this.PlaceCaret("Point");
this.VerifyCurrentTokenType("struct name");
this.RemoveMetadataReference(windowsBase, project);
this.VerifyCurrentTokenType("identifier");
}
public virtual void ProjectReference()
{
var project = new ProjectUtils.Project(ProjectName);
var csProj2 = new ProjectUtils.Project("CSProj2");
this.AddProject(project: csProj2, projectTemplate: DefaultProjectTemplate, languageName: LanguageName);
var projectName = new ProjectUtils.ProjectReference(ProjectName);
this.AddProjectReference(fromProjectName: csProj2, toProjectName: projectName);
this.AddFile("Program.cs", project: project, open: true, contents: "public class Class1 { }");
this.AddFile("Program.cs", project: csProj2, open: true, contents: "public class Class2 { Class1 c; }");
this.OpenFile("Program.cs", project: csProj2);
this.PlaceCaret("Class1");
this.VerifyCurrentTokenType("class name");
this.RemoveProjectReference(projectReferenceName: projectName, projectName: csProj2);
this.VerifyCurrentTokenType("identifier");
}
public virtual void ProjectProperties()
{
Editor.SetText(@"Module Program
Sub Main()
Dim x = 42
M(x)
End Sub
Sub M(p As Integer)
End Sub
Sub M(p As Object)
End Sub
End Module");
this.PlaceCaret("(x)", charsOffset: -1);
this.SetQuickInfo(true);
var project = new ProjectUtils.Project(ProjectName);
this.SetOptionInfer(project, true);
this.InvokeQuickInfo();
Assert.Equal("Sub‎ Program.M‎(p‎ As‎ Integer‎)‎ ‎(‎+‎ 1‎ overload‎)", Editor.GetQuickInfo());
this.SetOptionInfer(project, false);
this.InvokeQuickInfo();
Assert.Equal("Sub‎ Program.M‎(p‎ As‎ Object‎)‎ ‎(‎+‎ 1‎ overload‎)", Editor.GetQuickInfo());
}
}
}
// 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.CodeAnalysis;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests.Workspace
{
[Collection(nameof(SharedIntegrationHostFixture))]
public class WorkspacesDesktop : WorkspaceBase
{
public WorkspacesDesktop(VisualStudioInstanceFactory instanceFactory)
: base(instanceFactory, WellKnownProjectTemplates.ClassLibrary)
{
}
[Fact, Trait(Traits.Feature, Traits.Features.Workspace)]
public override void OpenCSharpThenVBSolution()
{
base.OpenCSharpThenVBSolution();
}
[Fact, Trait(Traits.Feature, Traits.Features.Workspace)]
public override void MetadataReference()
{
base.MetadataReference();
}
[Fact, Trait(Traits.Feature, Traits.Features.Workspace)]
public override void ProjectReference()
{
base.ProjectReference();
}
[Fact, Trait(Traits.Feature, Traits.Features.Workspace)]
public override void ProjectProperties()
{
VisualStudio.Instance.SolutionExplorer.CreateSolution(nameof(WorkspacesDesktop));
VisualStudio.Instance.SolutionExplorer.AddProject(ProjectName, WellKnownProjectTemplates.ClassLibrary, LanguageNames.VisualBasic);
base.ProjectProperties();
}
}
}
// 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.CodeAnalysis;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions;
using Roslyn.VisualStudio.IntegrationTests.Extensions.SolutionExplorer;
using Xunit;
using ProjectUtils = Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils;
namespace Roslyn.VisualStudio.IntegrationTests.Workspace
{
[Collection(nameof(SharedIntegrationHostFixture))]
public class WorkspacesNetCore : WorkspaceBase
{
public WorkspacesNetCore(VisualStudioInstanceFactory instanceFactory)
: base(instanceFactory, WellKnownProjectTemplates.CSharpNetCoreClassLibrary)
{
}
[Fact(Skip = "https://github.com/dotnet/roslyn-project-system/issues/1825"), Trait(Traits.Feature, Traits.Features.Workspace)]
public override void OpenCSharpThenVBSolution()
{
base.OpenCSharpThenVBSolution();
}
[Fact(Skip = "https://github.com/dotnet/roslyn-project-system/issues/1826"), Trait(Traits.Feature, Traits.Features.Workspace)]
public override void MetadataReference()
{
var project = new ProjectUtils.Project(ProjectName);
this.EditProjectFile(project);
Editor.SetText(@"<Project Sdk=""Microsoft.NET.Sdk"">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
</Project>");
this.SaveAll();
this.WaitForAsyncOperations(FeatureAttribute.Workspace);
this.OpenFile("Class1.cs", project);
base.MetadataReference();
}
[Fact, Trait(Traits.Feature, Traits.Features.Workspace)]
public override void ProjectReference()
{
base.ProjectReference();
}
[Fact(Skip = "https://github.com/dotnet/roslyn-project-system/issues/1825"), Trait(Traits.Feature, Traits.Features.Workspace)]
public override void ProjectProperties()
{
VisualStudio.Instance.SolutionExplorer.CreateSolution(nameof(WorkspacesDesktop));
VisualStudio.Instance.SolutionExplorer.AddProject(ProjectName, WellKnownProjectTemplates.ClassLibrary, LanguageNames.VisualBasic);
base.ProjectProperties();
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils
{
public abstract class Identity
{
public string Name { get; protected set; }
}
public class Project : Identity
{
public Project(string name)
{
Name = name;
}
}
public class ProjectReference : Identity
{
public ProjectReference(string name)
{
Name = name;
}
}
public class AssemblyReference : Identity
{
public AssemblyReference(string name)
{
Name = name;
}
}
}
......@@ -9,6 +9,7 @@
using System.Text;
using System.Threading;
using System.Windows.Automation;
using System.Windows.Documents;
using System.Windows.Forms;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Editor.Implementation.Suggestions;
......@@ -18,6 +19,7 @@
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.TextManager.Interop;
using Roslyn.Hosting.Diagnostics.Waiters;
namespace Microsoft.VisualStudio.IntegrationTest.Utilities.InProcess
{
......
......@@ -59,6 +59,20 @@ public static SolutionExplorer_InProc Create()
};
}
public void AddMetadataReference(string assemblyName, string projectName)
{
var project = GetProject(projectName);
var vsproject = ((VSProject)project.Object);
vsproject.References.Add(assemblyName);
}
public void RemoveMetadataReference(string assemblyName, string projectName)
{
var project = GetProject(projectName);
var reference = ((VSProject)project.Object).References.Cast<Reference>().Where(x => x.Name == assemblyName).First();
reference.Remove();
}
public string DirectoryName => Path.GetDirectoryName(SolutionFileFullPath);
public string SolutionFileFullPath
......@@ -106,6 +120,22 @@ public string[] GetAssemblyReferences(string projectName)
return references;
}
public void EditProjectFile(string projectName)
{
var solutionExplorer = ((DTE2)GetDTE()).ToolWindows.SolutionExplorer;
solutionExplorer.Parent.Activate();
var rootHierarchyItems = solutionExplorer.UIHierarchyItems.Cast<EnvDTE.UIHierarchyItem>();
var solution = rootHierarchyItems.First();
var solutionHierarchyItems = solution.UIHierarchyItems.Cast<EnvDTE.UIHierarchyItem>();
var project = solutionHierarchyItems.Where(x => x.Name == projectName).FirstOrDefault();
if (project == null)
{
throw new ArgumentException($"Could not find project file, current hierarchy items '{string.Join(", ", rootHierarchyItems.Select(x => x.Name))}'");
}
project.Select(EnvDTE.vsUISelectionType.vsUISelectionTypeSelect);
ExecuteCommand("Project.EditProjectFile");
}
public string[] GetProjectReferences(string projectName)
{
var project = GetProject(projectName);
......@@ -171,6 +201,20 @@ public void AddProjectReference(string projectName, string projectToReferenceNam
((VSProject)project.Object).References.AddProject(projectToReference);
}
public void RemoveProjectReference(string projectName, string projectReferenceName)
{
var project = GetProject(projectName);
var vsproject = (VSProject)project.Object;
var references = vsproject.References.Cast<Reference>();
var reference = references.Where(x => x.ContainingProject != null && x.Name == projectReferenceName).FirstOrDefault();
if (reference == null)
{
var projectReference = references.Where(x => x.ContainingProject != null).Select(x => x.Name);
throw new ArgumentException($"reference to project {projectReferenceName} not found, references: '{string.Join(", ", projectReference)}'");
}
reference.Remove();
}
public void OpenSolution(string path, bool saveExistingSolutionIfExists = false)
{
var dte = GetDTE();
......@@ -179,7 +223,6 @@ public void OpenSolution(string path, bool saveExistingSolutionIfExists = false)
{
CloseSolution(saveExistingSolutionIfExists);
}
dte.Solution.Open(path);
_solution = (EnvDTE80.Solution2)dte.Solution;
......@@ -242,7 +285,10 @@ public void CleanUpOpenSolution()
// cleanup any folders after the solution is closed.
foreach (EnvDTE.Project project in dte.Solution.Projects)
{
directoriesToDelete.Add(Path.GetDirectoryName(project.FullName));
if (!string.IsNullOrEmpty(project.FullName))
{
directoriesToDelete.Add(Path.GetDirectoryName(project.FullName));
}
}
// Save the full path to the solution. This is so we can cleanup any folders after the solution is closed.
......
......@@ -42,6 +42,15 @@ public void AddProject(string projectName, string projectTemplate, string langua
public void AddProjectReference(string fromProjectName, string toProjectName)
=> _inProc.AddProjectReference(fromProjectName, toProjectName);
public void RemoveProjectReference(string projectName, string projectReferenceName)
=> _inProc.RemoveProjectReference(projectName, projectReferenceName);
public void AddMetadataReference(string assemblyName, string projectName)
=> _inProc.AddMetadataReference(assemblyName, projectName);
public void RemoveMetadataReference(string assemblyName, string projectName)
=> _inProc.RemoveMetadataReference(assemblyName, projectName);
public void CleanUpOpenSolution()
=> _inProc.CleanUpOpenSolution();
......@@ -98,5 +107,8 @@ public string[] GetProjectReferences(string projectName)
public string[] GetAssemblyReferences(string projectName)
=> _inProc.GetAssemblyReferences(projectName);
public void EditProjectFile(string projectName)
=> _inProc.EditProjectFile(projectName);
}
}
......@@ -27,6 +27,7 @@
<Compile Include="CaptureTestNameAttribute.cs" />
<Compile Include="Common\Comparison.cs" />
<Compile Include="Common\Parameter.cs" />
<Compile Include="Common\ProjectUtilities.cs" />
<Compile Include="Common\Reference.cs" />
<Compile Include="Common\Signature.cs" />
<Compile Include="Helper.cs" />
......
......@@ -10,5 +10,9 @@ public static class WellKnownProjectTemplates
public const string WinFormsApplication = nameof(WinFormsApplication);
public const string WpfApplication = nameof(WpfApplication);
public const string WebApplication = nameof(WebApplication);
public const string CSharpNetCoreClassLibrary = "Microsoft.CSharp.NETCore.ClassLibrary";
public const string VisualBasicNetCoreClassLibrary = "Microsoft.VisualBasic.NETCore.ClassLibrary";
public const string CSharpNetCoreConsoleApplication = "Microsoft.CSharp.NETCore.ConsoleApplication";
public const string VisualBasicNetCoreConsoleApplication = "Microsoft.VisualBasic.NETCore.ConsoleApplication";
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册