NavigateToTests.cs 40.4 KB
Newer Older
S
Sam Harwell 已提交
1
// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.
2 3 4

using System.Collections.Generic;
using System.Linq;
C
Cyrus Najmabadi 已提交
5
using System.Threading.Tasks;
6
using Microsoft.CodeAnalysis.Editor.Implementation.NavigateTo;
7
using Microsoft.CodeAnalysis.Editor.UnitTests;
8
using Microsoft.CodeAnalysis.Editor.UnitTests.NavigateTo;
9 10
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Shared.TestHooks;
11
using Microsoft.CodeAnalysis.Test.Utilities;
12
using Microsoft.VisualStudio.Composition;
13
using Microsoft.VisualStudio.Language.NavigateTo.Interfaces;
14
using Microsoft.VisualStudio.Text.PatternMatching;
15 16 17 18
using Roslyn.Test.EditorUtilities.NavigateTo;
using Roslyn.Test.Utilities;
using Xunit;

19
#pragma warning disable CS0618 // MatchKind is obsolete
20 21
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.NavigateTo
{
22
    public class NavigateToTests : AbstractNavigateToTests
23
    {
24
        protected override string Language => "csharp";
25

C
CyrusNajmabadi 已提交
26
        protected override TestWorkspace CreateWorkspace(string content, ExportProvider exportProvider)
C
CyrusNajmabadi 已提交
27
            => TestWorkspace.CreateCSharp(content, exportProvider: exportProvider);
28

29 30
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task NoItemsForEmptyFile()
31
        {
32
            await TestAsync("", async w =>
33
            {
34
                Assert.Empty(await _aggregator.GetItemsAsync("Hello"));
35
            });
36 37
        }

38 39
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindClass()
40
        {
C
CyrusNajmabadi 已提交
41
            await TestAsync(
42
@"class Goo
C
CyrusNajmabadi 已提交
43 44
{
}", async w =>
45
            {
46
                var item = (await _aggregator.GetItemsAsync("Goo")).Single(x => x.Kind != "Method");
47
                VerifyNavigateToResultItem(item, "Goo", "[|Goo|]", PatternMatchKind.Exact, NavigateToItemKind.Class, Glyph.ClassInternal);
48
            });
49 50
        }

51 52
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindVerbatimClass()
53
        {
C
CyrusNajmabadi 已提交
54 55 56 57
            await TestAsync(
@"class @static
{
}", async w =>
58
            {
59
                var item = (await _aggregator.GetItemsAsync("static")).Single(x => x.Kind != "Method");
60
                VerifyNavigateToResultItem(item, "static", "[|static|]", PatternMatchKind.Exact, NavigateToItemKind.Class, Glyph.ClassInternal);
61 62

                // Check searching for @static too
63
                item = (await _aggregator.GetItemsAsync("@static")).Single(x => x.Kind != "Method");
64
                VerifyNavigateToResultItem(item, "static", "[|static|]", PatternMatchKind.Exact, NavigateToItemKind.Class, Glyph.ClassInternal);
65
            });
66 67
        }

68 69
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindNestedClass()
70
        {
C
CyrusNajmabadi 已提交
71
            await TestAsync(
72
@"class Goo
C
CyrusNajmabadi 已提交
73 74 75 76 77 78 79 80
{
    class Bar
    {
        internal class DogBed
        {
        }
    }
}", async w =>
81
            {
82
                var item = (await _aggregator.GetItemsAsync("DogBed")).Single(x => x.Kind != "Method");
83
                VerifyNavigateToResultItem(item, "DogBed", "[|DogBed|]", PatternMatchKind.Exact, NavigateToItemKind.Class, Glyph.ClassInternal);
84
            });
85 86
        }

87 88
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindMemberInANestedClass()
89
        {
C
CyrusNajmabadi 已提交
90
            await TestAsync(
91
@"class Goo
C
CyrusNajmabadi 已提交
92
{
93
    class Bar 
C
CyrusNajmabadi 已提交
94 95 96 97 98 99 100 101 102
    {
        class DogBed
        {
            public void Method()
            {
            }
        }
    }
}", async w =>
103
            {
104
                var item = (await _aggregator.GetItemsAsync("Method")).Single();
105
                VerifyNavigateToResultItem(item, "Method", "[|Method|]()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPublic, string.Format(FeaturesResources.in_0_project_1, "Goo.Bar.DogBed", "Test"));
106
            });
107 108
        }

109 110
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindGenericClassWithConstraints()
111
        {
C
CyrusNajmabadi 已提交
112 113 114
            await TestAsync(
@"using System.Collections;

115
class Goo<T> where T : IEnumerable
C
CyrusNajmabadi 已提交
116 117
{
}", async w =>
118
            {
119
                var item = (await _aggregator.GetItemsAsync("Goo")).Single(x => x.Kind != "Method");
120
                VerifyNavigateToResultItem(item, "Goo", "[|Goo|]<T>", PatternMatchKind.Exact, NavigateToItemKind.Class, Glyph.ClassInternal);
121
            });
122 123
        }

124 125
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindGenericMethodWithConstraints()
126
        {
C
CyrusNajmabadi 已提交
127 128 129
            await TestAsync(
@"using System;

130
class Goo<U>
C
CyrusNajmabadi 已提交
131 132 133 134 135
{
    public void Bar<T>(T item) where T : IComparable<T>
    {
    }
}", async w =>
136
            {
137
                var item = (await _aggregator.GetItemsAsync("Bar")).Single();
138
                VerifyNavigateToResultItem(item, "Bar", "[|Bar|]<T>(T)", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPublic, string.Format(FeaturesResources.in_0_project_1, "Goo<U>", "Test"));
139
            });
140 141
        }

142 143
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindPartialClass()
144
        {
C
CyrusNajmabadi 已提交
145
            await TestAsync(
146
@"public partial class Goo
C
CyrusNajmabadi 已提交
147 148 149 150
{
    int a;
}

151
partial class Goo
C
CyrusNajmabadi 已提交
152 153 154
{
    int b;
}", async w =>
155
            {
156
                var expecteditem1 = new NavigateToItem("Goo", NavigateToItemKind.Class, "csharp", null, null, s_emptyExactPatternMatch, null);
157 158
                var expecteditems = new List<NavigateToItem> { expecteditem1, expecteditem1 };

159
                var items = await _aggregator.GetItemsAsync("Goo");
160 161

                VerifyNavigateToResultItems(expecteditems, items);
162
            });
163 164
        }

165 166
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindTypesInMetadata()
167
        {
C
CyrusNajmabadi 已提交
168 169 170 171
            await TestAsync(
@"using System;

Class Program { FileStyleUriParser f; }", async w =>
172
            {
173
                var items = await _aggregator.GetItemsAsync("FileStyleUriParser");
174
                Assert.Equal(items.Count(), 0);
175
            });
176 177
        }

178 179
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindClassInNamespace()
180
        {
C
CyrusNajmabadi 已提交
181 182 183
            await TestAsync(
@"namespace Bar
{
184
    class Goo
C
CyrusNajmabadi 已提交
185 186 187
    {
    }
}", async w =>
188
            {
189
                var item = (await _aggregator.GetItemsAsync("Goo")).Single(x => x.Kind != "Method");
190
                VerifyNavigateToResultItem(item, "Goo", "[|Goo|]", PatternMatchKind.Exact, NavigateToItemKind.Class, Glyph.ClassInternal);
191
            });
192 193
        }

194 195
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindStruct()
196
        {
C
CyrusNajmabadi 已提交
197 198 199 200
            await TestAsync(
@"struct Bar
{
}", async w =>
201
            {
202
                var item = (await _aggregator.GetItemsAsync("B")).Single(x => x.Kind != "Method");
203
                VerifyNavigateToResultItem(item, "Bar", "[|B|]ar", PatternMatchKind.Prefix, NavigateToItemKind.Structure, Glyph.StructureInternal);
204
            });
205 206
        }

207 208
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindEnum()
209
        {
C
CyrusNajmabadi 已提交
210 211 212 213 214 215 216
            await TestAsync(
@"enum Colors
{
    Red,
    Green,
    Blue
}", async w =>
217
            {
218
                var item = (await _aggregator.GetItemsAsync("Colors")).Single(x => x.Kind != "Method");
219
                VerifyNavigateToResultItem(item, "Colors", "[|Colors|]", PatternMatchKind.Exact, NavigateToItemKind.Enum, Glyph.EnumInternal);
220
            });
221 222
        }

223 224
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindEnumMember()
225
        {
C
CyrusNajmabadi 已提交
226 227 228 229 230 231 232
            await TestAsync(
@"enum Colors
{
    Red,
    Green,
    Blue
}", async w =>
233
            {
234
                var item = (await _aggregator.GetItemsAsync("R")).Single();
235
                VerifyNavigateToResultItem(item, "Red", "[|R|]ed", PatternMatchKind.Prefix, NavigateToItemKind.EnumItem, Glyph.EnumMemberPublic);
236
            });
237 238
        }

239 240
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindField1()
241
        {
C
CyrusNajmabadi 已提交
242
            await TestAsync(
243
@"class Goo
C
CyrusNajmabadi 已提交
244 245 246
{
    int bar;
}", async w =>
247
            {
248
                var item = (await _aggregator.GetItemsAsync("b")).Single();
249
                VerifyNavigateToResultItem(item, "bar", "[|b|]ar", PatternMatchKind.Prefix, NavigateToItemKind.Field, Glyph.FieldPrivate, additionalInfo: string.Format(FeaturesResources.in_0_project_1, "Goo", "Test"));
250
            });
251 252
        }

253 254
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindField2()
255
        {
C
CyrusNajmabadi 已提交
256
            await TestAsync(
257
@"class Goo
C
CyrusNajmabadi 已提交
258 259 260
{
    int bar;
}", async w =>
261
            {
262
                var item = (await _aggregator.GetItemsAsync("ba")).Single();
263
                VerifyNavigateToResultItem(item, "bar", "[|ba|]r", PatternMatchKind.Prefix, NavigateToItemKind.Field, Glyph.FieldPrivate, additionalInfo: string.Format(FeaturesResources.in_0_project_1, "Goo", "Test"));
264
            });
265 266
        }

267 268
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindField3()
269
        {
C
CyrusNajmabadi 已提交
270
            await TestAsync(
271
@"class Goo
C
CyrusNajmabadi 已提交
272 273 274
{
    int bar;
}", async w =>
275
            {
276
                Assert.Empty(await _aggregator.GetItemsAsync("ar"));
277
            });
278 279
        }

280 281
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindVerbatimField()
282
        {
C
CyrusNajmabadi 已提交
283
            await TestAsync(
284
@"class Goo
C
CyrusNajmabadi 已提交
285 286 287
{
    int @string;
}", async w =>
288
            {
289
                var item = (await _aggregator.GetItemsAsync("string")).Single();
290
                VerifyNavigateToResultItem(item, "string", "[|string|]", PatternMatchKind.Exact, NavigateToItemKind.Field, Glyph.FieldPrivate, additionalInfo: string.Format(FeaturesResources.in_0_project_1, "Goo", "Test"));
291 292

                // Check searching for@string too
293
                item = (await _aggregator.GetItemsAsync("@string")).Single();
294
                VerifyNavigateToResultItem(item, "string", "[|string|]", PatternMatchKind.Exact, NavigateToItemKind.Field, Glyph.FieldPrivate, additionalInfo: string.Format(FeaturesResources.in_0_project_1, "Goo", "Test"));
295
            });
296 297
        }

298 299
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindPtrField1()
300
        {
C
CyrusNajmabadi 已提交
301
            await TestAsync(
302
@"class Goo
C
CyrusNajmabadi 已提交
303 304 305
{
    int* bar;
}", async w =>
306
            {
307
                Assert.Empty(await _aggregator.GetItemsAsync("ar"));
308
            });
309 310
        }

311 312
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindPtrField2()
313
        {
C
CyrusNajmabadi 已提交
314
            await TestAsync(
315
@"class Goo
C
CyrusNajmabadi 已提交
316 317 318
{
    int* bar;
}", async w =>
319
            {
320
                var item = (await _aggregator.GetItemsAsync("b")).Single();
321
                VerifyNavigateToResultItem(item, "bar", "[|b|]ar", PatternMatchKind.Prefix, NavigateToItemKind.Field, Glyph.FieldPrivate);
322
            });
323 324
        }

325 326
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindConstField()
327
        {
C
CyrusNajmabadi 已提交
328
            await TestAsync(
329
@"class Goo
C
CyrusNajmabadi 已提交
330 331 332
{
    const int bar = 7;
}", async w =>
333
            {
334
                var item = (await _aggregator.GetItemsAsync("ba")).Single();
335
                VerifyNavigateToResultItem(item, "bar", "[|ba|]r", PatternMatchKind.Prefix, NavigateToItemKind.Constant, Glyph.ConstantPrivate);
336
            });
337 338
        }

339 340
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindIndexer()
341
        {
342
            var program = @"class Goo { int[] arr; public int this[int i] { get { return arr[i]; } set { arr[i] = value; } } }";
343
            await TestAsync(program, async w =>
344
            {
345
                var item = (await _aggregator.GetItemsAsync("this")).Single();
346
                VerifyNavigateToResultItem(item, "this", "[|this|][int]", PatternMatchKind.Exact, NavigateToItemKind.Property, Glyph.PropertyPublic, additionalInfo: string.Format(FeaturesResources.in_0_project_1, "Goo", "Test"));
347
            });
348 349
        }

350 351
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindEvent()
352
        {
353
            var program = "class Goo { public event EventHandler ChangedEventHandler; }";
354
            await TestAsync(program, async w =>
355
            {
356
                var item = (await _aggregator.GetItemsAsync("CEH")).Single();
357
                VerifyNavigateToResultItem(item, "ChangedEventHandler", "[|C|]hanged[|E|]vent[|H|]andler", PatternMatchKind.CamelCaseExact, NavigateToItemKind.Event, Glyph.EventPublic, additionalInfo: string.Format(FeaturesResources.in_0_project_1, "Goo", "Test"));
358
            });
359 360
        }

361 362
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindAutoProperty()
363
        {
C
CyrusNajmabadi 已提交
364
            await TestAsync(
365
@"class Goo
C
CyrusNajmabadi 已提交
366 367 368
{
    int Bar { get; set; }
}", async w =>
369
            {
370
                var item = (await _aggregator.GetItemsAsync("B")).Single();
371
                VerifyNavigateToResultItem(item, "Bar", "[|B|]ar", PatternMatchKind.Prefix, NavigateToItemKind.Property, Glyph.PropertyPrivate, additionalInfo: string.Format(FeaturesResources.in_0_project_1, "Goo", "Test"));
372
            });
373 374
        }

375 376
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindMethod()
377
        {
C
CyrusNajmabadi 已提交
378
            await TestAsync(
379
@"class Goo
C
CyrusNajmabadi 已提交
380 381 382
{
    void DoSomething();
}", async w =>
383
            {
384
                var item = (await _aggregator.GetItemsAsync("DS")).Single();
385
                VerifyNavigateToResultItem(item, "DoSomething", "[|D|]o[|S|]omething()", PatternMatchKind.CamelCaseExact, NavigateToItemKind.Method, Glyph.MethodPrivate, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test"));
386
            });
387 388
        }

389 390
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindVerbatimMethod()
391
        {
C
CyrusNajmabadi 已提交
392
            await TestAsync(
393
@"class Goo
C
CyrusNajmabadi 已提交
394 395 396
{
    void @static();
}", async w =>
397
            {
398
                var item = (await _aggregator.GetItemsAsync("static")).Single();
399
                VerifyNavigateToResultItem(item, "static", "[|static|]()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPrivate, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test"));
400 401

                // Verify if we search for @static too
402
                item = (await _aggregator.GetItemsAsync("@static")).Single();
403
                VerifyNavigateToResultItem(item, "static", "[|static|]()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPrivate, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test"));
404
            });
405 406
        }

407 408
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindParameterizedMethod()
409
        {
C
CyrusNajmabadi 已提交
410
            await TestAsync(
411
@"class Goo
C
CyrusNajmabadi 已提交
412 413 414 415 416
{
    void DoSomething(int a, string b)
    {
    }
}", async w =>
417
            {
418
                var item = (await _aggregator.GetItemsAsync("DS")).Single();
419
                VerifyNavigateToResultItem(item, "DoSomething", "[|D|]o[|S|]omething(int, string)", PatternMatchKind.CamelCaseExact, NavigateToItemKind.Method, Glyph.MethodPrivate, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test"));
420
            });
421 422
        }

423 424
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindConstructor()
425
        {
C
CyrusNajmabadi 已提交
426
            await TestAsync(
427
@"class Goo
C
CyrusNajmabadi 已提交
428
{
429
    public Goo()
C
CyrusNajmabadi 已提交
430 431 432
    {
    }
}", async w =>
433
            {
434
                var item = (await _aggregator.GetItemsAsync("Goo")).Single(t => t.Kind == NavigateToItemKind.Method);
435
                VerifyNavigateToResultItem(item, "Goo", "[|Goo|]()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPublic, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test"));
436
            });
437 438
        }

439 440
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindParameterizedConstructor()
441
        {
C
CyrusNajmabadi 已提交
442
            await TestAsync(
443
@"class Goo
C
CyrusNajmabadi 已提交
444
{
445
    public Goo(int i)
C
CyrusNajmabadi 已提交
446 447 448
    {
    }
}", async w =>
449
            {
450
                var item = (await _aggregator.GetItemsAsync("Goo")).Single(t => t.Kind == NavigateToItemKind.Method);
451
                VerifyNavigateToResultItem(item, "Goo", "[|Goo|](int)", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPublic, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test"));
452
            });
453 454
        }

455 456
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindStaticConstructor()
457
        {
C
CyrusNajmabadi 已提交
458
            await TestAsync(
459
@"class Goo
C
CyrusNajmabadi 已提交
460
{
461
    static Goo()
C
CyrusNajmabadi 已提交
462 463 464
    {
    }
}", async w =>
465
            {
466
                var item = (await _aggregator.GetItemsAsync("Goo")).Single(t => t.Kind == NavigateToItemKind.Method && t.Name != ".ctor");
467
                VerifyNavigateToResultItem(item, "Goo", "[|Goo|].static Goo()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPrivate, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test"));
468
            });
469 470
        }

471 472
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindPartialMethods()
473
        {
474
            await TestAsync("partial class Goo { partial void Bar(); } partial class Goo { partial void Bar() { Console.Write(\"hello\"); } }", async w =>
475
            {
476
                var expecteditem1 = new NavigateToItem("Bar", NavigateToItemKind.Method, "csharp", null, null, s_emptyExactPatternMatch, null);
477 478
                var expecteditems = new List<NavigateToItem> { expecteditem1, expecteditem1 };

479
                var items = await _aggregator.GetItemsAsync("Bar");
480 481

                VerifyNavigateToResultItems(expecteditems, items);
482
            });
483 484
        }

485 486
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindPartialMethodDefinitionOnly()
487
        {
C
CyrusNajmabadi 已提交
488
            await TestAsync(
489
@"partial class Goo
C
CyrusNajmabadi 已提交
490 491 492
{
    partial void Bar();
}", async w =>
493
            {
494
                var item = (await _aggregator.GetItemsAsync("Bar")).Single();
495
                VerifyNavigateToResultItem(item, "Bar", "[|Bar|]()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPrivate, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test"));
496
            });
497 498
        }

499 500
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindPartialMethodImplementationOnly()
501
        {
C
CyrusNajmabadi 已提交
502
            await TestAsync(
503
@"partial class Goo
C
CyrusNajmabadi 已提交
504 505 506 507 508
{
    partial void Bar()
    {
    }
}", async w =>
509
            {
510
                var item = (await _aggregator.GetItemsAsync("Bar")).Single();
511
                VerifyNavigateToResultItem(item, "Bar", "[|Bar|]()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPrivate, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test"));
512
            });
513 514
        }

