1+ using System ;
2+ using System . Globalization ;
13using System . IO ;
4+ using System . Security . Cryptography ;
5+ using System . Text ;
26using System . Threading . Tasks ;
37using GitReleaseManager . Core . Commands ;
48using GitReleaseManager . Core . Helpers ;
@@ -24,7 +28,11 @@ public void Setup()
2428 _fileSystem = new FileSystem ( Substitute . For < BaseSubOptions > ( ) ) ;
2529 _logger = Substitute . For < ILogger > ( ) ;
2630 _command = new InitCommand ( _fileSystem , _logger ) ;
27- _targetDirectory = Path . GetTempPath ( ) ;
31+ _targetDirectory = Path . Combine ( Path . GetTempPath ( ) , Guid . NewGuid ( ) . ToString ( ) ) ;
32+ if ( ! Directory . Exists ( _targetDirectory ) )
33+ {
34+ Directory . CreateDirectory ( _targetDirectory ) ;
35+ }
2836 }
2937
3038 [ Test ]
@@ -46,5 +54,44 @@ public async Task Should_Execute_Command()
4654 File . Delete ( configFilePath ) ;
4755 }
4856 }
57+
58+ [ Test ]
59+ public async Task Should_Not_Execute_Command_For_Legacy_FileName ( )
60+ {
61+ var options = new InitSubOptions { TargetDirectory = _targetDirectory } ;
62+
63+ var configFilePath = Path . Combine ( _targetDirectory , "GitReleaseManager.yaml" ) ;
64+ var configNewFilePath = Path . Combine ( _targetDirectory , "GitReleaseManager.yml" ) ;
65+ if ( File . Exists ( configNewFilePath ) )
66+ {
67+ File . Delete ( configNewFilePath ) ;
68+ }
69+
70+ File . WriteAllText ( configFilePath , "s" ) ;
71+ var expectedHash = GetHash ( configFilePath ) ;
72+
73+ var result = await _command . Execute ( options ) . ConfigureAwait ( false ) ;
74+ result . ShouldBe ( 0 ) ; // Should this perhaps return 1
75+
76+ var actualHash = GetHash ( configFilePath ) ;
77+ actualHash . ShouldBe ( expectedHash ) ;
78+ File . Exists ( configNewFilePath ) . ShouldBeFalse ( ) ;
79+ }
80+
81+ private static string GetHash ( string filePath )
82+ {
83+ using ( var sha256 = SHA256 . Create ( ) )
84+ {
85+ var bytes = sha256 . ComputeHash ( File . ReadAllBytes ( filePath ) ) ;
86+
87+ var builder = new StringBuilder ( ) ;
88+ foreach ( var b in bytes )
89+ {
90+ builder . AppendFormat ( CultureInfo . InvariantCulture , "{0:x2}" , b ) ;
91+ }
92+
93+ return builder . ToString ( ) ;
94+ }
95+ }
4996 }
5097}
0 commit comments