Skip to content

Commit

Permalink
refactoring tests to not use extension methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarolf committed Apr 4, 2017
1 parent aac94f4 commit fd9b37f
Show file tree
Hide file tree
Showing 79 changed files with 2,225 additions and 2,477 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities.OutOfProcess;
using Roslyn.Test.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions.SolutionExplorer;
using ProjectUtils = Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils;

namespace Roslyn.VisualStudio.IntegrationTests
{
public abstract class AbstractEditorTest : AbstractIntegrationTest
{
protected readonly Editor_OutOfProc Editor;

protected AbstractEditorTest(VisualStudioInstanceFactory instanceFactory)
: base(instanceFactory, visualStudio => visualStudio.Instance.Editor)
: base(instanceFactory)
{
Editor = (Editor_OutOfProc)TextViewWindow;
}

protected AbstractEditorTest(VisualStudioInstanceFactory instanceFactory, string solutionName)
Expand All @@ -27,19 +23,17 @@ protected AbstractEditorTest(
VisualStudioInstanceFactory instanceFactory,
string solutionName,
string projectTemplate)
: base(instanceFactory, visualStudio => visualStudio.Instance.Editor)
: base(instanceFactory)
{
this.CreateSolution(solutionName);
this.AddProject(projectTemplate, new ProjectUtils.Project(ProjectName), LanguageName);

Editor = (Editor_OutOfProc)TextViewWindow;
VisualStudio.SolutionExplorer.CreateSolution(solutionName);
VisualStudio.SolutionExplorer.AddProject(new ProjectUtils.Project(ProjectName), projectTemplate, LanguageName);

// Winforms and XAML do not open text files on creation
// so these editor tasks will not work if that is the project template being used.
if (projectTemplate != WellKnownProjectTemplates.WinFormsApplication &&
projectTemplate != WellKnownProjectTemplates.WpfApplication)
{
VisualStudioWorkspaceOutOfProc.SetUseSuggestionMode(false);
VisualStudio.Workspace.SetUseSuggestionMode(false);
ClearEditor();
}
}
Expand All @@ -53,17 +47,17 @@ protected void SetUpEditor(string markupCode)
{
MarkupTestFile.GetPosition(markupCode, out string code, out int caretPosition);

var originalValue = VisualStudioWorkspaceOutOfProc.IsPrettyListingOn(LanguageName);
var originalValue = VisualStudio.Workspace.IsPrettyListingOn(LanguageName);

VisualStudioWorkspaceOutOfProc.SetPrettyListing(LanguageName, false);
VisualStudio.Workspace.SetPrettyListing(LanguageName, false);
try
{
Editor.SetText(code);
Editor.MoveCaret(caretPosition);
VisualStudio.Editor.SetText(code);
VisualStudio.Editor.MoveCaret(caretPosition);
}
finally
{
VisualStudioWorkspaceOutOfProc.SetPrettyListing(LanguageName, originalValue);
VisualStudio.Workspace.SetPrettyListing(LanguageName, originalValue);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,22 @@ namespace Roslyn.VisualStudio.IntegrationTests
[CaptureTestName]
public abstract class AbstractIntegrationTest : IDisposable
{
public readonly VisualStudioInstanceContext VisualStudio;
public readonly VisualStudioWorkspace_OutOfProc VisualStudioWorkspaceOutOfProc;
public readonly TextViewWindow_OutOfProc TextViewWindow;
public readonly VisualStudioInstance VisualStudio;

protected readonly string ProjectName = "TestProj";
protected readonly string SolutionName = "TestSolution";

private VisualStudioInstanceContext _visualStudioContext;

protected AbstractIntegrationTest(
VisualStudioInstanceFactory instanceFactory,
Func<VisualStudioInstanceContext, TextViewWindow_OutOfProc> textViewWindowBuilder)
VisualStudioInstanceFactory instanceFactory)
{
VisualStudio = instanceFactory.GetNewOrUsedInstance(SharedIntegrationHostFixture.RequiredPackageIds);
TextViewWindow = textViewWindowBuilder(VisualStudio);
VisualStudioWorkspaceOutOfProc = VisualStudio.Instance.VisualStudioWorkspace;
_visualStudioContext = instanceFactory.GetNewOrUsedInstance(SharedIntegrationHostFixture.RequiredPackageIds);
VisualStudio = _visualStudioContext.Instance;
}

public void Dispose()
=> VisualStudio.Dispose();
=> _visualStudioContext.Dispose();

protected void Wait(double seconds)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,18 @@ namespace Roslyn.VisualStudio.IntegrationTests
{
public abstract class AbstractInteractiveWindowTest : AbstractIntegrationTest
{
internal readonly CSharpInteractiveWindow_OutOfProc InteractiveWindow;

protected AbstractInteractiveWindowTest(VisualStudioInstanceFactory instanceFactory)
: base(instanceFactory, visualStudio => visualStudio.Instance.CSharpInteractiveWindow)
: base(instanceFactory)
{
InteractiveWindow = (CSharpInteractiveWindow_OutOfProc)TextViewWindow;
ClearInteractiveWindow();
}

protected void ClearInteractiveWindow()
{
InteractiveWindow.Initialize();
InteractiveWindow.ClearScreen();
InteractiveWindow.ShowWindow();
InteractiveWindow.Reset();
VisualStudio.InteractiveWindow.Initialize();
VisualStudio.InteractiveWindow.ClearScreen();
VisualStudio.InteractiveWindow.ShowWindow();
VisualStudio.InteractiveWindow.Reset();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Roslyn.VisualStudio.IntegrationTests.Extensions;
using Roslyn.VisualStudio.IntegrationTests.Extensions.Editor;
using Roslyn.VisualStudio.IntegrationTests.Extensions.SolutionExplorer;
using Xunit;
using ProjectUtils = Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils;

Expand Down Expand Up @@ -102,7 +99,7 @@ static void Main(string[] args)
public CSharpAddMissingReference(VisualStudioInstanceFactory instanceFactory)
: base(instanceFactory)
{
VisualStudio.Instance.SolutionExplorer.CreateSolution("ReferenceErrors", solutionElement: XElement.Parse(
VisualStudio.SolutionExplorer.CreateSolution("ReferenceErrors", solutionElement: XElement.Parse(
"<Solution>" +
$" <Project ProjectName=\"{ClassLibrary1Name}\" ProjectTemplate=\"{WellKnownProjectTemplates.WinFormsApplication}\" Language=\"{LanguageNames.VisualBasic}\">" +
" <Document FileName=\"Class1.vb\"><![CDATA[" +
Expand Down Expand Up @@ -135,35 +132,35 @@ public CSharpAddMissingReference(VisualStudioInstanceFactory instanceFactory)
public void VerifyAvailableCodeActions()
{
var consoleProject = new ProjectUtils.Project(ConsoleProjectName);
this.OpenFile("Program.cs", consoleProject);
this.PlaceCaret("y.foo", charsOffset: 1);
this.InvokeCodeActionList();
this.VerifyCodeAction("Add reference to 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.", applyFix: false);
this.PlaceCaret("y.ee", charsOffset: 1);
this.InvokeCodeActionList();
this.VerifyCodeAction("Add reference to 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.", applyFix: false);
this.PlaceCaret("a.bar", charsOffset: 1);
this.InvokeCodeActionList();
this.VerifyCodeAction("Add project reference to 'ClassLibrary3'.", applyFix: false);
VisualStudio.SolutionExplorer.OpenFile( consoleProject, "Program.cs");
VisualStudio.Editor.PlaceCaret("y.foo", charsOffset: 1);
VisualStudio.Editor.InvokeCodeActionList();
VisualStudio.Editor.Verify.CodeAction("Add reference to 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.", applyFix: false);
VisualStudio.Editor.PlaceCaret("y.ee", charsOffset: 1);
VisualStudio.Editor.InvokeCodeActionList();
VisualStudio.Editor.Verify.CodeAction("Add reference to 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.", applyFix: false);
VisualStudio.Editor.PlaceCaret("a.bar", charsOffset: 1);
VisualStudio.Editor.InvokeCodeActionList();
VisualStudio.Editor.Verify.CodeAction("Add project reference to 'ClassLibrary3'.", applyFix: false);
}

[Fact, Trait(Traits.Feature, Traits.Features.AddMissingReference)]
public void InvokeSomeFixesInCSharpThenVerifyReferences()
{
var consoleProject = new ProjectUtils.Project(ConsoleProjectName);
this.OpenFile("Program.cs", consoleProject);
this.PlaceCaret("y.foo", charsOffset: 1);
this.InvokeCodeActionList();
this.VerifyCodeAction("Add reference to 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.", applyFix: true);
this.VerifyAssemblyReferencePresent(
VisualStudio.SolutionExplorer.OpenFile(consoleProject, "Program.cs");
VisualStudio.Editor.PlaceCaret("y.foo", charsOffset: 1);
VisualStudio.Editor.InvokeCodeActionList();
VisualStudio.Editor.Verify.CodeAction("Add reference to 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.", applyFix: true);
VisualStudio.SolutionExplorer.Verify.AssemblyReferencePresent(
project: consoleProject,
assemblyName: "System.Windows.Forms",
assemblyVersion: "4.0.0.0",
assemblyPublicKeyToken: "b77a5c561934e089");
this.PlaceCaret("a.bar", charsOffset: 1);
this.InvokeCodeActionList();
this.VerifyCodeAction("Add project reference to 'ClassLibrary3'.", applyFix: true);
this.VerifyProjectReferencePresent(
VisualStudio.Editor.PlaceCaret("a.bar", charsOffset: 1);
VisualStudio.Editor.InvokeCodeActionList();
VisualStudio.Editor.Verify.CodeAction("Add project reference to 'ClassLibrary3'.", applyFix: true);
VisualStudio.SolutionExplorer.Verify.ProjectReferencePresent(
project: consoleProject,
referencedProjectName: ClassLibrary3Name);
}
Expand Down
Loading

0 comments on commit fd9b37f

Please sign in to comment.