@@ -389,16 +389,62 @@ public async Task UploadFileAsAsStreamWithoutNameSpecifiedAsync()
389389 #region Download
390390
391391 [ Fact ]
392- public async Task DownloadAsStreamAsync ( )
392+ public async Task DownloadFileBlobMetadataAsLocalFileAsync ( )
393393 {
394- const string uploadContent = $ "test { nameof ( DownloadAsStreamAsync ) } ";
395- const string fileName = $ "{ nameof ( DownloadAsStreamAsync ) } .txt";
394+ const string uploadContent = $ "test { nameof ( DownloadFileBlobMetadataAsLocalFileAsync ) } ";
395+ const string fileName = $ "{ nameof ( DownloadFileBlobMetadataAsLocalFileAsync ) } .txt";
396+
397+ //Upload file
398+ await PrepareFileToTest ( uploadContent , fileName ) ;
399+
400+ //Download file as LocalFile
401+ var localFile = await Storage . DownloadAsync ( new BlobMetadata { Name = fileName } ) ;
402+ using var sr = new StreamReader ( localFile . FileStream , Encoding . UTF8 ) ;
403+
404+ //Get content from file as string
405+ string content = await sr . ReadToEndAsync ( ) ;
406+
407+ content . Should ( ) . NotBeNull ( ) ;
408+ content . Should ( ) . Be ( uploadContent ) ;
409+
410+ //Delete file
411+ await DeleteFileAsync ( fileName ) ;
412+ }
413+
414+ [ Fact ]
415+ public async Task DownloadFileAsLocalFileAsync ( )
416+ {
417+ const string uploadContent = $ "test { nameof ( DownloadFileAsLocalFileAsync ) } ";
418+ const string fileName = $ "{ nameof ( DownloadFileAsLocalFileAsync ) } .txt";
419+
420+ //Upload file
421+ await PrepareFileToTest ( uploadContent , fileName ) ;
422+
423+ //Download file as LocalFile
424+ var localFile = await Storage . DownloadAsync ( fileName ) ;
425+ using var sr = new StreamReader ( localFile . FileStream , Encoding . UTF8 ) ;
426+
427+ //Get content from file as string
428+ string content = await sr . ReadToEndAsync ( ) ;
429+
430+ content . Should ( ) . NotBeNull ( ) ;
431+ content . Should ( ) . Be ( uploadContent ) ;
432+
433+ //Delete file
434+ await DeleteFileAsync ( fileName ) ;
435+ }
436+
437+ [ Fact ]
438+ public async Task DownloadFileBlobMetadataAsync ( )
439+ {
440+ const string uploadContent = $ "test { nameof ( DownloadFileAsync ) } ";
441+ const string fileName = $ "{ nameof ( DownloadFileAsync ) } .txt";
396442
397443 //Upload file
398444 await PrepareFileToTest ( uploadContent , fileName ) ;
399445
400446 //Download file as stream
401- var stream = await Storage . DownloadAsStreamAsync ( fileName ) ;
447+ var stream = await Storage . DownloadAsStreamAsync ( new BlobMetadata { Name = fileName } ) ;
402448 using var sr = new StreamReader ( stream , Encoding . UTF8 ) ;
403449
404450 //Get content from file as string
@@ -412,20 +458,20 @@ public async Task DownloadAsStreamAsync()
412458 }
413459
414460 [ Fact ]
415- public async Task DownloadAsLocalFileAsync ( )
461+ public async Task DownloadFileAsync ( )
416462 {
417- const string uploadContent = $ "test { nameof ( DownloadAsLocalFileAsync ) } ";
418- const string fileName = $ "{ nameof ( DownloadAsLocalFileAsync ) } .txt";
463+ const string uploadContent = $ "test { nameof ( DownloadFileAsync ) } ";
464+ const string fileName = $ "{ nameof ( DownloadFileAsync ) } .txt";
419465
420466 //Upload file
421467 await PrepareFileToTest ( uploadContent , fileName ) ;
422468
423- //Download file
424- var tempFile = await Storage . DownloadAsync ( fileName ) ;
425- var sr = new StreamReader ( tempFile . FileStream , Encoding . UTF8 ) ;
469+ //Download file as stream
470+ var stream = await Storage . DownloadAsStreamAsync ( fileName ) ;
471+ using var sr = new StreamReader ( stream , Encoding . UTF8 ) ;
426472
427473 //Get content from file as string
428- var content = await sr . ReadToEndAsync ( ) ;
474+ string content = await sr . ReadToEndAsync ( ) ;
429475
430476 content . Should ( ) . NotBeNull ( ) ;
431477 content . Should ( ) . Be ( uploadContent ) ;
@@ -439,16 +485,103 @@ public async Task DownloadAsLocalFileAsync()
439485 #region Delete
440486
441487 [ Fact ]
442- public async Task WhenDeleteAsyncIsCalled ( )
488+ public async Task DeleteFileListAsync ( )
443489 {
444- const string uploadContent = $ "test { nameof ( WhenDeleteAsyncIsCalled ) } ";
445- const string fileName = $ "{ nameof ( WhenDeleteAsyncIsCalled ) } .txt";
490+ var listFile = new List < ( string FileName , string UploadedContent ) > ( ) ;
491+ listFile . Add ( ( $ "{ nameof ( DeleteFileListAsync ) } 1.txt", $ "test { nameof ( DeleteFileListAsync ) } 1") ) ;
492+ listFile . Add ( ( $ "{ nameof ( DeleteFileListAsync ) } 2.txt", $ "test { nameof ( DeleteFileListAsync ) } 2") ) ;
493+ listFile . Add ( ( $ "{ nameof ( DeleteFileListAsync ) } 3.txt", $ "test { nameof ( DeleteFileListAsync ) } 3") ) ;
494+
495+ // Upload files to server
496+ foreach ( var item in listFile )
497+ {
498+ await PrepareFileToTest ( item . UploadedContent , item . FileName ) ;
499+ } ;
500+
501+ var expectedList = listFile . Select ( x => x . FileName ) ;
502+
503+ //Delete list files
504+ await Storage . DeleteAsync ( expectedList ) ;
505+
506+ //Check is exist files
507+ var result = Storage . ExistsAsync ( expectedList ) ;
508+ var resultList = await result . ToListAsync ( ) ;
509+
510+ foreach ( var item in resultList )
511+ {
512+ item . Should ( ) . BeFalse ( ) ;
513+ }
514+
515+ }
516+
517+ [ Fact ]
518+ public async Task DeleteFileAsBlobMetadataListAsync ( )
519+ {
520+ var listFile = new List < ( string FileName , string UploadedContent ) > ( ) ;
521+ listFile . Add ( ( $ "{ nameof ( DeleteFileAsBlobMetadataListAsync ) } 1.txt", $ "test { nameof ( DeleteFileAsBlobMetadataListAsync ) } 1") ) ;
522+ listFile . Add ( ( $ "{ nameof ( DeleteFileAsBlobMetadataListAsync ) } 2.txt", $ "test { nameof ( DeleteFileAsBlobMetadataListAsync ) } 2") ) ;
523+ listFile . Add ( ( $ "{ nameof ( DeleteFileAsBlobMetadataListAsync ) } 3.txt", $ "test { nameof ( DeleteFileAsBlobMetadataListAsync ) } 3") ) ;
524+
525+ // Upload files to server
526+ foreach ( var item in listFile )
527+ {
528+ await PrepareFileToTest ( item . UploadedContent , item . FileName ) ;
529+ } ;
530+
531+ var expectedList = listFile . Select ( x => new BlobMetadata { Name = x . FileName } ) ;
532+
533+ //Delete list blobMetadata
534+ await Storage . DeleteAsync ( expectedList ) ;
535+
536+ //Check is exist files
537+ var result = Storage . ExistsAsync ( expectedList ) ;
538+ var resultList = await result . ToListAsync ( ) ;
539+
540+ foreach ( var item in resultList )
541+ {
542+ item . Should ( ) . BeFalse ( ) ;
543+ }
544+
545+ }
546+
547+ [ Fact ]
548+ public async Task DeleteFileAsBlobMetadataAsync ( )
549+ {
550+ const string uploadContent = $ "test { nameof ( DeleteFileAsBlobMetadataAsync ) } ";
551+ const string fileName = $ "{ nameof ( DeleteFileAsBlobMetadataAsync ) } .txt";
552+
553+ //Upload file
554+ await PrepareFileToTest ( uploadContent , fileName ) ;
555+
556+ //Get file as BlobMetadata
557+ var blobMetadata = await Storage . GetBlobAsync ( fileName ) ;
558+
559+ //Delete BlobMetadata
560+ await Storage . DeleteAsync ( blobMetadata ) ;
561+
562+ //Check is exists file
563+ var result = await Storage . ExistsAsync ( fileName ) ;
564+
565+ result . Should ( ) . BeFalse ( ) ;
566+
567+ }
568+
569+ [ Fact ]
570+ public async Task DeleteFileAsStringAsync ( )
571+ {
572+ const string uploadContent = $ "test { nameof ( DeleteFileAsStringAsync ) } ";
573+ const string fileName = $ "{ nameof ( DeleteFileAsStringAsync ) } .txt";
446574
447575 //Upload file
448576 await PrepareFileToTest ( uploadContent , fileName ) ;
449577
450578 //Delete file
451579 await Storage . DeleteAsync ( fileName ) ;
580+
581+ //Check is exists file
582+ var result = await Storage . ExistsAsync ( fileName ) ;
583+
584+ result . Should ( ) . BeFalse ( ) ;
452585 }
453586
454587 #endregion
0 commit comments