@@ -9,42 +9,48 @@ namespace GitVersionCore.Tests
9
9
{
10
10
public class TestFileSystem : IFileSystem
11
11
{
12
- private readonly Dictionary < string , byte [ ] > fileSystem = new Dictionary < string , byte [ ] > ( ) ;
12
+ private readonly Dictionary < string , byte [ ] > fileSystem = new Dictionary < string , byte [ ] > ( StringComparer . OrdinalIgnoreCase ) ;
13
13
14
14
public void Copy ( string @from , string to , bool overwrite )
15
15
{
16
- if ( fileSystem . ContainsKey ( to ) )
16
+ var fromPath = Path . GetFullPath ( @from ) ;
17
+ var toPath = Path . GetFullPath ( to ) ;
18
+ if ( fileSystem . ContainsKey ( toPath ) )
17
19
{
18
20
if ( overwrite )
19
- fileSystem . Remove ( to ) ;
21
+ fileSystem . Remove ( toPath ) ;
20
22
else
21
23
throw new IOException ( "File already exists" ) ;
22
24
}
23
25
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 ) ;
26
28
27
- fileSystem . Add ( to , source ) ;
29
+ fileSystem . Add ( toPath , source ) ;
28
30
}
29
31
30
32
public void Move ( string @from , string to )
31
33
{
34
+ var fromPath = Path . GetFullPath ( @from ) ;
32
35
Copy ( from , to , false ) ;
33
- fileSystem . Remove ( from ) ;
36
+ fileSystem . Remove ( fromPath ) ;
34
37
}
35
38
36
39
public bool Exists ( string file )
37
40
{
38
- return fileSystem . ContainsKey ( file ) ;
41
+ var path = Path . GetFullPath ( file ) ;
42
+ return fileSystem . ContainsKey ( path ) ;
39
43
}
40
44
41
45
public void Delete ( string path )
42
46
{
43
- fileSystem . Remove ( path ) ;
47
+ var fullPath = Path . GetFullPath ( path ) ;
48
+ fileSystem . Remove ( fullPath ) ;
44
49
}
45
50
46
- public string ReadAllText ( string path )
51
+ public string ReadAllText ( string file )
47
52
{
53
+ var path = Path . GetFullPath ( file ) ;
48
54
if ( ! fileSystem . TryGetValue ( path , out var content ) )
49
55
throw new FileNotFoundException ( $ "The file '{ path } ' was not found", path ) ;
50
56
@@ -54,15 +60,17 @@ public string ReadAllText(string path)
54
60
55
61
public void WriteAllText ( string file , string fileContents )
56
62
{
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
59
66
: Encoding . UTF8 ;
60
- WriteAllText ( file , fileContents , encoding ) ;
67
+ WriteAllText ( path , fileContents , encoding ) ;
61
68
}
62
69
63
70
public void WriteAllText ( string file , string fileContents , Encoding encoding )
64
71
{
65
- fileSystem [ file ] = encoding . GetBytes ( fileContents ) ;
72
+ var path = Path . GetFullPath ( file ) ;
73
+ fileSystem [ path ] = encoding . GetBytes ( fileContents ) ;
66
74
}
67
75
68
76
public IEnumerable < string > DirectoryGetFiles ( string directory , string searchPattern , SearchOption searchOption )
@@ -75,8 +83,9 @@ public Stream OpenWrite(string path)
75
83
return new TestStream ( path , this ) ;
76
84
}
77
85
78
- public Stream OpenRead ( string path )
86
+ public Stream OpenRead ( string file )
79
87
{
88
+ var path = Path . GetFullPath ( file ) ;
80
89
if ( fileSystem . ContainsKey ( path ) )
81
90
{
82
91
var content = fileSystem [ path ] ;
@@ -86,8 +95,9 @@ public Stream OpenRead(string path)
86
95
throw new FileNotFoundException ( "File not found." , path ) ;
87
96
}
88
97
89
- public void CreateDirectory ( string path )
98
+ public void CreateDirectory ( string directory )
90
99
{
100
+ var path = Path . GetFullPath ( directory ) ;
91
101
if ( fileSystem . ContainsKey ( path ) )
92
102
{
93
103
fileSystem [ path ] = new byte [ 0 ] ;
@@ -98,8 +108,9 @@ public void CreateDirectory(string path)
98
108
}
99
109
}
100
110
101
- public bool DirectoryExists ( string path )
111
+ public bool DirectoryExists ( string directory )
102
112
{
113
+ var path = Path . GetFullPath ( directory ) ;
103
114
return fileSystem . ContainsKey ( path ) ;
104
115
}
105
116
0 commit comments