Repository navigation
Add integration tests for Go To Definition #5983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
davidwengier
merged 10 commits into
dotnet:main
from
davidwengier:GoToDefnIntegrationTests
Jan 31, 2022
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cc0bef2
Add integration tests for Go To Definition
davidwengier f69b60a
Skip test
davidwengier 6e4075d
PR feedback
davidwengier c28eb0b
Run test only in VS versions that support it
davidwengier 099d205
Wait for components to be classified properly before running any test
davidwengier e5043c0
Merge remote-tracking branch 'upstream/main' into GoToDefnIntegration…
davidwengier 02ca60e
Post merge cleanup
davidwengier 6436cf0
Wait for current line text, rather than caret move
davidwengier c5782bd
Remove DTE
davidwengier 786bed5
Remove DTE
davidwengier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/Razor/test/Microsoft.VisualStudio.Razor.IntegrationTests/GoToDefinitionTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
|
||
| using System.Threading.Tasks; | ||
| using Microsoft.CodeAnalysis.Host; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.VisualStudio.Razor.IntegrationTests | ||
| { | ||
| public class GoToDefinitionTests : AbstractRazorEditorTest | ||
| { | ||
| [IdeFact] | ||
| public async Task GoToDefinition_MethodInSameFile() | ||
| { | ||
| // Open the file | ||
| await TestServices.SolutionExplorer.OpenFileAsync(BlazorProjectName, CounterRazorFile, HangMitigatingCancellationToken); | ||
|
|
||
| await TestServices.Editor.PlaceCaretAsync("IncrementCount", charsOffset: -1, HangMitigatingCancellationToken); | ||
|
|
||
| // Act | ||
| await TestServices.Editor.InvokeGoToDefinitionAsync(HangMitigatingCancellationToken); | ||
|
|
||
| // Assert | ||
| await TestServices.Editor.WaitForCurrentLineTextAsync("private void IncrementCount()", HangMitigatingCancellationToken); | ||
| } | ||
|
|
||
| [IdeFact] | ||
| public async Task GoToDefinition_CSharpClass() | ||
| { | ||
| // Open the file | ||
| await TestServices.SolutionExplorer.OpenFileAsync(BlazorProjectName, IndexRazorFile, HangMitigatingCancellationToken); | ||
|
|
||
| // Change text to refer back to Program class | ||
| await TestServices.Editor.SetTextAsync(@"<SurveyPrompt Title=""@nameof(Program)", HangMitigatingCancellationToken); | ||
| await TestServices.Editor.PlaceCaretAsync("Program", charsOffset: -1, HangMitigatingCancellationToken); | ||
|
|
||
| // Act | ||
| await TestServices.Editor.InvokeGoToDefinitionAsync(HangMitigatingCancellationToken); | ||
|
|
||
| // Assert | ||
| await TestServices.Editor.WaitForActiveWindowAsync("Program.cs", HangMitigatingCancellationToken); | ||
| } | ||
|
|
||
| [IdeFact] | ||
| public async Task GoToDefinition_Component() | ||
| { | ||
| // Open the file | ||
| await TestServices.SolutionExplorer.OpenFileAsync(BlazorProjectName, IndexRazorFile, HangMitigatingCancellationToken); | ||
|
|
||
| await TestServices.Editor.PlaceCaretAsync("SurveyPrompt", charsOffset: -1, HangMitigatingCancellationToken); | ||
|
|
||
| // Act | ||
| await TestServices.Editor.InvokeGoToDefinitionAsync(HangMitigatingCancellationToken); | ||
|
|
||
| // Assert | ||
| await TestServices.Editor.WaitForActiveWindowAsync("SurveyPrompt.razor", HangMitigatingCancellationToken); | ||
| } | ||
|
|
||
| [IdeFact] | ||
| public async Task GoToDefinition_ComponentAttribute() | ||
| { | ||
| var version = await TestServices.Shell.GetVersionAsync(HangMitigatingCancellationToken); | ||
| if (version < new System.Version(17, 1, 32113, 165)) | ||
| { | ||
| // Functionality under test was added in v17 Preview 3 (17.1.32113.165) so this test will | ||
| // file until CI is updated, so we'll skip it. | ||
| return; | ||
| } | ||
|
|
||
| // Open the file | ||
| await TestServices.SolutionExplorer.OpenFileAsync(BlazorProjectName, IndexRazorFile, HangMitigatingCancellationToken); | ||
|
|
||
| await TestServices.Editor.PlaceCaretAsync("Title=", charsOffset: -1, HangMitigatingCancellationToken); | ||
|
|
||
| // Act | ||
| await TestServices.Editor.InvokeGoToDefinitionAsync(HangMitigatingCancellationToken); | ||
|
|
||
| // Assert | ||
| await TestServices.Editor.WaitForActiveWindowAsync("SurveyPrompt.razor", HangMitigatingCancellationToken); | ||
| await TestServices.Editor.WaitForCurrentLineTextAsync("public string? Title { get; set; }", HangMitigatingCancellationToken); | ||
| } | ||
| } | ||
| } | ||
38 changes: 38 additions & 0 deletions
38
.../test/Microsoft.VisualStudio.Razor.IntegrationTests/InProcess/EditorInProcess_Commands.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.VisualStudio.OLE.Interop; | ||
| using Microsoft.VisualStudio.Shell.Interop; | ||
| using Microsoft.VisualStudio.Threading; | ||
| using static Microsoft.VisualStudio.VSConstants; | ||
|
|
||
| namespace Microsoft.VisualStudio.Extensibility.Testing | ||
| { | ||
| internal partial class EditorInProcess | ||
| { | ||
| public async Task InvokeGoToDefinitionAsync(CancellationToken cancellationToken) | ||
| { | ||
| var commandGuid = typeof(VSStd97CmdID).GUID; | ||
| var commandId = VSStd97CmdID.GotoDefn; | ||
| await ExecuteCommandAsync(commandGuid, (uint)commandId, cancellationToken); | ||
| } | ||
|
|
||
| public async Task CloseDocumentWindowAsync(CancellationToken cancellationToken) | ||
| { | ||
| var commandGuid = typeof(VSStd97CmdID).GUID; | ||
| var commandId = VSStd97CmdID.CloseDocument; | ||
| await ExecuteCommandAsync(commandGuid, (uint)commandId, cancellationToken); | ||
| } | ||
|
|
||
| private async Task ExecuteCommandAsync(Guid commandGuid, uint commandId, CancellationToken cancellationToken) | ||
| { | ||
| await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); | ||
|
|
||
| var dispatcher = await GetRequiredGlobalServiceAsync<SUIHostCommandDispatcher, IOleCommandTarget>(cancellationToken); | ||
| ErrorHandler.ThrowOnFailure(dispatcher.Exec(commandGuid, commandId, (uint)OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, IntPtr.Zero, IntPtr.Zero)); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed microsoft/vs-extension-testing#101. I think this'd be nice to have as part of the framework. Maybe instead of returning ("Success") we should do
Assert.Ignore("Wrong VS Version");so we know the test didn't really run.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I was looking for
Assert.Inconclusivebut didn't noticeIgnore.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. no Assert.Ignore in xUnit 😛