1- // Copyright (c) .NET Foundation. All rights reserved.
1+ // Copyright (c) .NET Foundation. All rights reserved.
22// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
44using System ;
99using Xunit ;
1010using NuGet . Services . Metadata . Catalog . Persistence ;
1111using Azure . Storage . Blobs ;
12+ using Azure . Storage . Blobs . Models ;
1213
1314namespace CatalogMetadataTests
1415{
@@ -19,25 +20,29 @@ public AzureStorageFacts() : base()
1920 }
2021
2122 [ Theory ]
22- [ InlineData ( true , true , "SHA512Value1" , true , true , "SHA512Value1" , true ) ]
23- [ InlineData ( true , true , "SHA512Value1" , true , true , "SHA512Value2" , false ) ]
24- [ InlineData ( false , false , null , true , true , "SHA512Value1" , true ) ]
25- [ InlineData ( true , true , "SHA512Value1" , false , false , null , false ) ]
26- [ InlineData ( false , false , null , false , false , null , true ) ]
27- [ InlineData ( true , false , null , true , true , "SHA512Value1" , false ) ]
28- [ InlineData ( true , true , "SHA512Value1" , true , false , null , false ) ]
29- [ InlineData ( true , false , null , true , false , null , false ) ]
30- public async Task ValidateAreSynchronizedmethod ( bool sourceBlobExists ,
23+ [ InlineData ( true , true , "SHA512Value1" , 10 , true , true , "SHA512Value1" , 10 , true ) ]
24+ [ InlineData ( true , true , "SHA512Value1" , 10 , true , true , "SHA512Value2" , 10 , false ) ]
25+ [ InlineData ( false , false , null , 10 , true , true , "SHA512Value1" , 10 , true ) ]
26+ [ InlineData ( true , true , "SHA512Value1" , 10 , false , false , null , 10 , false ) ]
27+ [ InlineData ( false , false , null , 10 , false , false , null , 10 , true ) ]
28+ [ InlineData ( true , false , null , 10 , true , true , "SHA512Value1" , 10 , false ) ]
29+ [ InlineData ( true , true , "SHA512Value1" , 10 , true , false , null , 10 , false ) ]
30+ [ InlineData ( true , false , null , 10 , true , false , null , 10 , false ) ]
31+ [ InlineData ( true , true , "SHA512Value1" , 10 , true , true , "SHA512Value1" , 11 , false ) ]
32+ public async Task ValidateAreSynchronizedmethod (
33+ bool sourceBlobExists ,
3134 bool hasSourceBlobSHA512Value ,
3235 string sourceBlobSHA512Value ,
36+ long sourceSize ,
3337 bool destinationBlobExists ,
3438 bool hasDestinationBlobSHA512Value ,
3539 string destinationBlobSHA512Value ,
40+ long destinationSize ,
3641 bool expected )
3742 {
3843 // Arrange
39- var sourceBlob = GetMockedBlockBlob ( sourceBlobExists , hasSourceBlobSHA512Value , sourceBlobSHA512Value , new Uri ( "https://blockBlob1" ) ) ;
40- var destinationBlob = GetMockedBlockBlob ( destinationBlobExists , hasDestinationBlobSHA512Value , destinationBlobSHA512Value , new Uri ( "https://blockBlob2" ) ) ;
44+ var sourceBlob = GetMockedBlockBlob ( sourceBlobExists , hasSourceBlobSHA512Value , sourceBlobSHA512Value , sourceSize , new Uri ( "https://blockBlob1" ) ) ;
45+ var destinationBlob = GetMockedBlockBlob ( destinationBlobExists , hasDestinationBlobSHA512Value , destinationBlobSHA512Value , destinationSize , new Uri ( "https://blockBlob2" ) ) ;
4146
4247 // Act
4348 var isSynchronized = await _storage . AreSynchronized ( sourceBlob . Object , destinationBlob . Object ) ;
@@ -48,8 +53,8 @@ public async Task ValidateAreSynchronizedmethod(bool sourceBlobExists,
4853
4954 if ( sourceBlobExists && destinationBlobExists )
5055 {
51- sourceBlob . Verify ( x => x . GetMetadataAsync ( CancellationToken . None ) , Times . Once ) ;
52- destinationBlob . Verify ( x => x . GetMetadataAsync ( CancellationToken . None ) , Times . Once ) ;
56+ sourceBlob . Verify ( x => x . FetchAttributesAsync ( CancellationToken . None ) , Times . Once ) ;
57+ destinationBlob . Verify ( x => x . FetchAttributesAsync ( CancellationToken . None ) , Times . Once ) ;
5358
5459 if ( ! hasSourceBlobSHA512Value )
5560 {
@@ -69,7 +74,7 @@ public async Task ValidateAreSynchronizedmethod(bool sourceBlobExists,
6974 Assert . Equal ( expected , isSynchronized ) ;
7075 }
7176
72- private Mock < ICloudBlockBlob > GetMockedBlockBlob ( bool isExisted , bool hasSHA512Value , string SHA512Value , Uri blockBlobUri )
77+ private Mock < ICloudBlockBlob > GetMockedBlockBlob ( bool isExisted , bool hasSHA512Value , string SHA512Value , long size , Uri blockBlobUri )
7378 {
7479 var mockBlob = new Mock < ICloudBlockBlob > ( ) ;
7580
@@ -82,16 +87,16 @@ private Mock<ICloudBlockBlob> GetMockedBlockBlob(bool isExisted, bool hasSHA512V
8287
8388 if ( hasSHA512Value )
8489 {
85- mockBlob . Setup ( x => x . GetMetadataAsync ( CancellationToken . None ) )
86- . ReturnsAsync ( new Dictionary < string , string > ( )
90+ mockBlob . Setup ( x => x . FetchAttributesAsync ( CancellationToken . None ) )
91+ . ReturnsAsync ( BlobsModelFactory . BlobProperties ( contentLength : size , metadata : new Dictionary < string , string > ( )
8792 {
8893 { "SHA512" , SHA512Value }
89- } ) ;
94+ } ) ) ;
9095 }
9196 else
9297 {
93- mockBlob . Setup ( x => x . GetMetadataAsync ( CancellationToken . None ) )
94- . ReturnsAsync ( new Dictionary < string , string > ( ) ) ;
98+ mockBlob . Setup ( x => x . FetchAttributesAsync ( CancellationToken . None ) )
99+ . ReturnsAsync ( BlobsModelFactory . BlobProperties ( contentLength : size , metadata : new Dictionary < string , string > ( ) ) ) ;
95100 }
96101 }
97102
@@ -116,13 +121,17 @@ private ICloudBlockBlob GetMockedBlockBlobWithNullMetadata(bool isBlobMetadataEx
116121 {
117122 if ( isBlobMetadataExisted )
118123 {
119- return Mock . Of < ICloudBlockBlob > ( x => x . ExistsAsync ( CancellationToken . None ) == Task . FromResult ( true ) &&
120- x . GetMetadataAsync ( CancellationToken . None ) == Task . FromResult < IReadOnlyDictionary < string , string > > ( new Dictionary < string , string > ( ) ) ) ;
124+ var properties = BlobsModelFactory . BlobProperties ( metadata : new Dictionary < string , string > ( ) ) ;
125+ return Mock . Of < ICloudBlockBlob > (
126+ x => x . ExistsAsync ( CancellationToken . None ) == Task . FromResult ( true ) &&
127+ x . FetchAttributesAsync ( CancellationToken . None ) == Task . FromResult ( properties ) ) ;
121128 }
122129 else
123130 {
124- return Mock . Of < ICloudBlockBlob > ( x => x . ExistsAsync ( CancellationToken . None ) == Task . FromResult ( true ) &&
125- x . GetMetadataAsync ( CancellationToken . None ) == Task . FromResult < IReadOnlyDictionary < string , string > > ( null ) ) ;
131+ var properties = BlobsModelFactory . BlobProperties ( metadata : null ) ;
132+ return Mock . Of < ICloudBlockBlob > (
133+ x => x . ExistsAsync ( CancellationToken . None ) == Task . FromResult ( true ) &&
134+ x . FetchAttributesAsync ( CancellationToken . None ) == Task . FromResult ( properties ) ) ;
126135 }
127136 }
128137 }
@@ -166,4 +175,4 @@ public AzureStorageBaseFacts()
166175 false ) ;
167176 }
168177 }
169- }
178+ }
0 commit comments