@@ -673,6 +673,64 @@ public async Task WillSetTheBlobContentType(string folderName)
673673 }
674674 }
675675
676+ public class TheGetFileUriAsyncMethod
677+ {
678+ private const string folderName = "theFolderName" ;
679+ private const string fileName = "theFileName" ;
680+
681+ [ Fact ]
682+ public async Task WillThrowIfFolderIsNull ( )
683+ {
684+ var service = CreateService ( ) ;
685+
686+ var ex = await Assert . ThrowsAsync < ArgumentNullException > ( ( ) => service . GetFileUriAsync ( null , fileName ) ) ;
687+ Assert . Equal ( "folderName" , ex . ParamName ) ;
688+ }
689+
690+ [ Fact ]
691+ public async Task WillThrowIfFilenameIsNull ( )
692+ {
693+ var service = CreateService ( ) ;
694+
695+ var ex = await Assert . ThrowsAsync < ArgumentNullException > ( ( ) => service . GetFileUriAsync ( folderName , null ) ) ;
696+ Assert . Equal ( "fileName" , ex . ParamName ) ;
697+ }
698+
699+ [ Fact ]
700+ public async Task WillAlwaysReturnValidUri ( )
701+ {
702+ var containerName = CoreConstants . Folders . ValidationFolderName ;
703+ var expectedUri = $ "http://example.com/{ CoreConstants . Folders . ValidationFolderName } /{ fileName } ";
704+
705+ var setupResult = Setup ( containerName , fileName ) ;
706+ var fakeBlobClient = setupResult . Item1 ;
707+
708+ var service = CreateService ( fakeBlobClient ) ;
709+
710+ var uri = await service . GetFileUriAsync ( containerName , fileName ) ;
711+
712+ Assert . Equal ( expectedUri , uri . AbsoluteUri ) ;
713+ }
714+
715+ private static Tuple < Mock < ICloudBlobClient > , Mock < ISimpleCloudBlob > , Uri > Setup ( string folderName , string fileName )
716+ {
717+ var fakeBlobClient = new Mock < ICloudBlobClient > ( ) ;
718+ var fakeContainer = new Mock < ICloudBlobContainer > ( ) ;
719+ fakeBlobClient
720+ . Setup ( bc => bc . GetContainerReference ( folderName ) )
721+ . Returns ( fakeContainer . Object )
722+ . Callback ( ( ) => { int i = 0 ; i = i + 1 ; } ) ;
723+ var fakeBlob = new Mock < ISimpleCloudBlob > ( ) ;
724+ fakeContainer . Setup ( c => c . GetBlobReference ( fileName ) ) . Returns ( fakeBlob . Object ) ;
725+
726+ var blobUri = new Uri ( $ "http://example.com/{ folderName } /{ fileName } ") ;
727+
728+ fakeBlob . SetupGet ( b => b . Uri ) . Returns ( blobUri ) ;
729+
730+ return Tuple . Create ( fakeBlobClient , fakeBlob , blobUri ) ;
731+ }
732+ }
733+
676734 public class TheGetPriviledgedFileUriAsyncMethod
677735 {
678736 private const string folderName = "theFolderName" ;
@@ -824,12 +882,18 @@ public async Task WillThrowIfFilenameIsNull()
824882 }
825883
826884 [ Fact ]
827- public async Task WillThrowIfEndOfAccessIsInThePast ( )
885+ public async Task WillThrowIfEndOfAccessIsInThePastForNonPublicContainer ( )
828886 {
829- var service = CreateService ( ) ;
830-
887+ var setupResult = Setup ( folderName , fileName ) ;
888+ var fakeFolderInformationProvider = new Mock < ICloudBlobContainerInformationProvider > ( ) ;
889+ fakeFolderInformationProvider
890+ . Setup ( fip => fip . IsPublicContainer ( It . IsAny < string > ( ) ) )
891+ . Returns ( false ) ;
892+ var service = CreateService ( setupResult . Item1 , fakeFolderInformationProvider ) ;
831893 DateTimeOffset inThePast = DateTimeOffset . UtcNow . AddSeconds ( - 1 ) ;
894+
832895 var ex = await Assert . ThrowsAsync < ArgumentOutOfRangeException > ( ( ) => service . GetFileReadUriAsync ( folderName , fileName , inThePast ) ) ;
896+
833897 Assert . Equal ( "endOfAccess" , ex . ParamName ) ;
834898 }
835899
@@ -863,11 +927,12 @@ public async Task WillUseSasTokenDependingOnContainerAvailability(bool isPublicC
863927 [ Fact ]
864928 public async Task WillThrowIfNoEndOfAccessSpecifiedForNonPublicContainer ( )
865929 {
930+ var setupResult = Setup ( CoreConstants . Folders . ValidationFolderName , fileName ) ;
866931 var fakeFolderInformationProvider = new Mock < ICloudBlobContainerInformationProvider > ( ) ;
867932 fakeFolderInformationProvider
868933 . Setup ( fip => fip . IsPublicContainer ( It . IsAny < string > ( ) ) )
869934 . Returns ( false ) ;
870- var service = CreateService ( fakeFolderInformationProvider : fakeFolderInformationProvider ) ;
935+ var service = CreateService ( setupResult . Item1 , fakeFolderInformationProvider ) ;
871936
872937 var ex = await Assert . ThrowsAsync < ArgumentNullException > ( ( ) => service . GetFileReadUriAsync ( CoreConstants . Folders . ValidationFolderName , fileName , null ) ) ;
873938 Assert . Equal ( "endOfAccess" , ex . ParamName ) ;
@@ -1596,6 +1661,5 @@ public async Task VerifyETagIsNullWhenBlobDoesNotExist()
15961661 Assert . Null ( etagValue ) ;
15971662 }
15981663 }
1599-
16001664 }
16011665}
0 commit comments