@@ -9,42 +9,49 @@ namespace GitVersionCore.Tests
99{
1010 public class TestFileSystem : IFileSystem
1111 {
12- private readonly Dictionary < string , byte [ ] > fileSystem = new Dictionary < string , byte [ ] > ( ) ;
12+ private static IEqualityComparer < string > fileSystemCasingComparer = System . Environment . OSVersion . Platform == PlatformID . Unix ? StringComparer . Ordinal : StringComparer . OrdinalIgnoreCase ;
13+ private readonly Dictionary < string , byte [ ] > fileSystem = new Dictionary < string , byte [ ] > ( fileSystemCasingComparer ) ;
1314
1415 public void Copy ( string @from , string to , bool overwrite )
1516 {
16- if ( fileSystem . ContainsKey ( to ) )
17+ var fromPath = Path . GetFullPath ( @from ) ;
18+ var toPath = Path . GetFullPath ( to ) ;
19+ if ( fileSystem . ContainsKey ( toPath ) )
1720 {
1821 if ( overwrite )
19- fileSystem . Remove ( to ) ;
22+ fileSystem . Remove ( toPath ) ;
2023 else
2124 throw new IOException ( "File already exists" ) ;
2225 }
2326
24- if ( ! fileSystem . TryGetValue ( from , out var source ) )
25- throw new FileNotFoundException ( $ "The source file '{ @from } ' was not found", from ) ;
27+ if ( ! fileSystem . TryGetValue ( fromPath , out var source ) )
28+ throw new FileNotFoundException ( $ "The source file '{ fromPath } ' was not found", from ) ;
2629
27- fileSystem . Add ( to , source ) ;
30+ fileSystem . Add ( toPath , source ) ;
2831 }
2932
3033 public void Move ( string @from , string to )
3134 {
35+ var fromPath = Path . GetFullPath ( @from ) ;
3236 Copy ( from , to , false ) ;
33- fileSystem . Remove ( from ) ;
37+ fileSystem . Remove ( fromPath ) ;
3438 }
3539
3640 public bool Exists ( string file )
3741 {
38- return fileSystem . ContainsKey ( file ) ;
42+ var path = Path . GetFullPath ( file ) ;
43+ return fileSystem . ContainsKey ( path ) ;
3944 }
4045
4146 public void Delete ( string path )
4247 {
43- fileSystem . Remove ( path ) ;
48+ var fullPath = Path . GetFullPath ( path ) ;
49+ fileSystem . Remove ( fullPath ) ;
4450 }
4551
46- public string ReadAllText ( string path )
52+ public string ReadAllText ( string file )
4753 {
54+ var path = Path . GetFullPath ( file ) ;
4855 if ( ! fileSystem . TryGetValue ( path , out var content ) )
4956 throw new FileNotFoundException ( $ "The file '{ path } ' was not found", path ) ;
5057
@@ -54,15 +61,17 @@ public string ReadAllText(string path)
5461
5562 public void WriteAllText ( string file , string fileContents )
5663 {
57- var encoding = fileSystem . ContainsKey ( file )
58- ? EncodingHelper . DetectEncoding ( fileSystem [ file ] ) ?? Encoding . UTF8
64+ var path = Path . GetFullPath ( file ) ;
65+ var encoding = fileSystem . ContainsKey ( path )
66+ ? EncodingHelper . DetectEncoding ( fileSystem [ path ] ) ?? Encoding . UTF8
5967 : Encoding . UTF8 ;
60- WriteAllText ( file , fileContents , encoding ) ;
68+ WriteAllText ( path , fileContents , encoding ) ;
6169 }
6270
6371 public void WriteAllText ( string file , string fileContents , Encoding encoding )
6472 {
65- fileSystem [ file ] = encoding . GetBytes ( fileContents ) ;
73+ var path = Path . GetFullPath ( file ) ;
74+ fileSystem [ path ] = encoding . GetBytes ( fileContents ) ;
6675 }
6776
6877 public IEnumerable < string > DirectoryGetFiles ( string directory , string searchPattern , SearchOption searchOption )
@@ -75,8 +84,9 @@ public Stream OpenWrite(string path)
7584 return new TestStream ( path , this ) ;
7685 }
7786
78- public Stream OpenRead ( string path )
87+ public Stream OpenRead ( string file )
7988 {
89+ var path = Path . GetFullPath ( file ) ;
8090 if ( fileSystem . ContainsKey ( path ) )
8191 {
8292 var content = fileSystem [ path ] ;
@@ -86,8 +96,9 @@ public Stream OpenRead(string path)
8696 throw new FileNotFoundException ( "File not found." , path ) ;
8797 }
8898
89- public void CreateDirectory ( string path )
99+ public void CreateDirectory ( string directory )
90100 {
101+ var path = Path . GetFullPath ( directory ) ;
91102 if ( fileSystem . ContainsKey ( path ) )
92103 {
93104 fileSystem [ path ] = new byte [ 0 ] ;
@@ -98,8 +109,9 @@ public void CreateDirectory(string path)
98109 }
99110 }
100111
101- public bool DirectoryExists ( string path )
112+ public bool DirectoryExists ( string directory )
102113 {
114+ var path = Path . GetFullPath ( directory ) ;
103115 return fileSystem . ContainsKey ( path ) ;
104116 }
105117
0 commit comments