@@ -28,10 +28,7 @@ public async Task FindProjectsForFilePaths_ShouldFindSingleProject()
2828 await this . Repository . CreateTextFileAsync ( targetFilePath , "// Initial content" ) ;
2929
3030 // Act
31- var projects = this . Provider . GetReferencingProjects ( new [ ]
32- {
33- targetFilePath ,
34- } )
31+ var projects = this . Provider . GetReferencingProjects ( new [ ] { targetFilePath , } )
3532 . ToArray ( ) ;
3633
3734 // Assert
@@ -55,10 +52,7 @@ public async Task FindProjectsForFilePaths_WithMultipleFiles_ShouldFindSinglePro
5552 await this . Repository . CreateTextFileAsync ( targetFilePath2 , "// Other content" ) ;
5653
5754 // Act
58- var projects = this . Provider . GetReferencingProjects ( new [ ]
59- {
60- targetFilePath , targetFilePath2
61- } )
55+ var projects = this . Provider . GetReferencingProjects ( new [ ] { targetFilePath , targetFilePath2 } )
6256 . ToArray ( ) ;
6357
6458 // Assert
@@ -82,10 +76,7 @@ public async Task FindProjectsForFilePaths_ShouldFindMultipleProject()
8276 await this . Repository . CreateTextFileAsync ( targetFilePath2 , "// Initial content" ) ;
8377
8478 // Act
85- var projects = this . Provider . GetReferencingProjects ( new [ ]
86- {
87- targetFilePath , targetFilePath2
88- } )
79+ var projects = this . Provider . GetReferencingProjects ( new [ ] { targetFilePath , targetFilePath2 } )
8980 . OrderBy ( p => p . GetProjectName ( ) )
9081 . ToArray ( ) ;
9182
@@ -97,5 +88,34 @@ public async Task FindProjectsForFilePaths_ShouldFindMultipleProject()
9788 p => Assert . Equal ( project1Node , p ) ,
9889 p => Assert . Equal ( project2Node , p ) ) ;
9990 }
91+
92+ /// <summary>
93+ /// Covers the case where the project references a file outside the project directory
94+ /// using paths that are not normalized.
95+ /// affected should compare paths normmalized (Path.GetFullPath) so that the comparison works.
96+ /// </summary>
97+ [ Fact ]
98+ public async Task FindProjectsWithNonFullPathFilePaths_ShouldFindSingleProject ( )
99+ {
100+ // Arrange
101+ var project1 = Repository . CreateCsProject ( "context/Project1" , p =>
102+ {
103+ p . AddItem ( "None" , Path . Combine ( Repository . Path , "context/Project1" , "../../subdir/file.json" ) ) ;
104+ } ) ;
105+
106+ var targetFilePath = Path . Join ( this . Repository . Path , "/subdir/" , "file.json" ) ;
107+ Directory . CreateDirectory ( Path . Join ( this . Repository . Path , "/subdir/" ) ) ;
108+ await this . Repository . CreateTextFileAsync ( targetFilePath , "// Initial content" ) ;
109+
110+ // Act
111+ var projects = this . Provider . GetReferencingProjects ( new [ ] { targetFilePath , } )
112+ . ToArray ( ) ;
113+
114+ // Assert
115+ Assert . Single ( projects ) ;
116+
117+ var project1Node = Graph . FindNodeByPath ( project1 . FullPath ) ;
118+ Assert . Equal ( project1Node , projects . Single ( ) ) ;
119+ }
100120 }
101121}
0 commit comments