@@ -1067,54 +1067,6 @@ await _target.CopyFileAsync(
10671067 Times . Once ) ;
10681068 }
10691069
1070- [ Theory ]
1071- [ InlineData ( CoreConstants . PackagesFolderName ) ]
1072- [ InlineData ( CoreConstants . SymbolPackagesFolderName ) ]
1073- public async Task WillCopyAndSetCacheControlOnCopyForFolder ( string folderName )
1074- {
1075- // Arrange
1076- var instance = new TheCopyFileAsyncMethod ( ) ;
1077- instance . _blobClient
1078- . Setup ( x => x . GetBlobFromUri ( It . IsAny < Uri > ( ) ) )
1079- . Returns ( instance . _srcBlobMock . Object ) ;
1080- instance . _blobClient
1081- . Setup ( x => x . GetContainerReference ( folderName ) )
1082- . Returns ( ( ) => instance . _destContainer . Object ) ;
1083-
1084- instance . _destBlobMock
1085- . Setup ( x => x . StartCopyAsync ( It . IsAny < ISimpleCloudBlob > ( ) , It . IsAny < AccessCondition > ( ) , It . IsAny < AccessCondition > ( ) ) )
1086- . Returns ( Task . FromResult ( 0 ) )
1087- . Callback < ISimpleCloudBlob , AccessCondition , AccessCondition > ( ( _ , __ , ___ ) =>
1088- {
1089- SetDestCopyStatus ( CopyStatus . Success ) ;
1090- } ) ;
1091-
1092- // Act
1093- await instance . _target . CopyFileAsync (
1094- instance . _srcUri ,
1095- folderName ,
1096- instance . _destFileName ,
1097- AccessConditionWrapper . GenerateIfNotExistsCondition ( ) ) ;
1098-
1099- // Assert
1100- instance . _destBlobMock . Verify (
1101- x => x . StartCopyAsync ( instance . _srcBlobMock . Object , It . IsAny < AccessCondition > ( ) , It . IsAny < AccessCondition > ( ) ) ,
1102- Times . Once ) ;
1103- instance . _destBlobMock . Verify (
1104- x => x . StartCopyAsync ( It . IsAny < ISimpleCloudBlob > ( ) , It . IsAny < AccessCondition > ( ) , It . IsAny < AccessCondition > ( ) ) ,
1105- Times . Once ) ;
1106- instance . _destBlobMock . Verify (
1107- x => x . SetPropertiesAsync ( ) ,
1108- Times . Once ) ;
1109- instance . _destBlobMock . Verify (
1110- x => x . StartCopyAsync ( It . IsAny < ISimpleCloudBlob > ( ) , It . IsAny < AccessCondition > ( ) , It . IsAny < AccessCondition > ( ) ) ,
1111- Times . Once ) ;
1112- Assert . NotNull ( instance . _destProperties . CacheControl ) ;
1113- instance . _blobClient . Verify (
1114- x => x . GetBlobFromUri ( instance . _srcUri ) ,
1115- Times . Once ) ;
1116- }
1117-
11181070 [ Fact ]
11191071 public async Task WillCopyTheFileIfDestinationDoesNotExist ( )
11201072 {
@@ -1461,6 +1413,110 @@ await _service.SetMetadataAsync(
14611413 }
14621414 }
14631415
1416+ public class TheSetPropertiesAsyncMethod
1417+ {
1418+ private const string _content = "peach" ;
1419+
1420+ private readonly Mock < ICloudBlobClient > _blobClient ;
1421+ private readonly Mock < ICloudBlobContainer > _blobContainer ;
1422+ private readonly Mock < ISimpleCloudBlob > _blob ;
1423+ private readonly CloudBlobCoreFileStorageService _service ;
1424+
1425+ public TheSetPropertiesAsyncMethod ( )
1426+ {
1427+ _blobClient = new Mock < ICloudBlobClient > ( ) ;
1428+ _blobContainer = new Mock < ICloudBlobContainer > ( ) ;
1429+ _blob = new Mock < ISimpleCloudBlob > ( ) ;
1430+
1431+ _blobClient . Setup ( x => x . GetContainerReference ( It . IsAny < string > ( ) ) )
1432+ . Returns ( _blobContainer . Object ) ;
1433+ _blobContainer . Setup ( x => x . CreateIfNotExistAsync ( ) )
1434+ . Returns ( Task . FromResult ( 0 ) ) ;
1435+ _blobContainer . Setup ( x => x . SetPermissionsAsync ( It . IsAny < BlobContainerPermissions > ( ) ) )
1436+ . Returns ( Task . FromResult ( 0 ) ) ;
1437+ _blobContainer . Setup ( x => x . GetBlobReference ( It . IsAny < string > ( ) ) )
1438+ . Returns ( _blob . Object ) ;
1439+
1440+ _service = CreateService ( fakeBlobClient : _blobClient ) ;
1441+ }
1442+
1443+ [ Fact ]
1444+ public async Task WhenLazyStreamRead_ReturnsContent ( )
1445+ {
1446+ _blob . Setup ( x => x . DownloadToStreamAsync ( It . IsAny < Stream > ( ) , It . IsAny < AccessCondition > ( ) ) )
1447+ . Callback < Stream , AccessCondition > ( ( stream , _ ) =>
1448+ {
1449+ using ( var writer = new StreamWriter ( stream , Encoding . UTF8 , bufferSize : 4096 , leaveOpen : true ) )
1450+ {
1451+ writer . Write ( _content ) ;
1452+ }
1453+ } )
1454+ . Returns ( Task . FromResult ( 0 ) ) ;
1455+
1456+ await _service . SetPropertiesAsync (
1457+ folderName : CoreConstants . PackagesFolderName ,
1458+ fileName : "a" ,
1459+ updatePropertiesAsync : async ( lazyStream , properties ) =>
1460+ {
1461+ using ( var stream = await lazyStream . Value )
1462+ using ( var reader = new StreamReader ( stream ) )
1463+ {
1464+ Assert . Equal ( _content , reader . ReadToEnd ( ) ) ;
1465+ }
1466+
1467+ return false ;
1468+ } ) ;
1469+
1470+ _blob . VerifyAll ( ) ;
1471+ _blobContainer . VerifyAll ( ) ;
1472+ _blobClient . VerifyAll ( ) ;
1473+ }
1474+
1475+ [ Fact ]
1476+ public async Task WhenReturnValueIsFalse_PropertyChangesAreNotPersisted ( )
1477+ {
1478+ _blob . SetupGet ( x => x . Properties )
1479+ . Returns ( new BlobProperties ( ) ) ;
1480+
1481+ await _service . SetPropertiesAsync (
1482+ folderName : CoreConstants . PackagesFolderName ,
1483+ fileName : "a" ,
1484+ updatePropertiesAsync : ( lazyStream , properties ) =>
1485+ {
1486+ Assert . NotNull ( properties ) ;
1487+
1488+ return Task . FromResult ( false ) ;
1489+ } ) ;
1490+
1491+ _blob . VerifyAll ( ) ;
1492+ _blobContainer . VerifyAll ( ) ;
1493+ _blobClient . VerifyAll ( ) ;
1494+ }
1495+
1496+ [ Fact ]
1497+ public async Task WhenReturnValueIsTrue_PropertiesChangesArePersisted ( )
1498+ {
1499+ _blob . SetupGet ( x => x . Properties )
1500+ . Returns ( new BlobProperties ( ) ) ;
1501+ _blob . Setup ( x => x . SetPropertiesAsync ( It . IsNotNull < AccessCondition > ( ) ) )
1502+ . Returns ( Task . FromResult ( 0 ) ) ;
1503+
1504+ await _service . SetPropertiesAsync (
1505+ folderName : CoreConstants . PackagesFolderName ,
1506+ fileName : "a" ,
1507+ updatePropertiesAsync : ( lazyStream , properties ) =>
1508+ {
1509+ Assert . NotNull ( properties ) ;
1510+
1511+ return Task . FromResult ( true ) ;
1512+ } ) ;
1513+
1514+ _blob . VerifyAll ( ) ;
1515+ _blobContainer . VerifyAll ( ) ;
1516+ _blobClient . VerifyAll ( ) ;
1517+ }
1518+ }
1519+
14641520 public class TheGetETagMethod
14651521 {
14661522 private const string _etag = "dummy_etag" ;
0 commit comments