|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | + |
| 5 | +using System.Threading.Tasks; |
| 6 | +using Microsoft.CodeAnalysis; |
| 7 | +using Microsoft.CodeAnalysis.Shared.TestHooks; |
| 8 | +using Microsoft.VisualStudio.Extensibility.Testing; |
| 9 | +using Microsoft.VisualStudio.IntegrationTest.Utilities; |
| 10 | +using Microsoft.VisualStudio.LanguageServices.Implementation; |
| 11 | +using Roslyn.Utilities; |
| 12 | +using Roslyn.VisualStudio.IntegrationTests; |
| 13 | +using WindowsInput.Native; |
| 14 | +using Xunit; |
| 15 | + |
| 16 | +namespace Roslyn.VisualStudio.NewIntegrationTests.CSharp |
| 17 | +{ |
| 18 | + public class CSharpInheritanceMarginTests : AbstractEditorTest |
| 19 | + { |
| 20 | + protected override string LanguageName => LanguageNames.CSharp; |
| 21 | + |
| 22 | + public CSharpInheritanceMarginTests() |
| 23 | + : base(nameof(CSharpInheritanceMarginTests)) |
| 24 | + { |
| 25 | + } |
| 26 | + |
| 27 | + [IdeFact] |
| 28 | + public async Task TestNavigateInSource() |
| 29 | + { |
| 30 | + var project = ProjectName; |
| 31 | + await TestServices.InheritanceMargin.EnableOptionsAsync(LanguageName, cancellationToken: HangMitigatingCancellationToken); |
| 32 | + await TestServices.SolutionExplorer.AddFileAsync(project, "Test.cs", cancellationToken: HangMitigatingCancellationToken); |
| 33 | + await TestServices.SolutionExplorer.OpenFileAsync(project, "Test.cs", HangMitigatingCancellationToken); |
| 34 | + |
| 35 | + await TestServices.InheritanceMargin.SetTextAndEnsureGlyphsAppearAsync( |
| 36 | +@" |
| 37 | +interface IBar |
| 38 | +{ |
| 39 | +} |
| 40 | +
|
| 41 | +class Implementation : IBar |
| 42 | +{ |
| 43 | +}", expectedGlyphsNumberInMargin: 2, HangMitigatingCancellationToken); |
| 44 | + |
| 45 | + await TestServices.InheritanceMargin.ClickTheGlyphOnLine(2, HangMitigatingCancellationToken); |
| 46 | + |
| 47 | + // Move focus to menu item of 'IBar', the destination is targeting 'class Implementation' |
| 48 | + await TestServices.Input.SendWithoutActivateAsync(VirtualKeyCode.TAB); |
| 49 | + // Navigate to the destination |
| 50 | + await TestServices.Input.SendWithoutActivateAsync(VirtualKeyCode.RETURN); |
| 51 | + await TestServices.Workspace.WaitForAllAsyncOperationsAsync(new[] { FeatureAttribute.InheritanceMargin }, HangMitigatingCancellationToken); |
| 52 | + await TestServices.EditorVerifier.TextContainsAsync(@"class Implementation$$", assertCaretPosition: true); |
| 53 | + } |
| 54 | + |
| 55 | + [IdeFact] |
| 56 | + public async Task TestMultipleItemsOnSameLine() |
| 57 | + { |
| 58 | + var project = ProjectName; |
| 59 | + await TestServices.InheritanceMargin.EnableOptionsAsync(LanguageName, cancellationToken: HangMitigatingCancellationToken); |
| 60 | + await TestServices.SolutionExplorer.AddFileAsync(project, "Test.cs", cancellationToken: HangMitigatingCancellationToken); |
| 61 | + await TestServices.SolutionExplorer.OpenFileAsync(project, "Test.cs", HangMitigatingCancellationToken); |
| 62 | + |
| 63 | + await TestServices.InheritanceMargin.SetTextAndEnsureGlyphsAppearAsync( |
| 64 | +@" |
| 65 | +using System; |
| 66 | +interface IBar |
| 67 | +{ |
| 68 | + event EventHandler e1, e2; |
| 69 | +} |
| 70 | +
|
| 71 | +class Implementation : IBar |
| 72 | +{ |
| 73 | + public event EventHandler e1, e2; |
| 74 | +}", expectedGlyphsNumberInMargin: 4, HangMitigatingCancellationToken); |
| 75 | + |
| 76 | + await TestServices.InheritanceMargin.ClickTheGlyphOnLine(5, HangMitigatingCancellationToken); |
| 77 | + |
| 78 | + // The context menu contains two members, e1 and e2. |
| 79 | + // Move focus to menu item of 'event e1' |
| 80 | + await TestServices.Input.SendWithoutActivateAsync(VirtualKeyCode.TAB); |
| 81 | + // Expand the submenu |
| 82 | + await TestServices.Input.SendWithoutActivateAsync(VirtualKeyCode.RETURN); |
| 83 | + // Navigate to the implemention |
| 84 | + await TestServices.Input.SendWithoutActivateAsync(VirtualKeyCode.RETURN); |
| 85 | + await TestServices.Workspace.WaitForAllAsyncOperationsAsync(new[] { FeatureAttribute.InheritanceMargin }, HangMitigatingCancellationToken); |
| 86 | + await TestServices.EditorVerifier.TextContainsAsync(@"public event EventHandler e1$$, e2;", assertCaretPosition: true); |
| 87 | + } |
| 88 | + |
| 89 | + [IdeFact] |
| 90 | + public async Task TestNavigateToMetadata() |
| 91 | + { |
| 92 | + var project = ProjectName; |
| 93 | + await TestServices.InheritanceMargin.EnableOptionsAsync(LanguageName, cancellationToken: HangMitigatingCancellationToken); |
| 94 | + await TestServices.SolutionExplorer.AddFileAsync(project, "Test.cs", cancellationToken: HangMitigatingCancellationToken); |
| 95 | + await TestServices.SolutionExplorer.OpenFileAsync(project, "Test.cs", HangMitigatingCancellationToken); |
| 96 | + |
| 97 | + await TestServices.InheritanceMargin.SetTextAndEnsureGlyphsAppearAsync( |
| 98 | +@" |
| 99 | +using System.Collections; |
| 100 | +
|
| 101 | +class Implementation : IEnumerable |
| 102 | +{ |
| 103 | + public IEnumerator GetEnumerator() |
| 104 | + { |
| 105 | + throw new NotImplementedException(); |
| 106 | + } |
| 107 | +}", expectedGlyphsNumberInMargin: 2, HangMitigatingCancellationToken); |
| 108 | + |
| 109 | + await TestServices.InheritanceMargin.ClickTheGlyphOnLine(4, HangMitigatingCancellationToken); |
| 110 | + |
| 111 | + // Move focus to menu item of 'class Implementation' |
| 112 | + await TestServices.Input.SendWithoutActivateAsync(VirtualKeyCode.TAB); |
| 113 | + // Navigate to 'IEnumerable' |
| 114 | + await TestServices.Input.SendWithoutActivateAsync(VirtualKeyCode.RETURN); |
| 115 | + await TestServices.Workspace.WaitForAllAsyncOperationsAsync(new[] { FeatureAttribute.InheritanceMargin }, HangMitigatingCancellationToken); |
| 116 | + await TestServices.EditorVerifier.TextContainsAsync(@"public interface IEnumerable$$", assertCaretPosition: true); |
| 117 | + |
| 118 | + var document = await TestServices.Editor.GetActiveDocumentAsync(HangMitigatingCancellationToken); |
| 119 | + RoslynDebug.AssertNotNull(document); |
| 120 | + Assert.Equal(WorkspaceKind.MetadataAsSource, document.Project.Solution.Workspace.Kind); |
| 121 | + } |
| 122 | + |
| 123 | + [IdeFact] |
| 124 | + public async Task TestNavigateToDifferentProjects() |
| 125 | + { |
| 126 | + await TestServices.InheritanceMargin.EnableOptionsAsync(LanguageNames.CSharp, cancellationToken: HangMitigatingCancellationToken); |
| 127 | + await TestServices.InheritanceMargin.EnableOptionsAsync(LanguageNames.VisualBasic, cancellationToken: HangMitigatingCancellationToken); |
| 128 | + |
| 129 | + var csharpProjectName = ProjectName; |
| 130 | + var vbProjectName = "TestVBProject"; |
| 131 | + await TestServices.SolutionExplorer.AddProjectAsync( |
| 132 | + vbProjectName, WellKnownProjectTemplates.VisualBasicNetStandardClassLibrary, LanguageNames.VisualBasic, cancellationToken: HangMitigatingCancellationToken); |
| 133 | + await TestServices.SolutionExplorer.AddFileAsync(vbProjectName, "Test.vb", @" |
| 134 | +Namespace MyNs |
| 135 | + Public Interface IBar |
| 136 | + End Interface |
| 137 | +End Namespace"); |
| 138 | + |
| 139 | + await TestServices.SolutionExplorer.AddFileAsync(csharpProjectName, "Test.cs", cancellationToken: HangMitigatingCancellationToken); |
| 140 | + await TestServices.SolutionExplorer.AddProjectReferenceAsync(csharpProjectName, vbProjectName, cancellationToken: HangMitigatingCancellationToken); |
| 141 | + await TestServices.SolutionExplorer.OpenFileAsync(csharpProjectName, "Test.cs", HangMitigatingCancellationToken); |
| 142 | + |
| 143 | + await TestServices.InheritanceMargin.SetTextAndEnsureGlyphsAppearAsync( |
| 144 | +@" |
| 145 | +using TestVBProject.MyNs; |
| 146 | +
|
| 147 | +class Implementation : IBar |
| 148 | +{ |
| 149 | +}", expectedGlyphsNumberInMargin: 1, HangMitigatingCancellationToken); |
| 150 | + |
| 151 | + await TestServices.InheritanceMargin.ClickTheGlyphOnLine(4, HangMitigatingCancellationToken); |
| 152 | + |
| 153 | + // Move focus to menu item of 'class Implementation' |
| 154 | + await TestServices.Input.SendWithoutActivateAsync(VirtualKeyCode.TAB); |
| 155 | + // Navigate to 'IBar' |
| 156 | + await TestServices.Input.SendWithoutActivateAsync(VirtualKeyCode.RETURN); |
| 157 | + await TestServices.Workspace.WaitForAllAsyncOperationsAsync(new[] { FeatureAttribute.InheritanceMargin }, HangMitigatingCancellationToken); |
| 158 | + await TestServices.EditorVerifier.TextContainsAsync(@"Public Interface IBar$$", assertCaretPosition: true); |
| 159 | + |
| 160 | + var document = await TestServices.Editor.GetActiveDocumentAsync(HangMitigatingCancellationToken); |
| 161 | + RoslynDebug.AssertNotNull(document); |
| 162 | + Assert.NotEqual(WorkspaceKind.MetadataAsSource, document.Project.Solution.Workspace.Kind); |
| 163 | + } |
| 164 | + } |
| 165 | +} |
0 commit comments