@@ -10,57 +10,87 @@ namespace System.IO.Abstractions.TestingHelpers
10
10
{
11
11
partial class MockFile
12
12
{
13
+ #if FEATURE_FILE_SPAN
14
+ /// <inheritdoc cref="IFile.AppendAllBytesAsync(string,byte[],CancellationToken)"/>
15
+ public override Task AppendAllBytesAsync ( string path , byte [ ] bytes , CancellationToken cancellationToken = default )
16
+ {
17
+ cancellationToken . ThrowIfCancellationRequested ( ) ;
18
+ AppendAllBytes ( path , bytes ) ;
19
+ return Task . CompletedTask ;
20
+ }
21
+
22
+ /// <inheritdoc cref="IFile.AppendAllBytesAsync(string,ReadOnlyMemory{byte},CancellationToken)"/>
23
+ public override Task AppendAllBytesAsync ( string path , ReadOnlyMemory < byte > bytes , CancellationToken cancellationToken = default )
24
+ {
25
+ return AppendAllBytesAsync ( path , bytes . ToArray ( ) , cancellationToken ) ;
26
+ }
27
+ #endif
13
28
/// <inheritdoc />
14
- public override Task AppendAllLinesAsync ( string path , IEnumerable < string > contents , CancellationToken cancellationToken = default ( CancellationToken ) ) =>
29
+ public override Task AppendAllLinesAsync ( string path , IEnumerable < string > contents , CancellationToken cancellationToken = default ) =>
15
30
AppendAllLinesAsync ( path , contents , MockFileData . DefaultEncoding , cancellationToken ) ;
16
31
17
32
/// <inheritdoc />
18
- public override Task AppendAllLinesAsync ( string path , IEnumerable < string > contents , Encoding encoding , CancellationToken cancellationToken = default ( CancellationToken ) )
33
+ public override Task AppendAllLinesAsync ( string path , IEnumerable < string > contents , Encoding encoding , CancellationToken cancellationToken = default )
19
34
{
20
35
cancellationToken . ThrowIfCancellationRequested ( ) ;
21
36
AppendAllLines ( path , contents , encoding ) ;
22
37
return Task . CompletedTask ;
23
38
}
24
39
25
40
/// <inheritdoc />
26
- public override Task AppendAllTextAsync ( string path , string contents , CancellationToken cancellationToken = default ( CancellationToken ) ) =>
41
+ public override Task AppendAllTextAsync ( string path , string contents , CancellationToken cancellationToken = default ) =>
27
42
AppendAllTextAsync ( path , contents , MockFileData . DefaultEncoding , cancellationToken ) ;
28
43
29
44
30
45
/// <inheritdoc />
31
- public override Task AppendAllTextAsync ( string path , string contents , Encoding encoding , CancellationToken cancellationToken = default ( CancellationToken ) )
46
+ public override Task AppendAllTextAsync ( string path , string contents , Encoding encoding , CancellationToken cancellationToken = default )
32
47
{
33
48
cancellationToken . ThrowIfCancellationRequested ( ) ;
34
49
AppendAllText ( path , contents , encoding ) ;
35
50
return Task . CompletedTask ;
36
51
}
52
+
53
+ #if FEATURE_FILE_SPAN
54
+ /// <inheritdoc cref="IFile.AppendAllTextAsync(string,ReadOnlyMemory{char},CancellationToken)"/>
55
+ public override Task AppendAllTextAsync ( string path , ReadOnlyMemory < char > contents , CancellationToken cancellationToken = default )
56
+ {
57
+ return AppendAllTextAsync ( path , contents . ToString ( ) , cancellationToken ) ;
58
+ }
59
+
60
+ /// <inheritdoc cref="IFile.AppendAllTextAsync(string,ReadOnlyMemory{char},Encoding,CancellationToken)"/>
61
+ public override Task AppendAllTextAsync ( string path , ReadOnlyMemory < char > contents , Encoding encoding ,
62
+ CancellationToken cancellationToken = default )
63
+ {
64
+ return AppendAllTextAsync ( path , contents . ToString ( ) , encoding , cancellationToken ) ;
65
+ }
66
+ #endif
37
67
38
68
/// <inheritdoc />
39
- public override Task < byte [ ] > ReadAllBytesAsync ( string path , CancellationToken cancellationToken = default ( CancellationToken ) )
69
+ public override Task < byte [ ] > ReadAllBytesAsync ( string path , CancellationToken cancellationToken = default )
40
70
{
41
71
cancellationToken . ThrowIfCancellationRequested ( ) ;
42
72
return Task . FromResult ( ReadAllBytes ( path ) ) ;
43
73
}
44
74
45
75
/// <inheritdoc />
46
- public override Task < string [ ] > ReadAllLinesAsync ( string path , CancellationToken cancellationToken = default ( CancellationToken ) ) =>
76
+ public override Task < string [ ] > ReadAllLinesAsync ( string path , CancellationToken cancellationToken = default ) =>
47
77
ReadAllLinesAsync ( path , MockFileData . DefaultEncoding , cancellationToken ) ;
48
78
49
79
/// <inheritdoc />
50
80
51
- public override Task < string [ ] > ReadAllLinesAsync ( string path , Encoding encoding , CancellationToken cancellationToken = default ( CancellationToken ) )
81
+ public override Task < string [ ] > ReadAllLinesAsync ( string path , Encoding encoding , CancellationToken cancellationToken = default )
52
82
{
53
83
cancellationToken . ThrowIfCancellationRequested ( ) ;
54
84
return Task . FromResult ( ReadAllLines ( path , encoding ) ) ;
55
85
}
56
86
57
87
/// <inheritdoc />
58
- public override Task < string > ReadAllTextAsync ( string path , CancellationToken cancellationToken ) =>
88
+ public override Task < string > ReadAllTextAsync ( string path , CancellationToken cancellationToken = default ) =>
59
89
ReadAllTextAsync ( path , MockFileData . DefaultEncoding , cancellationToken ) ;
60
90
61
91
62
92
/// <inheritdoc />
63
- public override Task < string > ReadAllTextAsync ( string path , Encoding encoding , CancellationToken cancellationToken )
93
+ public override Task < string > ReadAllTextAsync ( string path , Encoding encoding , CancellationToken cancellationToken = default )
64
94
{
65
95
cancellationToken . ThrowIfCancellationRequested ( ) ;
66
96
return Task . FromResult ( ReadAllText ( path , encoding ) ) ;
@@ -82,36 +112,59 @@ public override async IAsyncEnumerable<string> ReadLinesAsync(string path, Encod
82
112
#endif
83
113
84
114
/// <inheritdoc />
85
- public override Task WriteAllBytesAsync ( string path , byte [ ] bytes , CancellationToken cancellationToken )
115
+ public override Task WriteAllBytesAsync ( string path , byte [ ] bytes , CancellationToken cancellationToken = default )
86
116
{
87
117
cancellationToken . ThrowIfCancellationRequested ( ) ;
88
118
WriteAllBytes ( path , bytes ) ;
89
119
return Task . CompletedTask ;
90
120
}
121
+
122
+ #if FEATURE_FILE_SPAN
123
+ /// <inheritdoc cref="IFile.WriteAllBytesAsync(string,ReadOnlyMemory{byte},CancellationToken)"/>
124
+ public override Task WriteAllBytesAsync ( string path , ReadOnlyMemory < byte > bytes , CancellationToken cancellationToken = default )
125
+ {
126
+ return WriteAllBytesAsync ( path , bytes . ToArray ( ) , cancellationToken ) ;
127
+ }
128
+ #endif
91
129
92
130
/// <inheritdoc />
93
- public override Task WriteAllLinesAsync ( string path , IEnumerable < string > contents , CancellationToken cancellationToken ) =>
131
+ public override Task WriteAllLinesAsync ( string path , IEnumerable < string > contents , CancellationToken cancellationToken = default ) =>
94
132
WriteAllLinesAsync ( path , contents , MockFileData . DefaultEncoding , cancellationToken ) ;
95
133
96
134
/// <inheritdoc />
97
- public override Task WriteAllLinesAsync ( string path , IEnumerable < string > contents , Encoding encoding , CancellationToken cancellationToken )
135
+ public override Task WriteAllLinesAsync ( string path , IEnumerable < string > contents , Encoding encoding , CancellationToken cancellationToken = default )
98
136
{
99
137
cancellationToken . ThrowIfCancellationRequested ( ) ;
100
138
WriteAllLines ( path , contents , encoding ) ;
101
139
return Task . CompletedTask ;
102
140
}
103
141
104
142
/// <inheritdoc />
105
- public override Task WriteAllTextAsync ( string path , string contents , CancellationToken cancellationToken ) =>
143
+ public override Task WriteAllTextAsync ( string path , string contents , CancellationToken cancellationToken = default ) =>
106
144
WriteAllTextAsync ( path , contents , MockFileData . DefaultEncoding , cancellationToken ) ;
107
145
108
146
/// <inheritdoc />
109
- public override Task WriteAllTextAsync ( string path , string contents , Encoding encoding , CancellationToken cancellationToken )
147
+ public override Task WriteAllTextAsync ( string path , string contents , Encoding encoding , CancellationToken cancellationToken = default )
110
148
{
111
149
cancellationToken . ThrowIfCancellationRequested ( ) ;
112
150
WriteAllText ( path , contents , encoding ) ;
113
151
return Task . CompletedTask ;
114
152
}
153
+
154
+ #if FEATURE_FILE_SPAN
155
+ /// <inheritdoc cref="IFile.WriteAllTextAsync(string,ReadOnlyMemory{char},CancellationToken)"/>
156
+ public override Task WriteAllTextAsync ( string path , ReadOnlyMemory < char > contents , CancellationToken cancellationToken = default )
157
+ {
158
+ return WriteAllTextAsync ( path , contents . ToString ( ) , cancellationToken ) ;
159
+ }
160
+
161
+ /// <inheritdoc cref="IFile.WriteAllTextAsync(string,ReadOnlyMemory{char},Encoding,CancellationToken)"/>
162
+ public override Task WriteAllTextAsync ( string path , ReadOnlyMemory < char > contents , Encoding encoding ,
163
+ CancellationToken cancellationToken = default )
164
+ {
165
+ return WriteAllTextAsync ( path , contents . ToString ( ) , encoding , cancellationToken ) ;
166
+ }
167
+ #endif
115
168
}
116
169
}
117
170
0 commit comments