1
+ using System ;
2
+ using System . Globalization ;
1
3
using System . IO ;
4
+ using System . Security . Cryptography ;
5
+ using System . Text ;
2
6
using System . Threading . Tasks ;
3
7
using GitReleaseManager . Core . Commands ;
4
8
using GitReleaseManager . Core . Helpers ;
@@ -24,7 +28,11 @@ public void Setup()
24
28
_fileSystem = new FileSystem ( Substitute . For < BaseSubOptions > ( ) ) ;
25
29
_logger = Substitute . For < ILogger > ( ) ;
26
30
_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
+ }
28
36
}
29
37
30
38
[ Test ]
@@ -46,5 +54,44 @@ public async Task Should_Execute_Command()
46
54
File . Delete ( configFilePath ) ;
47
55
}
48
56
}
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
+ }
49
96
}
50
97
}
0 commit comments