diff --git a/test/TestAssets/dotnet-format/for_workspace_finder/multiple_projects/project_a.csproj b/test/TestAssets/dotnet-format/for_workspace_finder/multiple_projects/project_a.csproj
index c73e0d1692ab..36dd7f3c7e78 100644
--- a/test/TestAssets/dotnet-format/for_workspace_finder/multiple_projects/project_a.csproj
+++ b/test/TestAssets/dotnet-format/for_workspace_finder/multiple_projects/project_a.csproj
@@ -2,7 +2,7 @@
Exe
- netcoreapp3.1
+ $(CurrentTargetFramework)
diff --git a/test/TestAssets/dotnet-format/for_workspace_finder/multiple_projects/project_b.csproj b/test/TestAssets/dotnet-format/for_workspace_finder/multiple_projects/project_b.csproj
index c73e0d1692ab..36dd7f3c7e78 100644
--- a/test/TestAssets/dotnet-format/for_workspace_finder/multiple_projects/project_b.csproj
+++ b/test/TestAssets/dotnet-format/for_workspace_finder/multiple_projects/project_b.csproj
@@ -2,7 +2,7 @@
Exe
- netcoreapp3.1
+ $(CurrentTargetFramework)
diff --git a/test/TestAssets/dotnet-format/for_workspace_finder/project_and_solution/project_and_solution.csproj b/test/TestAssets/dotnet-format/for_workspace_finder/project_and_solution/project_and_solution.csproj
index c73e0d1692ab..36dd7f3c7e78 100644
--- a/test/TestAssets/dotnet-format/for_workspace_finder/project_and_solution/project_and_solution.csproj
+++ b/test/TestAssets/dotnet-format/for_workspace_finder/project_and_solution/project_and_solution.csproj
@@ -2,7 +2,7 @@
Exe
- netcoreapp3.1
+ $(CurrentTargetFramework)
diff --git a/test/TestAssets/dotnet-format/for_workspace_finder/single_project/single_project.csproj b/test/TestAssets/dotnet-format/for_workspace_finder/single_project/single_project.csproj
index c73e0d1692ab..36dd7f3c7e78 100644
--- a/test/TestAssets/dotnet-format/for_workspace_finder/single_project/single_project.csproj
+++ b/test/TestAssets/dotnet-format/for_workspace_finder/single_project/single_project.csproj
@@ -2,7 +2,7 @@
Exe
- netcoreapp3.1
+ $(CurrentTargetFramework)
diff --git a/test/dotnet-format.Tests/tests/MSBuild/MSBuildWorkspaceFinderTests.cs b/test/dotnet-format.Tests/tests/MSBuild/MSBuildWorkspaceFinderTests.cs
index 28526b8c95e4..e7fdce2e6efc 100644
--- a/test/dotnet-format.Tests/tests/MSBuild/MSBuildWorkspaceFinderTests.cs
+++ b/test/dotnet-format.Tests/tests/MSBuild/MSBuildWorkspaceFinderTests.cs
@@ -2,63 +2,79 @@
using Microsoft.CodeAnalysis.Tools.Tests.Utilities;
using Microsoft.CodeAnalysis.Tools.Workspaces;
+using Microsoft.NET.TestFramework;
namespace Microsoft.CodeAnalysis.Tools.Tests.MSBuild
{
- public class MSBuildWorkspaceFinderTests
+ public class MSBuildWorkspaceFinderTests : SdkTest
{
+
+ public MSBuildWorkspaceFinderTests(ITestOutputHelper log) : base(log)
+ {
+ }
+
private string ProjectsPath => TestProjectsPathHelper.GetProjectsDirectory();
[Fact]
public void ThrowsException_CannotFindMSBuildProjectFile()
{
- var workspacePath = "for_workspace_finder/no_project_or_solution/";
+ var testInstance = _testAssetsManager
+ .CopyTestAsset(testProjectName: "for_workspace_finder/no_project_or_solution", testAssetSubdirectory: "dotnet-format")
+ .WithSource();
var exceptionMessageStart = string.Format(
Resources.Could_not_find_a_MSBuild_project_or_solution_file_in_0_Specify_which_to_use_with_the_workspace_argument,
- Path.Combine(ProjectsPath, workspacePath)).Replace('/', Path.DirectorySeparatorChar);
- var exception = Assert.Throws(() => MSBuildWorkspaceFinder.FindWorkspace(ProjectsPath, workspacePath));
+ testInstance.Path).Replace('/', Path.DirectorySeparatorChar);
+ var exception = Assert.Throws(() => MSBuildWorkspaceFinder.FindWorkspace(testInstance.Path));
Assert.StartsWith(exceptionMessageStart, exception.Message);
}
[Fact]
public void ThrowsException_MultipleMSBuildProjectFiles()
{
- var workspacePath = "for_workspace_finder/multiple_projects/";
+ var testInstance = _testAssetsManager
+ .CopyTestAsset(testProjectName: "for_workspace_finder/multiple_projects", testAssetSubdirectory: "dotnet-format")
+ .WithSource();
var exceptionMessageStart = string.Format(
Resources.Multiple_MSBuild_project_files_found_in_0_Specify_which_to_use_with_the_workspace_argument,
- Path.Combine(ProjectsPath, workspacePath)).Replace('/', Path.DirectorySeparatorChar);
- var exception = Assert.Throws(() => MSBuildWorkspaceFinder.FindWorkspace(ProjectsPath, workspacePath));
+ testInstance.Path).Replace('/', Path.DirectorySeparatorChar);
+ var exception = Assert.Throws(() => MSBuildWorkspaceFinder.FindWorkspace(testInstance.Path));
Assert.Equal(exceptionMessageStart, exception.Message);
}
[Fact]
public void ThrowsException_MultipleMSBuildSolutionFiles()
{
- var workspacePath = "for_workspace_finder/multiple_solutions/";
+ var testInstance = _testAssetsManager
+ .CopyTestAsset(testProjectName: "for_workspace_finder/multiple_solutions", testAssetSubdirectory: "dotnet-format")
+ .WithSource();
var exceptionMessageStart = string.Format(
Resources.Multiple_MSBuild_solution_files_found_in_0_Specify_which_to_use_with_the_workspace_argument,
- Path.Combine(ProjectsPath, workspacePath)).Replace('/', Path.DirectorySeparatorChar);
- var exception = Assert.Throws(() => MSBuildWorkspaceFinder.FindWorkspace(ProjectsPath, workspacePath));
+ testInstance.Path).Replace('/', Path.DirectorySeparatorChar);
+ var exception = Assert.Throws(() => MSBuildWorkspaceFinder.FindWorkspace(testInstance.Path));
Assert.Equal(exceptionMessageStart, exception.Message);
}
[Fact]
public void ThrowsException_SolutionAndProjectAmbiguity()
{
- var workspacePath = "for_workspace_finder/project_and_solution/";
+ var testInstance = _testAssetsManager
+ .CopyTestAsset(testProjectName: "for_workspace_finder/project_and_solution", testAssetSubdirectory: "dotnet-format")
+ .WithSource();
var exceptionMessageStart = string.Format(
Resources.Both_a_MSBuild_project_file_and_solution_file_found_in_0_Specify_which_to_use_with_the_workspace_argument,
- Path.Combine(ProjectsPath, workspacePath)).Replace('/', Path.DirectorySeparatorChar);
- var exception = Assert.Throws(() => MSBuildWorkspaceFinder.FindWorkspace(ProjectsPath, workspacePath));
+ testInstance.Path).Replace('/', Path.DirectorySeparatorChar);
+ var exception = Assert.Throws(() => MSBuildWorkspaceFinder.FindWorkspace(testInstance.Path));
Assert.Equal(exceptionMessageStart, exception.Message);
}
[Fact]
public void FindsSolutionByFolder()
{
- const string Path = "for_workspace_finder/single_solution/";
+ var testInstance = _testAssetsManager
+ .CopyTestAsset(testProjectName: "for_workspace_finder/single_solution", testAssetSubdirectory: "dotnet-format")
+ .WithSource();
- var (isSolution, workspacePath) = MSBuildWorkspaceFinder.FindWorkspace(ProjectsPath, Path);
+ var (isSolution, workspacePath) = MSBuildWorkspaceFinder.FindWorkspace(testInstance.Path);
var solutionFileName = System.IO.Path.GetFileName(workspacePath);
Assert.Equal("single_solution.sln", solutionFileName);
@@ -68,9 +84,11 @@ public void FindsSolutionByFolder()
[Fact]
public void FindsSolutionByFilePath()
{
- const string Path = "for_workspace_finder/multiple_solutions/solution_b.sln";
+ var testInstance = _testAssetsManager
+ .CopyTestAsset(testProjectName: "for_workspace_finder/multiple_solutions", testAssetSubdirectory: "dotnet-format")
+ .WithSource();
- var (isSolution, workspacePath) = MSBuildWorkspaceFinder.FindWorkspace(ProjectsPath, Path);
+ var (isSolution, workspacePath) = MSBuildWorkspaceFinder.FindWorkspace(testInstance.Path, "solution_b.sln");
var solutionFileName = System.IO.Path.GetFileName(workspacePath);
Assert.Equal("solution_b.sln", solutionFileName);
@@ -80,9 +98,11 @@ public void FindsSolutionByFilePath()
[Fact]
public void FindsProjectByFolder()
{
- const string Path = "for_workspace_finder/single_project/";
+ var testInstance = _testAssetsManager
+ .CopyTestAsset(testProjectName: "for_workspace_finder/single_project", testAssetSubdirectory: "dotnet-format")
+ .WithSource();
- var (isSolution, workspacePath) = MSBuildWorkspaceFinder.FindWorkspace(ProjectsPath, Path);
+ var (isSolution, workspacePath) = MSBuildWorkspaceFinder.FindWorkspace(testInstance.Path);
var solutionFileName = System.IO.Path.GetFileName(workspacePath);
Assert.Equal("single_project.csproj", solutionFileName);
@@ -92,9 +112,11 @@ public void FindsProjectByFolder()
[Fact]
public void FindsProjectByFilePath()
{
- const string Path = "for_workspace_finder/multiple_projects/project_b.csproj";
+ var testInstance = _testAssetsManager
+ .CopyTestAsset(testProjectName: "for_workspace_finder/multiple_projects", testAssetSubdirectory: "dotnet-format")
+ .WithSource();
- var (isSolution, workspacePath) = MSBuildWorkspaceFinder.FindWorkspace(ProjectsPath, Path);
+ var (isSolution, workspacePath) = MSBuildWorkspaceFinder.FindWorkspace(testInstance.Path, "project_b.csproj");
var solutionFileName = System.IO.Path.GetFileName(workspacePath);
Assert.Equal("project_b.csproj", solutionFileName);