forked from dotnet/roslyn
/
CSharpGoToImplementation.cs
92 lines (84 loc) · 3.81 KB
/
CSharpGoToImplementation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// 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 Roslyn.Test.Utilities;
using Xunit;
using ProjectUtils = Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils;
namespace Roslyn.VisualStudio.IntegrationTests.CSharp
{
[Collection(nameof(SharedIntegrationHostFixture))]
public class CSharpGoToImplementation : AbstractEditorTest
{
protected override string LanguageName => LanguageNames.CSharp;
public CSharpGoToImplementation(VisualStudioInstanceFactory instanceFactory)
: base(instanceFactory, nameof(CSharpGoToImplementation))
{
}
[WpfFact, Trait(Traits.Feature, Traits.Features.GoToImplementation)]
public void SimpleGoToImplementation()
{
var project = new ProjectUtils.Project(ProjectName);
VisualStudio.SolutionExplorer.AddFile(project, "FileImplementation.cs");
VisualStudio.SolutionExplorer.OpenFile(project, "FileImplementation.cs");
VisualStudio.Editor.SetText(
@"class Implementation : IGoo
{
}");
VisualStudio.SolutionExplorer.AddFile(project, "FileInterface.cs");
VisualStudio.SolutionExplorer.OpenFile(project, "FileInterface.cs");
VisualStudio.Editor.SetText(
@"interface IGoo
{
}");
VisualStudio.Editor.PlaceCaret("interface IGoo");
VisualStudio.Editor.GoToImplementation();
VisualStudio.Editor.Verify.TextContains(@"class Implementation$$", assertCaretPosition: true);
Assert.False(VisualStudio.Shell.IsActiveTabProvisional());
}
[WpfFact, Trait(Traits.Feature, Traits.Features.GoToImplementation)]
public void GoToImplementationOpensProvisionalTabIfDocumentNotOpen()
{
var project = new ProjectUtils.Project(ProjectName);
VisualStudio.SolutionExplorer.AddFile(project, "FileImplementation.cs");
VisualStudio.SolutionExplorer.OpenFile(project, "FileImplementation.cs");
VisualStudio.Editor.SetText(
@"class Implementation : IBar
{
}
");
VisualStudio.SolutionExplorer.CloseCodeFile(project, "FileImplementation.cs", saveFile: true);
VisualStudio.SolutionExplorer.AddFile(project, "FileInterface.cs");
VisualStudio.SolutionExplorer.OpenFile(project, "FileInterface.cs");
VisualStudio.Editor.SetText(
@"interface IBar
{
}");
VisualStudio.Editor.PlaceCaret("interface IBar");
VisualStudio.Editor.GoToImplementation();
VisualStudio.Editor.Verify.TextContains(@"class Implementation$$", assertCaretPosition: true);
Assert.True(VisualStudio.Shell.IsActiveTabProvisional());
}
// TODO: Enable this once the GoToDefinition tests are merged
[WpfFact, Trait(Traits.Feature, Traits.Features.GoToImplementation)]
public void GoToImplementationFromMetadataAsSource()
{
var project = new ProjectUtils.Project(ProjectName);
VisualStudio.SolutionExplorer.AddFile(project, "FileImplementation.cs");
VisualStudio.SolutionExplorer.OpenFile(project, "FileImplementation.cs");
VisualStudio.Editor.SetText(
@"using System;
class Implementation : IDisposable
{
public void SomeMethod()
{
IDisposable d;
}
}");
VisualStudio.Editor.PlaceCaret("IDisposable d", charsOffset: -1);
VisualStudio.Editor.GoToDefinition();
VisualStudio.Editor.GoToImplementation();
VisualStudio.Editor.Verify.TextContains(@"class Implementation$$ : IDisposable", assertCaretPosition: true);
}
}
}