22
33using Microsoft . CodeAnalysis . Tools . Tests . Utilities ;
44using Microsoft . CodeAnalysis . Tools . Workspaces ;
5+ using Microsoft . NET . TestFramework ;
56
67namespace Microsoft . CodeAnalysis . Tools . Tests . MSBuild
78{
8- public class MSBuildWorkspaceFinderTests
9+ public class MSBuildWorkspaceFinderTests : SdkTest
910 {
11+
12+ public MSBuildWorkspaceFinderTests ( ITestOutputHelper log ) : base ( log )
13+ {
14+ }
15+
1016 private string ProjectsPath => TestProjectsPathHelper . GetProjectsDirectory ( ) ;
1117
1218 [ Fact ]
1319 public void ThrowsException_CannotFindMSBuildProjectFile ( )
1420 {
15- var workspacePath = "for_workspace_finder/no_project_or_solution/" ;
21+ var testInstance = _testAssetsManager
22+ . CopyTestAsset ( testProjectName : "for_workspace_finder/no_project_or_solution" , testAssetSubdirectory : "dotnet-format" )
23+ . WithSource ( ) ;
1624 var exceptionMessageStart = string . Format (
1725 Resources . Could_not_find_a_MSBuild_project_or_solution_file_in_0_Specify_which_to_use_with_the_workspace_argument ,
18- Path . Combine ( ProjectsPath , workspacePath ) ) . Replace ( '/' , Path . DirectorySeparatorChar ) ;
19- var exception = Assert . Throws < FileNotFoundException > ( ( ) => MSBuildWorkspaceFinder . FindWorkspace ( ProjectsPath , workspacePath ) ) ;
26+ testInstance . Path ) . Replace ( '/' , Path . DirectorySeparatorChar ) ;
27+ var exception = Assert . Throws < FileNotFoundException > ( ( ) => MSBuildWorkspaceFinder . FindWorkspace ( testInstance . Path ) ) ;
2028 Assert . StartsWith ( exceptionMessageStart , exception . Message ) ;
2129 }
2230
2331 [ Fact ]
2432 public void ThrowsException_MultipleMSBuildProjectFiles ( )
2533 {
26- var workspacePath = "for_workspace_finder/multiple_projects/" ;
34+ var testInstance = _testAssetsManager
35+ . CopyTestAsset ( testProjectName : "for_workspace_finder/multiple_projects" , testAssetSubdirectory : "dotnet-format" )
36+ . WithSource ( ) ;
2737 var exceptionMessageStart = string . Format (
2838 Resources . Multiple_MSBuild_project_files_found_in_0_Specify_which_to_use_with_the_workspace_argument ,
29- Path . Combine ( ProjectsPath , workspacePath ) ) . Replace ( '/' , Path . DirectorySeparatorChar ) ;
30- var exception = Assert . Throws < FileNotFoundException > ( ( ) => MSBuildWorkspaceFinder . FindWorkspace ( ProjectsPath , workspacePath ) ) ;
39+ testInstance . Path ) . Replace ( '/' , Path . DirectorySeparatorChar ) ;
40+ var exception = Assert . Throws < FileNotFoundException > ( ( ) => MSBuildWorkspaceFinder . FindWorkspace ( testInstance . Path ) ) ;
3141 Assert . Equal ( exceptionMessageStart , exception . Message ) ;
3242 }
3343
3444 [ Fact ]
3545 public void ThrowsException_MultipleMSBuildSolutionFiles ( )
3646 {
37- var workspacePath = "for_workspace_finder/multiple_solutions/" ;
47+ var testInstance = _testAssetsManager
48+ . CopyTestAsset ( testProjectName : "for_workspace_finder/multiple_solutions" , testAssetSubdirectory : "dotnet-format" )
49+ . WithSource ( ) ;
3850 var exceptionMessageStart = string . Format (
3951 Resources . Multiple_MSBuild_solution_files_found_in_0_Specify_which_to_use_with_the_workspace_argument ,
40- Path . Combine ( ProjectsPath , workspacePath ) ) . Replace ( '/' , Path . DirectorySeparatorChar ) ;
41- var exception = Assert . Throws < FileNotFoundException > ( ( ) => MSBuildWorkspaceFinder . FindWorkspace ( ProjectsPath , workspacePath ) ) ;
52+ testInstance . Path ) . Replace ( '/' , Path . DirectorySeparatorChar ) ;
53+ var exception = Assert . Throws < FileNotFoundException > ( ( ) => MSBuildWorkspaceFinder . FindWorkspace ( testInstance . Path ) ) ;
4254 Assert . Equal ( exceptionMessageStart , exception . Message ) ;
4355 }
4456
4557 [ Fact ]
4658 public void ThrowsException_SolutionAndProjectAmbiguity ( )
4759 {
48- var workspacePath = "for_workspace_finder/project_and_solution/" ;
60+ var testInstance = _testAssetsManager
61+ . CopyTestAsset ( testProjectName : "for_workspace_finder/project_and_solution" , testAssetSubdirectory : "dotnet-format" )
62+ . WithSource ( ) ;
4963 var exceptionMessageStart = string . Format (
5064 Resources . Both_a_MSBuild_project_file_and_solution_file_found_in_0_Specify_which_to_use_with_the_workspace_argument ,
51- Path . Combine ( ProjectsPath , workspacePath ) ) . Replace ( '/' , Path . DirectorySeparatorChar ) ;
52- var exception = Assert . Throws < FileNotFoundException > ( ( ) => MSBuildWorkspaceFinder . FindWorkspace ( ProjectsPath , workspacePath ) ) ;
65+ testInstance . Path ) . Replace ( '/' , Path . DirectorySeparatorChar ) ;
66+ var exception = Assert . Throws < FileNotFoundException > ( ( ) => MSBuildWorkspaceFinder . FindWorkspace ( testInstance . Path ) ) ;
5367 Assert . Equal ( exceptionMessageStart , exception . Message ) ;
5468 }
5569
5670 [ Fact ]
5771 public void FindsSolutionByFolder ( )
5872 {
59- const string Path = "for_workspace_finder/single_solution/" ;
73+ var testInstance = _testAssetsManager
74+ . CopyTestAsset ( testProjectName : "for_workspace_finder/single_solution" , testAssetSubdirectory : "dotnet-format" )
75+ . WithSource ( ) ;
6076
61- var ( isSolution , workspacePath ) = MSBuildWorkspaceFinder . FindWorkspace ( ProjectsPath , Path ) ;
77+ var ( isSolution , workspacePath ) = MSBuildWorkspaceFinder . FindWorkspace ( testInstance . Path ) ;
6278
6379 var solutionFileName = System . IO . Path . GetFileName ( workspacePath ) ;
6480 Assert . Equal ( "single_solution.sln" , solutionFileName ) ;
@@ -68,9 +84,11 @@ public void FindsSolutionByFolder()
6884 [ Fact ]
6985 public void FindsSolutionByFilePath ( )
7086 {
71- const string Path = "for_workspace_finder/multiple_solutions/solution_b.sln" ;
87+ var testInstance = _testAssetsManager
88+ . CopyTestAsset ( testProjectName : "for_workspace_finder/multiple_solutions" , testAssetSubdirectory : "dotnet-format" )
89+ . WithSource ( ) ;
7290
73- var ( isSolution , workspacePath ) = MSBuildWorkspaceFinder . FindWorkspace ( ProjectsPath , Path ) ;
91+ var ( isSolution , workspacePath ) = MSBuildWorkspaceFinder . FindWorkspace ( testInstance . Path , "solution_b.sln" ) ;
7492
7593 var solutionFileName = System . IO . Path . GetFileName ( workspacePath ) ;
7694 Assert . Equal ( "solution_b.sln" , solutionFileName ) ;
@@ -80,9 +98,11 @@ public void FindsSolutionByFilePath()
8098 [ Fact ]
8199 public void FindsProjectByFolder ( )
82100 {
83- const string Path = "for_workspace_finder/single_project/" ;
101+ var testInstance = _testAssetsManager
102+ . CopyTestAsset ( testProjectName : "for_workspace_finder/single_project" , testAssetSubdirectory : "dotnet-format" )
103+ . WithSource ( ) ;
84104
85- var ( isSolution , workspacePath ) = MSBuildWorkspaceFinder . FindWorkspace ( ProjectsPath , Path ) ;
105+ var ( isSolution , workspacePath ) = MSBuildWorkspaceFinder . FindWorkspace ( testInstance . Path ) ;
86106
87107 var solutionFileName = System . IO . Path . GetFileName ( workspacePath ) ;
88108 Assert . Equal ( "single_project.csproj" , solutionFileName ) ;
@@ -92,9 +112,11 @@ public void FindsProjectByFolder()
92112 [ Fact ]
93113 public void FindsProjectByFilePath ( )
94114 {
95- const string Path = "for_workspace_finder/multiple_projects/project_b.csproj" ;
115+ var testInstance = _testAssetsManager
116+ . CopyTestAsset ( testProjectName : "for_workspace_finder/multiple_projects" , testAssetSubdirectory : "dotnet-format" )
117+ . WithSource ( ) ;
96118
97- var ( isSolution , workspacePath ) = MSBuildWorkspaceFinder . FindWorkspace ( ProjectsPath , Path ) ;
119+ var ( isSolution , workspacePath ) = MSBuildWorkspaceFinder . FindWorkspace ( testInstance . Path , "project_b.csproj" ) ;
98120
99121 var solutionFileName = System . IO . Path . GetFileName ( workspacePath ) ;
100122 Assert . Equal ( "project_b.csproj" , solutionFileName ) ;
0 commit comments