@@ -9,42 +9,48 @@ namespace GitVersionCore.Tests
99{
1010 public class TestFileSystem : IFileSystem
1111 {
12- Dictionary < string , byte [ ] > fileSystem = new Dictionary < string , byte [ ] > ( ) ;
12+ Dictionary < string , byte [ ] > fileSystem = new Dictionary < string , byte [ ] > ( StringComparer . OrdinalIgnoreCase ) ;
1313
1414 public void Copy ( string @from , string to , bool overwrite )
1515 {
16- if ( fileSystem . ContainsKey ( to ) )
16+ var fromPath = Path . GetFullPath ( @from ) ;
17+ var toPath = Path . GetFullPath ( to ) ;
18+ if ( fileSystem . ContainsKey ( toPath ) )
1719 {
1820 if ( overwrite )
19- fileSystem . Remove ( to ) ;
21+ fileSystem . Remove ( toPath ) ;
2022 else
2123 throw new IOException ( "File already exists" ) ;
2224 }
2325
24- if ( ! fileSystem . TryGetValue ( from , out var source ) )
25- throw new FileNotFoundException ( $ "The source file '{ @from } ' was not found", from ) ;
26+ if ( ! fileSystem . TryGetValue ( fromPath , out var source ) )
27+ throw new FileNotFoundException ( $ "The source file '{ fromPath } ' was not found", from ) ;
2628
27- fileSystem . Add ( to , source ) ;
29+ fileSystem . Add ( toPath , source ) ;
2830 }
2931
3032 public void Move ( string @from , string to )
3133 {
34+ var fromPath = Path . GetFullPath ( @from ) ;
3235 Copy ( from , to , false ) ;
33- fileSystem . Remove ( from ) ;
36+ fileSystem . Remove ( fromPath ) ;
3437 }
3538
3639 public bool Exists ( string file )
3740 {
38- return fileSystem . ContainsKey ( file ) ;
41+ var path = Path . GetFullPath ( file ) ;
42+ return fileSystem . ContainsKey ( path ) ;
3943 }
4044
4145 public void Delete ( string path )
4246 {
43- fileSystem . Remove ( path ) ;
47+ var fullPath = Path . GetFullPath ( path ) ;
48+ fileSystem . Remove ( fullPath ) ;
4449 }
4550
46- public string ReadAllText ( string path )
51+ public string ReadAllText ( string file )
4752 {
53+ var path = Path . GetFullPath ( file ) ;
4854 if ( ! fileSystem . TryGetValue ( path , out var content ) )
4955 throw new FileNotFoundException ( $ "The file '{ path } ' was not found", path ) ;
5056
@@ -54,15 +60,17 @@ public string ReadAllText(string path)
5460
5561 public void WriteAllText ( string file , string fileContents )
5662 {
57- var encoding = fileSystem . ContainsKey ( file )
58- ? EncodingHelper . DetectEncoding ( fileSystem [ file ] ) ?? Encoding . UTF8
63+ var path = Path . GetFullPath ( file ) ;
64+ var encoding = fileSystem . ContainsKey ( path )
65+ ? EncodingHelper . DetectEncoding ( fileSystem [ path ] ) ?? Encoding . UTF8
5966 : Encoding . UTF8 ;
60- WriteAllText ( file , fileContents , encoding ) ;
67+ WriteAllText ( path , fileContents , encoding ) ;
6168 }
6269
6370 public void WriteAllText ( string file , string fileContents , Encoding encoding )
6471 {
65- fileSystem [ file ] = encoding . GetBytes ( fileContents ) ;
72+ var path = Path . GetFullPath ( file ) ;
73+ fileSystem [ path ] = encoding . GetBytes ( fileContents ) ;
6674 }
6775
6876 public IEnumerable < string > DirectoryGetFiles ( string directory , string searchPattern , SearchOption searchOption )
@@ -75,8 +83,9 @@ public Stream OpenWrite(string path)
7583 return new TestStream ( path , this ) ;
7684 }
7785
78- public Stream OpenRead ( string path )
86+ public Stream OpenRead ( string file )
7987 {
88+ var path = Path . GetFullPath ( file ) ;
8089 if ( fileSystem . ContainsKey ( path ) )
8190 {
8291 var content = fileSystem [ path ] ;
@@ -86,8 +95,9 @@ public Stream OpenRead(string path)
8695 throw new FileNotFoundException ( "File not found." , path ) ;
8796 }
8897
89- public void CreateDirectory ( string path )
98+ public void CreateDirectory ( string directory )
9099 {
100+ var path = Path . GetFullPath ( directory ) ;
91101 if ( fileSystem . ContainsKey ( path ) )
92102 {
93103 fileSystem [ path ] = new byte [ 0 ] ;
@@ -98,8 +108,9 @@ public void CreateDirectory(string path)
98108 }
99109 }
100110
101- public bool DirectoryExists ( string path )
111+ public bool DirectoryExists ( string directory )
102112 {
113+ var path = Path . GetFullPath ( directory ) ;
103114 return fileSystem . ContainsKey ( path ) ;
104115 }
105116
0 commit comments