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