@@ -239,6 +239,103 @@ public async Task File_Write_NewFile()
239239 Assert . That ( await file . ExistsAsync ( ) , Is . False ) ;
240240 }
241241
242+ [ Test ]
243+ public async Task File_Write_EmptyStream_CreatesFile ( )
244+ {
245+ using var fs = GetFileSystem ( ) ;
246+
247+ if ( fs . IsReadOnly )
248+ return ;
249+
250+ var file = fs . GetFile ( "/project/e3a1c7f0_empty_write.txt" ) ;
251+
252+ Assert . That ( await file . ExistsAsync ( ) , Is . False ) ;
253+
254+ await file . WriteAsync ( Stream . Null ) ;
255+
256+ Assert . That ( await file . ExistsAsync ( ) , Is . True ) ;
257+ Assert . That ( await file . GetLengthAsync ( ) , Is . Zero ) ;
258+
259+ await file . DeleteAsync ( ) ;
260+ }
261+
262+ [ Test ]
263+ public async Task File_Write_EmptyStream_ExistingFile_ResultsInZeroLength ( )
264+ {
265+ using var fs = GetFileSystem ( ) ;
266+
267+ if ( fs . IsReadOnly )
268+ return ;
269+
270+ var path = "/project/b7d2e9f1_overwrite_empty.txt" ;
271+ var file = fs . GetFile ( path ) ;
272+
273+ var ms = new MemoryStream ( "Some content"u8 . ToArray ( ) ) ;
274+ await file . WriteAsync ( ms ) ;
275+
276+ Assert . That ( await file . ExistsAsync ( ) , Is . True ) ;
277+ Assert . That ( await file . GetLengthAsync ( ) , Is . GreaterThan ( 0 ) ) ;
278+
279+ // Write empty stream over existing file
280+ await file . WriteAsync ( Stream . Null , overwrite : true ) ;
281+
282+ Assert . That ( await file . ExistsAsync ( ) , Is . True ) ;
283+ Assert . That ( await file . GetLengthAsync ( ) , Is . Zero ) ;
284+
285+ await file . DeleteAsync ( ) ;
286+ }
287+
288+ [ Test ]
289+ public async Task File_OpenWrite_NoWrite_CreatesFile ( )
290+ {
291+ using var fs = GetFileSystem ( ) ;
292+
293+ if ( fs . IsReadOnly )
294+ return ;
295+
296+ var file = fs . GetFile ( "/project/a4f8d2e0_openwrite_empty.txt" ) ;
297+
298+ Assert . That ( await file . ExistsAsync ( ) , Is . False ) ;
299+
300+ await using ( await file . OpenWriteAsync ( ) )
301+ {
302+ // Do not write anything, just close
303+ }
304+
305+ Assert . That ( await file . ExistsAsync ( ) , Is . True ) ;
306+ Assert . That ( await file . GetLengthAsync ( ) , Is . Zero ) ;
307+
308+ await file . DeleteAsync ( ) ;
309+ }
310+
311+ [ Test ]
312+ public async Task File_OpenWrite_ExistingFile_ResultsInZeroLength ( )
313+ {
314+ using var fs = GetFileSystem ( ) ;
315+
316+ if ( fs . IsReadOnly )
317+ return ;
318+
319+ var file = fs . GetFile ( "/project/c5e9a3b1_openwrite_truncate.txt" ) ;
320+
321+ var ms = new MemoryStream ( "Some content"u8 . ToArray ( ) ) ;
322+ await file . WriteAsync ( ms ) ;
323+
324+ Assert . That ( await file . ExistsAsync ( ) , Is . True ) ;
325+ Assert . That ( await file . GetLengthAsync ( ) , Is . GreaterThan ( 0 ) ) ;
326+
327+ // Open for write and close without writing
328+ await using ( await file . OpenWriteAsync ( ) )
329+ {
330+ // Do not write anything, just close
331+ }
332+
333+ Assert . That ( await file . ExistsAsync ( ) , Is . True ) ;
334+ Assert . That ( await file . GetLengthAsync ( ) , Is . Zero ) ;
335+
336+ await file . DeleteAsync ( ) ;
337+ }
338+
242339 [ Test ]
243340 public async Task File_Delete_For_ExistingFile ( )
244341 {
0 commit comments