1- using AzureStorageWrapper . Commands ;
1+ using AzureStorageWrapper . Commands ;
22using AzureStorageWrapper . Exceptions ;
33using AzureStorageWrapper . Tests . Sources ;
44using Xunit ;
5-
5+
66namespace AzureStorageWrapper . Tests . Should . Download
77{
88 public class DownloadBlobReferenceShould : BaseShould
@@ -17,49 +17,96 @@ public DownloadBlobReferenceShould(IAzureStorageWrapper azureStorageWrapper)
1717 [ Fact ]
1818 public async Task DownloadBlobReference_WithManyDots_Should_ReturnReference ( )
1919 {
20- var command = new DownloadBlobReference ( )
20+ var base64 = "SGVsbG8g8J+Zgg==" ;
21+
22+ var uploadBlobCommand = new UploadBase64 ( )
2123 {
22- Uri = Uris . ExistingFileWithManyDots ,
23- ExpiresIn = 360 ,
24+ Base64 = base64 ,
25+ Container = "files" ,
26+ Name = "hello.world.hello.world" ,
27+ Extension = "md" ,
28+ Metadata = new Dictionary < string , string > ( )
29+ { { "hello" , "world" } }
2430 } ;
2531
26- var response = await _azureStorageWrapper . DownloadBlobReferenceAsync ( command ) ;
32+ var uploadBlobResponse = await _azureStorageWrapper . UploadBlobAsync ( uploadBlobCommand ) ;
33+
34+ var downloadBlobReferenceCommand = new DownloadBlobReference ( )
35+ {
36+ Uri = uploadBlobResponse . Uri ,
37+ ExpiresIn = 360 ,
38+ } ;
2739
28- Assert . NotNull ( response ) ;
40+ // Act
41+ var blobReference = await _azureStorageWrapper . DownloadBlobReferenceAsync ( downloadBlobReferenceCommand ) ;
2942
30- Assert . True ( await PingAsync ( response . SasUri ) ) ;
43+ // Assert
44+ Assert . NotNull ( blobReference ) ;
45+ Assert . True ( await PingAsync ( blobReference . SasUri ) ) ;
3146 }
3247
3348 [ Fact ]
3449 public async Task DownloadBlobReference_WithExtensions_Should_ReturnReference ( )
3550 {
36- var command = new DownloadBlobReference ( )
51+ var base64 = "SGVsbG8g8J+Zgg==" ;
52+
53+ var uploadBlobCommand = new UploadBase64 ( )
3754 {
38- Uri = Uris . ExistingFileWithManyExtensions ,
39- ExpiresIn = 360 ,
55+ Base64 = base64 ,
56+ Container = "files" ,
57+ Name = "hello" ,
58+ Extension = "md.md.md" ,
59+ Metadata = new Dictionary < string , string > ( )
60+ { { "hello" , "world" } }
4061 } ;
4162
42- var response = await _azureStorageWrapper . DownloadBlobReferenceAsync ( command ) ;
63+ var uploadBlobResponse = await _azureStorageWrapper . UploadBlobAsync ( uploadBlobCommand ) ;
64+
65+ var downloadBlobReferenceCommand = new DownloadBlobReference ( )
66+ {
67+ Uri = uploadBlobResponse . Uri ,
68+ ExpiresIn = 360 ,
69+ } ;
4370
44- Assert . NotNull ( response ) ;
71+ // Act
72+ var blobReference = await _azureStorageWrapper . DownloadBlobReferenceAsync ( downloadBlobReferenceCommand ) ;
4573
46- Assert . True ( await PingAsync ( response . SasUri ) ) ;
74+ // Assert
75+ Assert . NotNull ( blobReference ) ;
76+ Assert . True ( await PingAsync ( blobReference . SasUri ) ) ;
4777 }
4878
4979 [ Fact ]
5080 public async Task DownloadBlobReference_Should_ReturnReference ( )
5181 {
52- var command = new DownloadBlobReference ( )
82+ // Arrange
83+
84+ var base64 = "SGVsbG8g8J+Zgg==" ;
85+
86+ var uploadBlobCommand = new UploadBase64 ( )
5387 {
54- Uri = Uris . ExistingFile ,
55- ExpiresIn = 360 ,
88+ Base64 = base64 ,
89+ Container = "files" ,
90+ Name = "hello" ,
91+ Extension = "md" ,
92+ Metadata = new Dictionary < string , string > ( )
93+ { { "hello" , "world" } }
5694 } ;
5795
58- var response = await _azureStorageWrapper . DownloadBlobReferenceAsync ( command ) ;
96+ var uploadBlobResponse = await _azureStorageWrapper . UploadBlobAsync ( uploadBlobCommand ) ;
97+
98+ var downloadBlobReferenceCommand = new DownloadBlobReference ( )
99+ {
100+ Uri = uploadBlobResponse . Uri ,
101+ ExpiresIn = 360 ,
102+ } ;
59103
60- Assert . NotNull ( response ) ;
104+ // Act
105+ var blobReference = await _azureStorageWrapper . DownloadBlobReferenceAsync ( downloadBlobReferenceCommand ) ;
61106
62- Assert . True ( await PingAsync ( response . SasUri ) ) ;
107+ // Assert
108+ Assert . NotNull ( blobReference ) ;
109+ Assert . True ( await PingAsync ( blobReference . SasUri ) ) ;
63110 }
64111
65112 [ Fact ]
@@ -84,7 +131,7 @@ public async Task DownloadBlobReference_WithUnExistingUri_Should_ThrowException(
84131 {
85132 var command = new DownloadBlobReference ( )
86133 {
87- Uri = Uris . UnExistingFile ,
134+ Uri = "" ,
88135 ExpiresIn = 360 ,
89136 } ;
90137
@@ -94,39 +141,7 @@ await Assert.ThrowsAsync<AzureStorageWrapperException>(async () =>
94141 _ = await _azureStorageWrapper . DownloadBlobReferenceAsync ( command ) ;
95142 } ) ;
96143 }
97-
98-
99- [ Theory ]
100- [ MemberData ( nameof ( InvalidExpiresIn ) ) ]
101- public async Task DownloadBlobReference_WithWrongExpiration_Should_ReturnReference ( int expiresIn )
102- {
103- var command = new DownloadBlobReference ( )
104- {
105- Uri = Uris . ExistingFile ,
106- ExpiresIn = expiresIn ,
107- } ;
108-
109- var response = await _azureStorageWrapper . DownloadBlobReferenceAsync ( command ) ;
110-
111- Assert . NotNull ( response ) ;
112-
113- Assert . True ( await PingAsync ( response . SasUri ) ) ;
114- }
115-
116- [ Fact ]
117- public async Task DownloadBlobReference_WithHighExpiration_Should_ThrowException ( )
118- {
119- var command = new DownloadBlobReference ( )
120- {
121- Uri = Uris . ExistingFile ,
122- ExpiresIn = int . MaxValue ,
123- } ;
124-
125- await Assert . ThrowsAsync < AzureStorageWrapperException > ( async ( ) =>
126- {
127- _ = await _azureStorageWrapper . DownloadBlobReferenceAsync ( command ) ;
128- } ) ;
129- }
144+
130145
131146 }
132147}
0 commit comments