@@ -44,9 +44,11 @@ async Task Act() =>
44
44
public async Task AppendAllTextAsync_ExistingFile_ShouldAppendLinesToFile (
45
45
string path , string previousContents , string contents )
46
46
{
47
- await FileSystem . File . AppendAllTextAsync ( path , previousContents , TestContext . Current . CancellationToken ) ;
47
+ await FileSystem . File . AppendAllTextAsync ( path , previousContents ,
48
+ TestContext . Current . CancellationToken ) ;
48
49
49
- await FileSystem . File . AppendAllTextAsync ( path , contents , TestContext . Current . CancellationToken ) ;
50
+ await FileSystem . File . AppendAllTextAsync ( path , contents ,
51
+ TestContext . Current . CancellationToken ) ;
50
52
51
53
await That ( FileSystem . File . Exists ( path ) ) . IsTrue ( ) ;
52
54
await That ( FileSystem . File . ReadAllText ( path ) ) . IsEqualTo ( previousContents + contents ) ;
@@ -61,7 +63,8 @@ public async Task AppendAllTextAsync_MissingDirectory_ShouldThrowDirectoryNotFou
61
63
62
64
async Task Act ( )
63
65
{
64
- await FileSystem . File . AppendAllTextAsync ( filePath , contents , TestContext . Current . CancellationToken ) ;
66
+ await FileSystem . File . AppendAllTextAsync ( filePath , contents ,
67
+ TestContext . Current . CancellationToken ) ;
65
68
}
66
69
67
70
await That ( Act ) . Throws < DirectoryNotFoundException > ( ) . WithHResult ( - 2147024893 ) ;
@@ -72,7 +75,8 @@ async Task Act()
72
75
public async Task AppendAllTextAsync_MissingFile_ShouldCreateFile (
73
76
string path , string contents )
74
77
{
75
- await FileSystem . File . AppendAllTextAsync ( path , contents , TestContext . Current . CancellationToken ) ;
78
+ await FileSystem . File . AppendAllTextAsync ( path , contents ,
79
+ TestContext . Current . CancellationToken ) ;
76
80
77
81
await That ( FileSystem . File . Exists ( path ) ) . IsTrue ( ) ;
78
82
await That ( FileSystem . File . ReadAllText ( path ) ) . IsEqualTo ( contents ) ;
@@ -84,7 +88,8 @@ public async Task AppendAllTextAsync_ShouldNotEndWithNewline(string path)
84
88
{
85
89
string contents = "foo" ;
86
90
87
- await FileSystem . File . AppendAllTextAsync ( path , contents , TestContext . Current . CancellationToken ) ;
91
+ await FileSystem . File . AppendAllTextAsync ( path , contents ,
92
+ TestContext . Current . CancellationToken ) ;
88
93
89
94
await That ( FileSystem . File . Exists ( path ) ) . IsTrue ( ) ;
90
95
await That ( FileSystem . File . ReadAllText ( path ) ) . IsEqualTo ( contents ) ;
@@ -100,7 +105,8 @@ public async Task
100
105
101
106
async Task Act ( )
102
107
{
103
- await FileSystem . File . AppendAllTextAsync ( path , contents , TestContext . Current . CancellationToken ) ;
108
+ await FileSystem . File . AppendAllTextAsync ( path , contents ,
109
+ TestContext . Current . CancellationToken ) ;
104
110
}
105
111
106
112
await That ( Act ) . Throws < UnauthorizedAccessException > ( ) . WithHResult ( - 2147024891 ) ;
@@ -114,13 +120,27 @@ public async Task AppendAllTextAsync_WithDifferentEncoding_ShouldNotReturnWritte
114
120
string contents , Encoding writeEncoding , Encoding readEncoding )
115
121
{
116
122
string path = new Fixture ( ) . Create < string > ( ) ;
117
- await FileSystem . File . AppendAllTextAsync ( path , contents , writeEncoding , TestContext . Current . CancellationToken ) ;
123
+ await FileSystem . File . AppendAllTextAsync ( path , contents , writeEncoding ,
124
+ TestContext . Current . CancellationToken ) ;
118
125
119
126
string [ ] result = FileSystem . File . ReadAllLines ( path , readEncoding ) ;
120
127
121
128
await That ( result ) . IsNotEqualTo ( [ contents ] ) ;
122
129
}
123
130
131
+ [ Theory ]
132
+ [ AutoData ]
133
+ public async Task AppendAllTextAsync_WithoutEncoding_ShouldUseUtf8 (
134
+ string path )
135
+ {
136
+ string contents = "breuß" ;
137
+
138
+ await FileSystem . File . AppendAllTextAsync ( path , contents , CancellationToken . None ) ;
139
+
140
+ byte [ ] bytes = FileSystem . File . ReadAllBytes ( path ) ;
141
+ await That ( bytes . Length ) . IsEqualTo ( 6 ) ;
142
+ }
143
+
124
144
#if FEATURE_FILE_SPAN
125
145
[ Theory ]
126
146
[ AutoData ]
@@ -146,7 +166,8 @@ public async Task
146
166
cts . Cancel ( ) ;
147
167
148
168
async Task Act ( ) =>
149
- await FileSystem . File . AppendAllTextAsync ( path , contents . AsMemory ( ) , Encoding . UTF8 , cts . Token ) ;
169
+ await FileSystem . File . AppendAllTextAsync ( path , contents . AsMemory ( ) , Encoding . UTF8 ,
170
+ cts . Token ) ;
150
171
151
172
await That ( Act ) . Throws < TaskCanceledException > ( ) . WithHResult ( - 2146233029 ) ;
152
173
}
@@ -156,24 +177,28 @@ async Task Act() =>
156
177
public async Task AppendAllTextAsync_ReadOnlyMemory_ExistingFile_ShouldAppendLinesToFile (
157
178
string path , string previousContents , string contents )
158
179
{
159
- await FileSystem . File . AppendAllTextAsync ( path , previousContents , TestContext . Current . CancellationToken ) ;
180
+ await FileSystem . File . AppendAllTextAsync ( path , previousContents ,
181
+ TestContext . Current . CancellationToken ) ;
160
182
161
- await FileSystem . File . AppendAllTextAsync ( path , contents . AsMemory ( ) , TestContext . Current . CancellationToken ) ;
183
+ await FileSystem . File . AppendAllTextAsync ( path , contents . AsMemory ( ) ,
184
+ TestContext . Current . CancellationToken ) ;
162
185
163
186
await That ( FileSystem . File . Exists ( path ) ) . IsTrue ( ) ;
164
187
await That ( FileSystem . File . ReadAllText ( path ) ) . IsEqualTo ( previousContents + contents ) ;
165
188
}
166
189
167
190
[ Theory ]
168
191
[ AutoData ]
169
- public async Task AppendAllTextAsync_ReadOnlyMemory_MissingDirectory_ShouldThrowDirectoryNotFoundException (
170
- string missingPath , string fileName , string contents )
192
+ public async Task
193
+ AppendAllTextAsync_ReadOnlyMemory_MissingDirectory_ShouldThrowDirectoryNotFoundException (
194
+ string missingPath , string fileName , string contents )
171
195
{
172
196
string filePath = FileSystem . Path . Combine ( missingPath , fileName ) ;
173
197
174
198
async Task Act ( )
175
199
{
176
- await FileSystem . File . AppendAllTextAsync ( filePath , contents . AsMemory ( ) , TestContext . Current . CancellationToken ) ;
200
+ await FileSystem . File . AppendAllTextAsync ( filePath , contents . AsMemory ( ) ,
201
+ TestContext . Current . CancellationToken ) ;
177
202
}
178
203
179
204
await That ( Act ) . Throws < DirectoryNotFoundException > ( ) . WithHResult ( - 2147024893 ) ;
@@ -184,7 +209,8 @@ async Task Act()
184
209
public async Task AppendAllTextAsync_ReadOnlyMemory_MissingFile_ShouldCreateFile (
185
210
string path , string contents )
186
211
{
187
- await FileSystem . File . AppendAllTextAsync ( path , contents . AsMemory ( ) , TestContext . Current . CancellationToken ) ;
212
+ await FileSystem . File . AppendAllTextAsync ( path , contents . AsMemory ( ) ,
213
+ TestContext . Current . CancellationToken ) ;
188
214
189
215
await That ( FileSystem . File . Exists ( path ) ) . IsTrue ( ) ;
190
216
await That ( FileSystem . File . ReadAllText ( path ) ) . IsEqualTo ( contents ) ;
@@ -196,7 +222,8 @@ public async Task AppendAllTextAsync_ReadOnlyMemory_ShouldNotEndWithNewline(stri
196
222
{
197
223
string contents = "foo" ;
198
224
199
- await FileSystem . File . AppendAllTextAsync ( path , contents . AsMemory ( ) , TestContext . Current . CancellationToken ) ;
225
+ await FileSystem . File . AppendAllTextAsync ( path , contents . AsMemory ( ) ,
226
+ TestContext . Current . CancellationToken ) ;
200
227
201
228
await That ( FileSystem . File . Exists ( path ) ) . IsTrue ( ) ;
202
229
await That ( FileSystem . File . ReadAllText ( path ) ) . IsEqualTo ( contents ) ;
@@ -212,7 +239,8 @@ public async Task
212
239
213
240
async Task Act ( )
214
241
{
215
- await FileSystem . File . AppendAllTextAsync ( path , contents . AsMemory ( ) , TestContext . Current . CancellationToken ) ;
242
+ await FileSystem . File . AppendAllTextAsync ( path , contents . AsMemory ( ) ,
243
+ TestContext . Current . CancellationToken ) ;
216
244
}
217
245
218
246
await That ( Act ) . Throws < UnauthorizedAccessException > ( ) . WithHResult ( - 2147024891 ) ;
@@ -222,16 +250,31 @@ async Task Act()
222
250
223
251
[ Theory ]
224
252
[ ClassData ( typeof ( TestDataGetEncodingDifference ) ) ]
225
- public async Task AppendAllTextAsync_ReadOnlyMemory_WithDifferentEncoding_ShouldNotReturnWrittenText (
226
- string contents , Encoding writeEncoding , Encoding readEncoding )
253
+ public async Task
254
+ AppendAllTextAsync_ReadOnlyMemory_WithDifferentEncoding_ShouldNotReturnWrittenText (
255
+ string contents , Encoding writeEncoding , Encoding readEncoding )
227
256
{
228
257
string path = new Fixture ( ) . Create < string > ( ) ;
229
- await FileSystem . File . AppendAllTextAsync ( path , contents . AsMemory ( ) , writeEncoding , TestContext . Current . CancellationToken ) ;
258
+ await FileSystem . File . AppendAllTextAsync ( path , contents . AsMemory ( ) , writeEncoding ,
259
+ TestContext . Current . CancellationToken ) ;
230
260
231
261
string [ ] result = FileSystem . File . ReadAllLines ( path , readEncoding ) ;
232
262
233
263
await That ( result ) . IsNotEqualTo ( [ contents ] ) ;
234
264
}
265
+
266
+ [ Theory ]
267
+ [ AutoData ]
268
+ public async Task AppendAllTextAsync_ReadOnlyMemory_WithoutEncoding_ShouldUseUtf8 (
269
+ string path )
270
+ {
271
+ string contents = "breuß" ;
272
+
273
+ await FileSystem . File . AppendAllTextAsync ( path , contents . AsMemory ( ) , CancellationToken . None ) ;
274
+
275
+ byte [ ] bytes = FileSystem . File . ReadAllBytes ( path ) ;
276
+ await That ( bytes . Length ) . IsEqualTo ( 6 ) ;
277
+ }
235
278
#endif
236
279
}
237
280
#endif
0 commit comments