515 516
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindOverriddenMembers()
517
        {
518
            var program = "class Goo { public virtual string Name { get; set; } } class DogBed : Goo { public override string Name { get { return base.Name; } set {} } }";
519
            await TestAsync(program, async w =>
520
            {
521
                var expecteditem1 = new NavigateToItem("Name", NavigateToItemKind.Property, "csharp", null, null, s_emptyExactPatternMatch, null);
522 523
                var expecteditems = new List<NavigateToItem> { expecteditem1, expecteditem1 };

524
                var items = await _aggregator.GetItemsAsync("Name");
525 526 527 528 529 530 531 532

                VerifyNavigateToResultItems(expecteditems, items);

                var item = items.ElementAt(0);
                var itemDisplay = item.DisplayFactory.CreateItemDisplay(item);
                var unused = itemDisplay.Glyph;

                Assert.Equal("Name", itemDisplay.Name);
C
CyrusNajmabadi 已提交
533
                Assert.Equal(string.Format(FeaturesResources.in_0_project_1, "DogBed", "Test"), itemDisplay.AdditionalInformation);
534 535 536 537 538 539

                item = items.ElementAt(1);
                itemDisplay = item.DisplayFactory.CreateItemDisplay(item);
                unused = itemDisplay.Glyph;

                Assert.Equal("Name", itemDisplay.Name);
540
                Assert.Equal(string.Format(FeaturesResources.in_0_project_1, "Goo", "Test"), itemDisplay.AdditionalInformation);
541
            });
542 543
        }

