This repository was archived by the owner on Dec 5, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -7,12 +7,16 @@ static class FileSystemHelpers
7
7
{
8
8
public static string FindCommonPath ( IEnumerable < string > paths )
9
9
{
10
- var pathsArray = paths . Where ( s => s != null ) . Select ( s => s . ToNPath ( ) . Parent ) . ToArray ( ) ;
11
- var maxDepth = pathsArray . Max ( path => path . Depth ) ;
12
- var deepestPath = pathsArray . First ( path => path . Depth == maxDepth ) ;
10
+ var parentPaths = paths . Where ( s => ! string . IsNullOrEmpty ( s ) ) . Select ( s => s . ToNPath ( ) . Parent ) ;
11
+ if ( ! parentPaths . Any ( ) )
12
+ return null ;
13
+
14
+ var parentsArray = parentPaths . ToArray ( ) ;
15
+ var maxDepth = parentsArray . Max ( path => path . Depth ) ;
16
+ var deepestPath = parentsArray . First ( path => path . Depth == maxDepth ) ;
13
17
14
18
var commonParent = deepestPath ;
15
- foreach ( var path in pathsArray )
19
+ foreach ( var path in parentsArray )
16
20
{
17
21
var cp = path . Elements . Any ( ) ? commonParent . GetCommonParent ( path ) : null ;
18
22
if ( cp != null )
Original file line number Diff line number Diff line change @@ -27,18 +27,18 @@ public void TestFixtureTearDown()
27
27
}
28
28
29
29
[ Test ]
30
- public void ShouldErrorIfEmpty ( )
30
+ public void ShouldNotErrorIfEmpty ( )
31
31
{
32
32
Action item ;
33
33
34
34
item = ( ) => { FileSystemHelpers . FindCommonPath ( new List < string > ( ) ) ; } ;
35
- item . ShouldThrow < InvalidOperationException > ( ) ;
35
+ item . ShouldNotThrow < InvalidOperationException > ( ) ;
36
36
37
37
item = ( ) => { FileSystemHelpers . FindCommonPath ( new List < string > { null } ) ; } ;
38
- item . ShouldThrow < InvalidOperationException > ( ) ;
38
+ item . ShouldNotThrow < InvalidOperationException > ( ) ;
39
39
40
40
item = ( ) => { FileSystemHelpers . FindCommonPath ( new List < string > { "" } ) ; } ;
41
- item . ShouldThrow < InvalidOperationException > ( ) ;
41
+ item . ShouldNotThrow < InvalidOperationException > ( ) ;
42
42
}
43
43
44
44
[ Test ]
You can’t perform that action at this time.
0 commit comments