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
77 {
88 public static string FindCommonPath ( IEnumerable < string > paths )
99 {
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 ) ;
1317
1418 var commonParent = deepestPath ;
15- foreach ( var path in pathsArray )
19+ foreach ( var path in parentsArray )
1620 {
1721 var cp = path . Elements . Any ( ) ? commonParent . GetCommonParent ( path ) : null ;
1822 if ( cp != null )
Original file line number Diff line number Diff line change @@ -27,18 +27,18 @@ public void TestFixtureTearDown()
2727 }
2828
2929 [ Test ]
30- public void ShouldErrorIfEmpty ( )
30+ public void ShouldNotErrorIfEmpty ( )
3131 {
3232 Action item ;
3333
3434 item = ( ) => { FileSystemHelpers . FindCommonPath ( new List < string > ( ) ) ; } ;
35- item . ShouldThrow < InvalidOperationException > ( ) ;
35+ item . ShouldNotThrow < InvalidOperationException > ( ) ;
3636
3737 item = ( ) => { FileSystemHelpers . FindCommonPath ( new List < string > { null } ) ; } ;
38- item . ShouldThrow < InvalidOperationException > ( ) ;
38+ item . ShouldNotThrow < InvalidOperationException > ( ) ;
3939
4040 item = ( ) => { FileSystemHelpers . FindCommonPath ( new List < string > { "" } ) ; } ;
41- item . ShouldThrow < InvalidOperationException > ( ) ;
41+ item . ShouldNotThrow < InvalidOperationException > ( ) ;
4242 }
4343
4444 [ Test ]
You can’t perform that action at this time.
0 commit comments