544 545
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindInterface()
546
        {
C
CyrusNajmabadi 已提交
547
            await TestAsync(
548
@"public interface IGoo
C
CyrusNajmabadi 已提交
549 550
{
}", async w =>
551
            {
552
                var item = (await _aggregator.GetItemsAsync("IG")).Single();
553
                VerifyNavigateToResultItem(item, "IGoo", "[|IG|]oo", PatternMatchKind.Prefix, NavigateToItemKind.Interface, Glyph.InterfacePublic);
554
            });
555 556
        }

557 558
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindDelegateInNamespace()
559
        {
C
CyrusNajmabadi 已提交
560
            await TestAsync(
561
@"namespace Goo
C
CyrusNajmabadi 已提交
562 563 564
{
    delegate void DoStuff();
}", async w =>
565
            {
566
                var item = (await _aggregator.GetItemsAsync("DoStuff")).Single(x => x.Kind != "Method");
567
                VerifyNavigateToResultItem(item, "DoStuff", "[|DoStuff|]", PatternMatchKind.Exact, NavigateToItemKind.Delegate, Glyph.DelegateInternal);
568
            });
569 570
        }

571 572
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindLambdaExpression()
573
        {
C
CyrusNajmabadi 已提交
574 575 576
            await TestAsync(
@"using System;

577
class Goo
C
CyrusNajmabadi 已提交
578 579 580
{
    Func<int, int> sqr = x => x * x;
}", async w =>
581
            {
582
                var item = (await _aggregator.GetItemsAsync("sqr")).Single();
583
                VerifyNavigateToResultItem(item, "sqr", "[|sqr|]", PatternMatchKind.Exact, NavigateToItemKind.Field, Glyph.FieldPrivate, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test"));
584
            });
585 586
        }

587 588
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindArray()
589
        {
C
CyrusNajmabadi 已提交
590
            await TestAsync(
591
@"class Goo
C
CyrusNajmabadi 已提交
592 593 594
{
    object[] itemArray;
}", async w =>
595
            {
596
                var item = (await _aggregator.GetItemsAsync("itemArray")).Single();
597
                VerifyNavigateToResultItem(item, "itemArray", "[|itemArray|]", PatternMatchKind.Exact, NavigateToItemKind.Field, Glyph.FieldPrivate, string.Format(FeaturesResources.in_0_project_1, "Goo", "Test"));
598
            });
599 600
        }

601 602
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindClassAndMethodWithSameName()
603
        {
C
CyrusNajmabadi 已提交
604
            await TestAsync(
605
@"class Goo
C
CyrusNajmabadi 已提交
606 607 608 609 610
{
}

class Test
{
611
    void Goo()
C
CyrusNajmabadi 已提交
612 613 614
    {
    }
}", async w =>
615 616 617
            {
                var expectedItems = new List<NavigateToItem>
                {
618 619
                    new NavigateToItem("Goo", NavigateToItemKind.Method, "csharp", "Goo", null, s_emptyExactPatternMatch, null),
                    new NavigateToItem("Goo", NavigateToItemKind.Class, "csharp", "Goo", null, s_emptyExactPatternMatch, null)
620
                };
621
                var items = await _aggregator.GetItemsAsync("Goo");
622
                VerifyNavigateToResultItems(expectedItems, items);
623
            });
624 625
        }

626 627
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindMethodNestedInGenericTypes()
628
        {
C
CyrusNajmabadi 已提交
629 630 631 632 633 634 635 636 637 638 639 640 641
            await TestAsync(
@"class A<T>
{
    class B
    {
        struct C<U>
        {
            void M()
            {
            }
        }
    }
}", async w =>
642
            {
643
                var item = (await _aggregator.GetItemsAsync("M")).Single();
644
                VerifyNavigateToResultItem(item, "M", "[|M|]()", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPrivate, additionalInfo: string.Format(FeaturesResources.in_0_project_1, "A<T>.B.C<U>", "Test"));
645
            });
646 647
        }

648 649
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task OrderingOfConstructorsAndTypes()
650
        {
C
CyrusNajmabadi 已提交
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
            await TestAsync(
@"class C1
{
    C1(int i)
    {
    }
}

class C2
{
    C2(float f)
    {
    }

    static C2()
    {
    }
}", async w =>
669 670 671
            {
                var expecteditems = new List<NavigateToItem>
                {
672 673 674 675 676
                    new NavigateToItem("C1", NavigateToItemKind.Class, "csharp", "C1", null, s_emptyPrefixPatternMatch, null),
                    new NavigateToItem("C1", NavigateToItemKind.Method, "csharp", "C1", null, s_emptyPrefixPatternMatch, null),
                    new NavigateToItem("C2", NavigateToItemKind.Class, "csharp", "C2", null, s_emptyPrefixPatternMatch, null),
                    new NavigateToItem("C2", NavigateToItemKind.Method, "csharp", "C2", null, s_emptyPrefixPatternMatch, null), // this is the static ctor
                    new NavigateToItem("C2", NavigateToItemKind.Method, "csharp", "C2", null, s_emptyPrefixPatternMatch, null),
677
                };
678
                var items = (await _aggregator.GetItemsAsync("C")).ToList();
679 680
                items.Sort(CompareNavigateToItems);
                VerifyNavigateToResultItems(expecteditems, items);
681
            });
682 683
        }

684 685
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task NavigateToMethodWithNullableParameter()
686
        {
C
CyrusNajmabadi 已提交
687 688 689 690 691 692 693
            await TestAsync(
@"class C
{
    void M(object? o)
    {
    }
}", async w =>
694
            {
695
                var item = (await _aggregator.GetItemsAsync("M")).Single();
696
                VerifyNavigateToResultItem(item, "M", "[|M|](object?)", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPrivate);
697
            });
698 699
        }

700 701
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task StartStopSanity()
702 703
        {
            // Verify that multiple calls to start/stop and dispose don't blow up
C
CyrusNajmabadi 已提交
704
            await TestAsync(
705
@"public class Goo
C
CyrusNajmabadi 已提交
706 707
{
}", async w =>
708 709
            {
                // Do one set of queries
710
                Assert.Single((await _aggregator.GetItemsAsync("Goo")).Where(x => x.Kind != "Method"));
711 712 713
                _provider.StopSearch();

                // Do the same query again, make sure nothing was left over
714
                Assert.Single((await _aggregator.GetItemsAsync("Goo")).Where(x => x.Kind != "Method"));
715 716 717 718
                _provider.StopSearch();

                // Dispose the provider
                _provider.Dispose();
719
            });
720 721
        }

722 723
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task DescriptionItems()
724
        {
725
            await TestAsync("public\r\nclass\r\nGoo\r\n{ }", async w =>
726
            {
727
                var item = (await _aggregator.GetItemsAsync("G")).Single(x => x.Kind != "Method");
728 729 730 731
                var itemDisplay = item.DisplayFactory.CreateItemDisplay(item);

                var descriptionItems = itemDisplay.DescriptionItems;

C
CyrusNajmabadi 已提交
732
                void assertDescription(string label, string value)
733 734 735
                {
                    var descriptionItem = descriptionItems.Single(i => i.Category.Single().Text == label);
                    Assert.Equal(value, descriptionItem.Details.Single().Text);
C
CyrusNajmabadi 已提交
736
                }
737

738
                assertDescription("File:", w.Documents.Single().Name);
739 740
                assertDescription("Line:", "3"); // one based line number
                assertDescription("Project:", "Test");
741
            });
742 743
        }

744 745
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task TermSplittingTest1()
746 747
        {
            var source = "class SyllableBreaking {int GetKeyWord; int get_key_word; string get_keyword; int getkeyword; int wake;}";
748
            await TestAsync(source, async w =>
749
            {
750 751 752
                var expecteditem1 = new NavigateToItem("get_keyword", NavigateToItemKind.Field, "csharp", null, null, s_emptyCamelCaseNonContiguousPrefixPatternMatch_NotCaseSensitive, null);
                var expecteditem2 = new NavigateToItem("get_key_word", NavigateToItemKind.Field, "csharp", null, null, s_emptyCamelCaseNonContiguousPrefixPatternMatch_NotCaseSensitive, null);
                var expecteditem3 = new NavigateToItem("GetKeyWord", NavigateToItemKind.Field, "csharp", null, null, s_emptyCamelCasePrefixPatternMatch, null);
753 754
                var expecteditems = new List<NavigateToItem> { expecteditem1, expecteditem2, expecteditem3 };

755
                var items = await _aggregator.GetItemsAsync("GK");
756 757 758 759

                Assert.Equal(expecteditems.Count(), items.Count());

                VerifyNavigateToResultItems(expecteditems, items);
760
            });
761 762
        }

763 764
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task TermSplittingTest2()
765 766
        {
            var source = "class SyllableBreaking {int GetKeyWord; int get_key_word; string get_keyword; int getkeyword; int wake;}";
767
            await TestAsync(source, async w =>
768
            {
769 770
                var expecteditem1 = new NavigateToItem("get_key_word", NavigateToItemKind.Field, "csharp", null, null, s_emptyCamelCaseNonContiguousPrefixPatternMatch_NotCaseSensitive, null);
                var expecteditem2 = new NavigateToItem("GetKeyWord", NavigateToItemKind.Field, "csharp", null, null, s_emptyCamelCaseExactPatternMatch, null);
771 772
                var expecteditems = new List<NavigateToItem> { expecteditem1, expecteditem2 };

773
                var items = await _aggregator.GetItemsAsync("GKW");
774 775

                VerifyNavigateToResultItems(expecteditems, items);
776
            });
777 778
        }

779 780
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task TermSplittingTest3()
781 782
        {
            var source = "class SyllableBreaking {int GetKeyWord; int get_key_word; string get_keyword; int getkeyword; int wake;}";
783
            await TestAsync(source, async w =>
784
            {
785 786
                var expecteditem1 = new NavigateToItem("get_key_word", NavigateToItemKind.Field, "csharp", null, null, s_emptyCamelCaseSubstringPatternMatch_NotCaseSensitive, null);
                var expecteditem2 = new NavigateToItem("GetKeyWord", NavigateToItemKind.Field, "csharp", null, null, s_emptySubstringPatternMatch, null);
787 788
                var expecteditems = new List<NavigateToItem> { expecteditem1, expecteditem2 };

789
                var items = await _aggregator.GetItemsAsync("K W");
790 791

                VerifyNavigateToResultItems(expecteditems, items);
792
            });
793 794
        }

795 796
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task TermSplittingTest4()
797 798
        {
            var source = "class SyllableBreaking {int GetKeyWord; int get_key_word; string get_keyword; int getkeyword; int wake;}";
799
            await TestAsync(source, async w =>
800
            {
801
                var items = await _aggregator.GetItemsAsync("WKG");
802
                Assert.Empty(items);
803
            });
804 805
        }

806 807
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task TermSplittingTest5()
808 809
        {
            var source = "class SyllableBreaking {int GetKeyWord; int get_key_word; string get_keyword; int getkeyword; int wake;}";
810
            await TestAsync(source, async w =>
811
            {
812
                var item = (await _aggregator.GetItemsAsync("G_K_W")).Single();
813
                VerifyNavigateToResultItem(item, "get_key_word", "[|g|]et[|_k|]ey[|_w|]ord", PatternMatchKind.CamelCaseExact, NavigateToItemKind.Field, Glyph.FieldPrivate);
814
            });
815 816
        }

817 818
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task TermSplittingTest6()
819 820
        {
            var source = "class SyllableBreaking {int GetKeyWord; int get_key_word; string get_keyword; int getkeyword; int wake;}";
821
            await TestAsync(source, async w =>
822 823 824
            {
                var expecteditems = new List<NavigateToItem>
                {
825 826
                    new NavigateToItem("get_key_word", NavigateToItemKind.Field, "csharp", null, null,s_emptyPrefixPatternMatch, null),
                    new NavigateToItem("GetKeyWord", NavigateToItemKind.Field, "csharp", null, null, s_emptyPrefixPatternMatch_NotCaseSensitive, null)
827 828
                };

829
                var items = await _aggregator.GetItemsAsync("get word");
830 831

                VerifyNavigateToResultItems(expecteditems, items);
832
            });
833 834
        }

835 836
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task TermSplittingTest7()
837 838
        {
            var source = "class SyllableBreaking {int GetKeyWord; int get_key_word; string get_keyword; int getkeyword; int wake;}";
839
            await TestAsync(source, async w =>
840
            {
841
                var items = await _aggregator.GetItemsAsync("GTW");
842
                Assert.Empty(items);
843
            });
844 845
        }

846 847
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task TestIndexer1()
848 849 850 851 852 853 854 855 856
        {
            var source =
@"class C
{
    public int this[int y] { get { } }
}

class D
{
857
    void Goo()
858 859 860 861 862
    {
        var q = new C();
        var b = q[4];
    }
}";
863
            await TestAsync(source, async w =>
864 865 866
            {
                var expecteditems = new List<NavigateToItem>
                {
867
                    new NavigateToItem("this", NavigateToItemKind.Property, "csharp", null, null, s_emptyExactPatternMatch, null),
868 869
                };

870
                var items = await _aggregator.GetItemsAsync("this");
871 872

                VerifyNavigateToResultItems(expecteditems, items);
873
            });
874 875
        }

876 877
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task DottedPattern1()
878
        {
879
            var source = "namespace Goo { namespace Bar { class Baz { void Quux() { } } } }";
880
            await TestAsync(source, async w =>
881 882 883
            {
                var expecteditems = new List<NavigateToItem>
                {
884
                    new NavigateToItem("Quux", NavigateToItemKind.Method, "csharp", null, null, s_emptyPrefixPatternMatch, null)
885 886
                };

887
                var items = await _aggregator.GetItemsAsync("B.Q");
888 889

                VerifyNavigateToResultItems(expecteditems, items);
890
            });
891 892
        }

893 894
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task DottedPattern2()
895
        {
896
            var source = "namespace Goo { namespace Bar { class Baz { void Quux() { } } } }";
897
            await TestAsync(source, async w =>
898 899 900 901 902
            {
                var expecteditems = new List<NavigateToItem>
                {
                };

903
                var items = await _aggregator.GetItemsAsync("C.Q");
904 905

                VerifyNavigateToResultItems(expecteditems, items);
906
            });
907 908
        }

909 910
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task DottedPattern3()
911
        {
912
            var source = "namespace Goo { namespace Bar { class Baz { void Quux() { } } } }";
913
            await TestAsync(source, async w =>
914 915 916
            {
                var expecteditems = new List<NavigateToItem>
                {
917
                    new NavigateToItem("Quux", NavigateToItemKind.Method, "csharp", null, null, s_emptyPrefixPatternMatch, null)
918 919
                };

920
                var items = await _aggregator.GetItemsAsync("B.B.Q");
921 922

                VerifyNavigateToResultItems(expecteditems, items);
923
            });
924 925
        }

926 927
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task DottedPattern4()
928
        {
929
            var source = "namespace Goo { namespace Bar { class Baz { void Quux() { } } } }";
930
            await TestAsync(source, async w =>
931 932 933
            {
                var expecteditems = new List<NavigateToItem>
                {
934
                    new NavigateToItem("Quux", NavigateToItemKind.Method, "csharp", null, null, s_emptyExactPatternMatch, null)
935 936
                };

937
                var items = await _aggregator.GetItemsAsync("Baz.Quux");
938 939

                VerifyNavigateToResultItems(expecteditems, items);
940
            });
941 942
        }

943 944
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task DottedPattern5()
945
        {
946
            var source = "namespace Goo { namespace Bar { class Baz { void Quux() { } } } }";
947
            await TestAsync(source, async w =>
948 949 950
            {
                var expecteditems = new List<NavigateToItem>
                {
951
                    new NavigateToItem("Quux", NavigateToItemKind.Method, "csharp", null, null, s_emptyExactPatternMatch, null)
952 953
                };

954
                var items = await _aggregator.GetItemsAsync("G.B.B.Quux");
955 956

                VerifyNavigateToResultItems(expecteditems, items);
957
            });
958 959
        }

960 961
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task DottedPattern6()
962
        {
963
            var source = "namespace Goo { namespace Bar { class Baz { void Quux() { } } } }";
964
            await TestAsync(source, async w =>
965 966 967 968 969
            {
                var expecteditems = new List<NavigateToItem>
                {
                };

970
                var items = await _aggregator.GetItemsAsync("F.F.B.B.Quux");
971 972

                VerifyNavigateToResultItems(expecteditems, items);
973
            });
974 975
        }

976
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
977
        [WorkItem(7855, "https://github.com/dotnet/Roslyn/issues/7855")]
978
        public async Task DottedPattern7()
979
        {
980
            var source = "namespace Goo { namespace Bar { class Baz<X,Y,Z> { void Quux() { } } } }";
981
            await TestAsync(source, async w =>
982 983 984
            {
                var expecteditems = new List<NavigateToItem>
                {
985
                    new NavigateToItem("Quux", NavigateToItemKind.Method, "csharp", null, null, s_emptyPrefixPatternMatch, null)
986 987
                };

988
                var items = await _aggregator.GetItemsAsync("Baz.Q");
989 990

                VerifyNavigateToResultItems(expecteditems, items);
991
            });
992 993
        }

J
Jared Parsons 已提交
994
        [WorkItem(1174255, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1174255")]
995
        [WorkItem(8009, "https://github.com/dotnet/roslyn/issues/8009")]
996
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
997
        public async Task NavigateToGeneratedFiles()
998
        {
C
CyrusNajmabadi 已提交
999
            using (var workspace = TestWorkspace.Create(@"
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015
<Workspace>
    <Project Language=""C#"" CommonReferences=""true"">
        <Document FilePath=""File1.cs"">
            namespace N
            {
                public partial class C
                {
                    public void VisibleMethod() { }
                }
            }
        </Document>
        <Document FilePath=""File1.g.cs"">
            namespace N
            {
                public partial class C
                {
1016
                    public void VisibleMethod_Generated() { }
1017 1018 1019 1020 1021
                }
            }
        </Document>
    </Project>
</Workspace>
1022
", exportProvider: TestExportProvider.ExportProviderWithCSharpAndVisualBasic))
1023
            {
1024
                _provider = new NavigateToItemProvider(workspace, AsynchronousOperationListenerProvider.NullListener);
1025 1026
                _aggregator = new NavigateToTestAggregator(_provider);

1027
                var items = await _aggregator.GetItemsAsync("VisibleMethod");
1028 1029
                var expectedItems = new List<NavigateToItem>()
                {
1030 1031
                    new NavigateToItem("VisibleMethod", NavigateToItemKind.Method, "csharp", null, null, s_emptyExactPatternMatch, null),
                    new NavigateToItem("VisibleMethod_Generated", NavigateToItemKind.Method, "csharp", null, null, s_emptyPrefixPatternMatch, null)
1032 1033 1034 1035 1036 1037 1038 1039
                };

                // The pattern matcher should match 'VisibleMethod' to both 'VisibleMethod' and 'VisibleMethod_Not', except that
                // the _Not method is declared in a generated file.
                VerifyNavigateToResultItems(expectedItems, items);
            }
        }

1040
        [WorkItem(11474, "https://github.com/dotnet/roslyn/pull/11474")]
1041 1042
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task FindFuzzy1()
1043
        {
C
CyrusNajmabadi 已提交
1044 1045 1046 1047 1048 1049 1050
            await TestAsync(
@"class C
{
    public void ToError()
    {
    }
}", async w =>
1051
            {
1052
                var item = (await _aggregator.GetItemsAsync("ToEror")).Single();
1053
                VerifyNavigateToResultItem(item, "ToError", "ToError()", PatternMatchKind.Fuzzy, NavigateToItemKind.Method, Glyph.MethodPublic);
1054
            });
1055
        }
1056 1057

        [WorkItem(18843, "https://github.com/dotnet/roslyn/issues/18843")]
1058 1059
        [WpfFact, Trait(Traits.Feature, Traits.Features.NavigateTo)]
        public async Task Test__arglist()
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
        {
            await TestAsync(
@"class C
{
    public void ToError(__arglist)
    {
    }
}", async w =>
{
    var item = (await _aggregator.GetItemsAsync("ToError")).Single();
1070
    VerifyNavigateToResultItem(item, "ToError", "[|ToError|](__arglist)", PatternMatchKind.Exact, NavigateToItemKind.Method, Glyph.MethodPublic);
1071
});
1072
        }
1073
    }
S
Sam Harwell 已提交
1074
}
1075
#pragma warning restore CS0618 // MatchKind is obsolete