Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>$(CurrentTargetFramework)</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>$(CurrentTargetFramework)</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>$(CurrentTargetFramework)</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>$(CurrentTargetFramework)</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Comment on lines +11 to +14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: empty line after ctor

Suggested change
public MSBuildWorkspaceFinderTests(ITestOutputHelper log) : base(log)
{
}
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<FileNotFoundException>(() => MSBuildWorkspaceFinder.FindWorkspace(ProjectsPath, workspacePath));
testInstance.Path).Replace('/', Path.DirectorySeparatorChar);
var exception = Assert.Throws<FileNotFoundException>(() => 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<FileNotFoundException>(() => MSBuildWorkspaceFinder.FindWorkspace(ProjectsPath, workspacePath));
testInstance.Path).Replace('/', Path.DirectorySeparatorChar);
var exception = Assert.Throws<FileNotFoundException>(() => 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<FileNotFoundException>(() => MSBuildWorkspaceFinder.FindWorkspace(ProjectsPath, workspacePath));
testInstance.Path).Replace('/', Path.DirectorySeparatorChar);
var exception = Assert.Throws<FileNotFoundException>(() => 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<FileNotFoundException>(() => MSBuildWorkspaceFinder.FindWorkspace(ProjectsPath, workspacePath));
testInstance.Path).Replace('/', Path.DirectorySeparatorChar);
var exception = Assert.Throws<FileNotFoundException>(() => 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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down