@@ -44,9 +44,11 @@ async Task Act() =>
4444 public async Task AppendAllTextAsync_ExistingFile_ShouldAppendLinesToFile (
4545 string path , string previousContents , string contents )
4646 {
47- await FileSystem . File . AppendAllTextAsync ( path , previousContents , TestContext . Current . CancellationToken ) ;
47+ await FileSystem . File . AppendAllTextAsync ( path , previousContents ,
48+ TestContext . Current . CancellationToken ) ;
4849
49- await FileSystem . File . AppendAllTextAsync ( path , contents , TestContext . Current . CancellationToken ) ;
50+ await FileSystem . File . AppendAllTextAsync ( path , contents ,
51+ TestContext . Current . CancellationToken ) ;
5052
5153 await That ( FileSystem . File . Exists ( path ) ) . IsTrue ( ) ;
5254 await That ( FileSystem . File . ReadAllText ( path ) ) . IsEqualTo ( previousContents + contents ) ;
@@ -61,7 +63,8 @@ public async Task AppendAllTextAsync_MissingDirectory_ShouldThrowDirectoryNotFou
6163
6264 async Task Act ( )
6365 {
64- await FileSystem . File . AppendAllTextAsync ( filePath , contents , TestContext . Current . CancellationToken ) ;
66+ await FileSystem . File . AppendAllTextAsync ( filePath , contents ,
67+ TestContext . Current . CancellationToken ) ;
6568 }
6669
6770 await That ( Act ) . Throws < DirectoryNotFoundException > ( ) . WithHResult ( - 2147024893 ) ;
@@ -72,7 +75,8 @@ async Task Act()
7275 public async Task AppendAllTextAsync_MissingFile_ShouldCreateFile (
7376 string path , string contents )
7477 {
75- await FileSystem . File . AppendAllTextAsync ( path , contents , TestContext . Current . CancellationToken ) ;
78+ await FileSystem . File . AppendAllTextAsync ( path , contents ,
79+ TestContext . Current . CancellationToken ) ;
7680
7781 await That ( FileSystem . File . Exists ( path ) ) . IsTrue ( ) ;
7882 await That ( FileSystem . File . ReadAllText ( path ) ) . IsEqualTo ( contents ) ;
@@ -84,7 +88,8 @@ public async Task AppendAllTextAsync_ShouldNotEndWithNewline(string path)
8488 {
8589 string contents = "foo" ;
8690
87- await FileSystem . File . AppendAllTextAsync ( path , contents , TestContext . Current . CancellationToken ) ;
91+ await FileSystem . File . AppendAllTextAsync ( path , contents ,
92+ TestContext . Current . CancellationToken ) ;
8893
8994 await That ( FileSystem . File . Exists ( path ) ) . IsTrue ( ) ;
9095 await That ( FileSystem . File . ReadAllText ( path ) ) . IsEqualTo ( contents ) ;
@@ -100,7 +105,8 @@ public async Task
100105
101106 async Task Act ( )
102107 {
103- await FileSystem . File . AppendAllTextAsync ( path , contents , TestContext . Current . CancellationToken ) ;
108+ await FileSystem . File . AppendAllTextAsync ( path , contents ,
109+ TestContext . Current . CancellationToken ) ;
104110 }
105111
106112 await That ( Act ) . Throws < UnauthorizedAccessException > ( ) . WithHResult ( - 2147024891 ) ;
@@ -114,13 +120,27 @@ public async Task AppendAllTextAsync_WithDifferentEncoding_ShouldNotReturnWritte
114120 string contents , Encoding writeEncoding , Encoding readEncoding )
115121 {
116122 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 ) ;
118125
119126 string [ ] result = FileSystem . File . ReadAllLines ( path , readEncoding ) ;
120127
121128 await That ( result ) . IsNotEqualTo ( [ contents ] ) ;
122129 }
123130
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+
124144#if FEATURE_FILE_SPAN
125145 [ Theory ]
126146 [ AutoData ]
@@ -146,7 +166,8 @@ public async Task
146166 cts . Cancel ( ) ;
147167
148168 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 ) ;
150171
151172 await That ( Act ) . Throws < TaskCanceledException > ( ) . WithHResult ( - 2146233029 ) ;
152173 }
@@ -156,24 +177,28 @@ async Task Act() =>
156177 public async Task AppendAllTextAsync_ReadOnlyMemory_ExistingFile_ShouldAppendLinesToFile (
157178 string path , string previousContents , string contents )
158179 {
159- await FileSystem . File . AppendAllTextAsync ( path , previousContents , TestContext . Current . CancellationToken ) ;
180+ await FileSystem . File . AppendAllTextAsync ( path , previousContents ,
181+ TestContext . Current . CancellationToken ) ;
160182
161- await FileSystem . File . AppendAllTextAsync ( path , contents . AsMemory ( ) , TestContext . Current . CancellationToken ) ;
183+ await FileSystem . File . AppendAllTextAsync ( path , contents . AsMemory ( ) ,
184+ TestContext . Current . CancellationToken ) ;
162185
163186 await That ( FileSystem . File . Exists ( path ) ) . IsTrue ( ) ;
164187 await That ( FileSystem . File . ReadAllText ( path ) ) . IsEqualTo ( previousContents + contents ) ;
165188 }
166189
167190 [ Theory ]
168191 [ 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 )
171195 {
172196 string filePath = FileSystem . Path . Combine ( missingPath , fileName ) ;
173197
174198 async Task Act ( )
175199 {
176- await FileSystem . File . AppendAllTextAsync ( filePath , contents . AsMemory ( ) , TestContext . Current . CancellationToken ) ;
200+ await FileSystem . File . AppendAllTextAsync ( filePath , contents . AsMemory ( ) ,
201+ TestContext . Current . CancellationToken ) ;
177202 }
178203
179204 await That ( Act ) . Throws < DirectoryNotFoundException > ( ) . WithHResult ( - 2147024893 ) ;
@@ -184,7 +209,8 @@ async Task Act()
184209 public async Task AppendAllTextAsync_ReadOnlyMemory_MissingFile_ShouldCreateFile (
185210 string path , string contents )
186211 {
187- await FileSystem . File . AppendAllTextAsync ( path , contents . AsMemory ( ) , TestContext . Current . CancellationToken ) ;
212+ await FileSystem . File . AppendAllTextAsync ( path , contents . AsMemory ( ) ,
213+ TestContext . Current . CancellationToken ) ;
188214
189215 await That ( FileSystem . File . Exists ( path ) ) . IsTrue ( ) ;
190216 await That ( FileSystem . File . ReadAllText ( path ) ) . IsEqualTo ( contents ) ;
@@ -196,7 +222,8 @@ public async Task AppendAllTextAsync_ReadOnlyMemory_ShouldNotEndWithNewline(stri
196222 {
197223 string contents = "foo" ;
198224
199- await FileSystem . File . AppendAllTextAsync ( path , contents . AsMemory ( ) , TestContext . Current . CancellationToken ) ;
225+ await FileSystem . File . AppendAllTextAsync ( path , contents . AsMemory ( ) ,
226+ TestContext . Current . CancellationToken ) ;
200227
201228 await That ( FileSystem . File . Exists ( path ) ) . IsTrue ( ) ;
202229 await That ( FileSystem . File . ReadAllText ( path ) ) . IsEqualTo ( contents ) ;
@@ -212,7 +239,8 @@ public async Task
212239
213240 async Task Act ( )
214241 {
215- await FileSystem . File . AppendAllTextAsync ( path , contents . AsMemory ( ) , TestContext . Current . CancellationToken ) ;
242+ await FileSystem . File . AppendAllTextAsync ( path , contents . AsMemory ( ) ,
243+ TestContext . Current . CancellationToken ) ;
216244 }
217245
218246 await That ( Act ) . Throws < UnauthorizedAccessException > ( ) . WithHResult ( - 2147024891 ) ;
@@ -222,16 +250,31 @@ async Task Act()
222250
223251 [ Theory ]
224252 [ 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 )
227256 {
228257 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 ) ;
230260
231261 string [ ] result = FileSystem . File . ReadAllLines ( path , readEncoding ) ;
232262
233263 await That ( result ) . IsNotEqualTo ( [ contents ] ) ;
234264 }
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+ }
235278#endif
236279}
237280#endif
0 commit comments