Skip to content

Commit

Permalink
Add VSI tests for Navigation Bars (#18478)
Browse files Browse the repository at this point in the history
Add VSI tests for Navigation Bars
  • Loading branch information
Ravi Chande authored Apr 6, 2017
1 parent ad64d42 commit 9616765
Show file tree
Hide file tree
Showing 7 changed files with 488 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// 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 Roslyn.Test.Utilities;
using Xunit;

namespace Roslyn.VisualStudio.IntegrationTests.CSharp
{
[Collection(nameof(SharedIntegrationHostFixture))]
public class CSharpNavigationBar : AbstractEditorTest
{
private const string TestSource = @"
class C
{
public void M(int i) { }
private C $$this[int index] { get { return null; } set { } }
public static bool operator ==(C c1, C c2) { return true; }
public static bool operator !=(C c1, C c2) { return false; }
}
struct S
{
int Foo() { }
void Bar() { }
}";

protected override string LanguageName => LanguageNames.CSharp;

public CSharpNavigationBar(VisualStudioInstanceFactory instanceFactory)
: base(instanceFactory, nameof(CSharpNavigationBar))
{
}

[Fact, Trait(Traits.Feature, Traits.Features.NavigationBar)]
public void VerifyNavBar()
{
SetUpEditor(TestSource);
VisualStudio.Editor.PlaceCaret("this", charsOffset: 1);
VisualStudio.Editor.ExpandMemberNavBar();
var expectedItems = new[]
{
"M(int i)",
"operator !=(C c1, C c2)",
"operator ==(C c1, C c2)",
"this[int index]"
};

Assert.Equal(expectedItems, VisualStudio.Editor.GetMemberNavBarItems());
VisualStudio.Editor.SelectMemberNavBarItem("operator !=(C c1, C c2)");

VisualStudio.Editor.Verify.CurrentLineText("public static bool operator $$!=(C c1, C c2) { return false; }", assertCaretPosition: true, trimWhitespace: true);
}

[Fact, Trait(Traits.Feature, Traits.Features.NavigationBar)]
public void VerifyNavBar2()
{
SetUpEditor(TestSource);

VerifyLeftSelected("C");
VerifyRightSelected("this[int index]");

VisualStudio.Editor.ExpandTypeNavBar();
var expectedItems = new[]
{
"C",
"S",
};

VisualStudio.Editor.SelectTypeNavBarItem("S");

VerifyLeftSelected("S");
VerifyRightSelected("Foo()");
VisualStudio.Editor.Verify.CurrentLineText("$$struct S", assertCaretPosition: true, trimWhitespace: true);
}

[Fact, Trait(Traits.Feature, Traits.Features.NavigationBar)]
public void VerifyNavBar3()
{
SetUpEditor(@"
struct S$$
{
int Foo() { }
void Bar() { }
}");
VisualStudio.Editor.ExpandMemberNavBar();
var expectedItems = new[]
{
"Bar()",
"Foo()",
};
Assert.Equal(expectedItems, VisualStudio.Editor.GetMemberNavBarItems());
VisualStudio.Editor.SelectMemberNavBarItem("Bar()");
VisualStudio.Editor.Verify.CurrentLineText("void $$Bar() { }", assertCaretPosition: true, trimWhitespace: true);

VisualStudio.ExecuteCommand("Edit.LineUp");
VerifyRightSelected("Foo()");
}

[Fact, Trait(Traits.Feature, Traits.Features.NavigationBar)]
public void TestSplitWindow()
{
VisualStudio.Editor.SetText(@"
class C
{
public void M(int i) { }
private C this[int index] { get { return null; } set { } }
}
struct S
{
int Foo() { }
void Bar() { }
}");
VisualStudio.ExecuteCommand("Window.Split");
VisualStudio.Editor.PlaceCaret("this", charsOffset: 1);
VerifyLeftSelected("C");
VerifyRightSelected("this[int index]");
VisualStudio.ExecuteCommand("Window.NextSplitPane");
VisualStudio.Editor.PlaceCaret("Foo", charsOffset: 1);
VerifyLeftSelected("S");
VerifyRightSelected("Foo()");
}

[Fact, Trait(Traits.Feature, Traits.Features.NavigationBar)]
public void VerifyOption()
{
VisualStudio.Workspace.SetFeatureOption("NavigationBarOptions", "ShowNavigationBar", "C#", "False");
Assert.False(VisualStudio.Editor.IsNavBarEnabled());

VisualStudio.Workspace.SetFeatureOption("NavigationBarOptions", "ShowNavigationBar", "C#", "True");
Assert.True(VisualStudio.Editor.IsNavBarEnabled());
}

private void VerifyLeftSelected(string expected)
{
Assert.Equal(expected, VisualStudio.Editor.GetTypeNavBarSelection());
}

private void VerifyRightSelected(string expected)
{
Assert.Equal(expected, VisualStudio.Editor.GetMemberNavBarSelection());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// 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 Roslyn.Test.Utilities;
using Xunit;

namespace Roslyn.VisualStudio.IntegrationTests.Basic
{
[Collection(nameof(SharedIntegrationHostFixture))]
public class BasicNavigationBar : AbstractEditorTest
{
private const string TestSource = @"
Class C
Public WithEvents Domain As AppDomain
Public Sub Foo()
End Sub
End Class
Structure S
Public Property A As Integer
Public Property B As Integer
End Structure";

protected override string LanguageName => LanguageNames.VisualBasic;

public BasicNavigationBar(VisualStudioInstanceFactory instanceFactory)
: base(instanceFactory, nameof(BasicNavigationBar))
{
}

[Fact, Trait(Traits.Feature, Traits.Features.NavigationBar)]
public void VerifyNavBar()
{
VisualStudio.Editor.SetText(TestSource);

VisualStudio.Editor.PlaceCaret("Foo", charsOffset: 1);

VerifyLeftSelected("C");
VerifyRightSelected("Foo");

VisualStudio.Editor.ExpandTypeNavBar();
var expectedItems = new[]
{
"C",
"Domain",
"S"
};

Assert.Equal(expectedItems, VisualStudio.Editor.GetTypeNavBarItems());

VisualStudio.Editor.SelectTypeNavBarItem("S");

VisualStudio.Editor.Verify.CaretPosition(112);
VisualStudio.Editor.Verify.CurrentLineText("Structure S$$", assertCaretPosition: true);

VisualStudio.ExecuteCommand("Edit.LineDown");
VerifyRightSelected("A");

VisualStudio.Editor.ExpandMemberNavBar();
expectedItems = new[]
{
"A",
"B",
};

Assert.Equal(expectedItems, VisualStudio.Editor.GetMemberNavBarItems());
VisualStudio.Editor.SelectMemberNavBarItem("B");
VisualStudio.Editor.Verify.CaretPosition(169);
VisualStudio.Editor.Verify.CurrentLineText("Public Property $$B As Integer", assertCaretPosition: true, trimWhitespace: true);
}

[Fact, Trait(Traits.Feature, Traits.Features.NavigationBar)]
public void CodeSpit()
{
VisualStudio.Editor.SetText(TestSource);

VisualStudio.Editor.PlaceCaret("C", charsOffset: 1);
VerifyLeftSelected("C");
VisualStudio.Editor.ExpandMemberNavBar();
Assert.Equal(new[] { "New", "Finalize", "Foo" }, VisualStudio.Editor.GetMemberNavBarItems());
VisualStudio.Editor.SelectMemberNavBarItem("New");
VisualStudio.Editor.Verify.TextContains(@"
Public Sub New()
End Sub");
VisualStudio.Editor.Verify.CaretPosition(78); // Caret is between New() and End Sub() in virtual whitespace
VisualStudio.Editor.Verify.CurrentLineText("$$", assertCaretPosition: true);
}

[Fact, Trait(Traits.Feature, Traits.Features.NavigationBar)]
public void VerifyOption()
{
VisualStudio.Workspace.SetFeatureOption("NavigationBarOptions", "ShowNavigationBar", "Visual Basic", "False");
Assert.False(VisualStudio.Editor.IsNavBarEnabled());

VisualStudio.Workspace.SetFeatureOption("NavigationBarOptions", "ShowNavigationBar", "Visual Basic", "True");
Assert.True(VisualStudio.Editor.IsNavBarEnabled());
}

private void VerifyLeftSelected(string expected)
{
Assert.Equal(expected, VisualStudio.Editor.GetTypeNavBarSelection());
}

private void VerifyRightSelected(string expected)
{
Assert.Equal(expected, VisualStudio.Editor.GetMemberNavBarSelection());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<Compile Include="CSharp\CSharpInteractive.cs" />
<Compile Include="AbstractEditorTest.cs" />
<Compile Include="CSharp\CSharpInteractiveCommands.cs" />
<Compile Include="CSharp\CSharpNavigationBar.cs" />
<Compile Include="CSharp\CSharpKeywordHighlighting.cs" />
<Compile Include="CSharp\CSharpReplClassification.cs" />
<Compile Include="CSharp\CSharpReplIdeFeatures.cs" />
Expand All @@ -56,6 +57,7 @@
<Compile Include="CSharp\CSharpAddMissingReference.cs" />
<Compile Include="VisualBasic\BasicKeywordHighlighting.cs" />
<Compile Include="VisualBasic\BasicEncapsulateField.cs" />
<Compile Include="VisualBasic\BasicNavigationBar.cs" />
<Compile Include="VisualBasic\BasicLineCommit.cs" />
<Compile Include="VisualBasic\BasicSquigglesCommon.cs" />
<Compile Include="VisualBasic\BasicSquigglesDesktop.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace Microsoft.VisualStudio.IntegrationTest.Utilities.InProcess
{
internal class Editor_InProc : TextViewWindow_InProc
internal partial class Editor_InProc : TextViewWindow_InProc
{
private static readonly Guid IWpfTextViewId = new Guid("8C40265E-9FDB-4F54-A0FD-EBB72B7D0476");

Expand Down
Loading

0 comments on commit 9616765

Please sign in to comment.