@@ -9,51 +9,53 @@ class AssemblyInfoFileUpdate : IDisposable
99 List < Action > restoreBackupTasks = new List < Action > ( ) ;
1010 List < Action > cleanupBackupTasks = new List < Action > ( ) ;
1111
12- public AssemblyInfoFileUpdate ( Arguments args , string workingDirectory , Dictionary < string , string > variables )
12+ public AssemblyInfoFileUpdate ( Arguments args , string workingDirectory , Dictionary < string , string > variables , IFileSystem fileSystem )
1313 {
1414 if ( ! args . UpdateAssemblyInfo ) return ;
1515
1616 if ( args . Output != OutputType . Json )
1717 Console . WriteLine ( "Updating assembly info files" ) ;
1818
19- var assemblyInfoFiles = GetAssemblyInfoFiles ( workingDirectory , args ) ;
19+ var assemblyInfoFiles = GetAssemblyInfoFiles ( workingDirectory , args , fileSystem ) ;
2020
2121 foreach ( var assemblyInfoFile in assemblyInfoFiles )
2222 {
2323 var backupAssemblyInfo = assemblyInfoFile + ".bak" ;
2424 var localAssemblyInfo = assemblyInfoFile ;
25- File . Copy ( assemblyInfoFile , backupAssemblyInfo , true ) ;
25+ fileSystem . Copy ( assemblyInfoFile , backupAssemblyInfo , true ) ;
2626 restoreBackupTasks . Add ( ( ) =>
2727 {
28- if ( File . Exists ( localAssemblyInfo ) )
29- File . Delete ( localAssemblyInfo ) ;
30- File . Move ( backupAssemblyInfo , localAssemblyInfo ) ;
28+ if ( fileSystem . Exists ( localAssemblyInfo ) )
29+ fileSystem . Delete ( localAssemblyInfo ) ;
30+ fileSystem . Move ( backupAssemblyInfo , localAssemblyInfo ) ;
3131 } ) ;
32- cleanupBackupTasks . Add ( ( ) => File . Delete ( backupAssemblyInfo ) ) ;
32+ cleanupBackupTasks . Add ( ( ) => fileSystem . Delete ( backupAssemblyInfo ) ) ;
3333
3434 var assemblyVersion = string . Format ( "{0}.{1}.0.0" , variables [ VariableProvider . Major ] , variables [ VariableProvider . Minor ] ) ;
3535 var assemblyInfoVersion = variables [ VariableProvider . InformationalVersion ] ;
3636 var assemblyFileVersion = variables [ VariableProvider . AssemblySemVer ] ;
37- var fileContents = File . ReadAllText ( assemblyInfoFile )
37+ var fileContents = fileSystem . ReadAllText ( assemblyInfoFile )
3838 . RegexReplace ( @"AssemblyVersion\(""\d+.\d+.\d+(.\d+|\*)?""\)" , string . Format ( "AssemblyVersion(\" {0}\" )" , assemblyVersion ) )
3939 . RegexReplace ( @"AssemblyInformationalVersion\(""\d+.\d+.\d+(.\d+|\*)?""\)" , string . Format ( "AssemblyInformationalVersion(\" {0}\" )" , assemblyInfoVersion ) )
4040 . RegexReplace ( @"AssemblyFileVersion\(""\d+.\d+.\d+(.\d+|\*)?""\)" , string . Format ( "AssemblyFileVersion(\" {0}\" )" , assemblyFileVersion ) ) ;
4141
42- File . WriteAllText ( assemblyInfoFile , fileContents ) ;
42+ fileSystem . WriteAllText ( assemblyInfoFile , fileContents ) ;
4343 }
4444 }
4545
46- static IEnumerable < string > GetAssemblyInfoFiles ( string workingDirectory , Arguments args )
46+ static IEnumerable < string > GetAssemblyInfoFiles ( string workingDirectory , Arguments args , IFileSystem fileSystem )
4747 {
4848 if ( args . UpdateAssemblyInfoFileName != null )
4949 {
50- if ( File . Exists ( args . UpdateAssemblyInfoFileName ) )
50+ var fullPath = Path . Combine ( workingDirectory , args . UpdateAssemblyInfoFileName ) ;
51+
52+ if ( fileSystem . Exists ( fullPath ) )
5153 {
52- return new [ ] { Path . GetFullPath ( args . UpdateAssemblyInfoFileName ) } ;
54+ return new [ ] { fullPath } ;
5355 }
5456 }
5557
56- return Directory . GetFiles ( workingDirectory , "AssemblyInfo.cs" , SearchOption . AllDirectories ) ;
58+ return fileSystem . DirectoryGetFiles ( workingDirectory , "AssemblyInfo.cs" , SearchOption . AllDirectories ) ;
5759 }
5860
5961 public void Dispose ( )
0 commit comments