public async Task DoesNotCopyWhenSourceAndDestinationHaveSameHash() { // Arrange var srcFolderName = CoreConstants.Folders.ValidationFolderName; var srcFileName = $"{_prefixA}/src"; var srcContent = "Hello, world."; var destFolderName = CoreConstants.Folders.PackagesFolderName; var destFileName = $"{_prefixB}/dest"; await _targetA.SaveFileAsync( srcFolderName, srcFileName, new MemoryStream(Encoding.ASCII.GetBytes(srcContent)), overwrite : false); await _targetB.SaveFileAsync( destFolderName, destFileName, new MemoryStream(Encoding.ASCII.GetBytes(srcContent)), overwrite : false); var originalDestFileReference = await _targetB.GetFileReferenceAsync(destFolderName, destFileName); var originalDestETag = originalDestFileReference.ContentId; var srcUri = await _targetA.GetFileReadUriAsync( srcFolderName, srcFileName, DateTimeOffset.UtcNow.AddHours(1)); var destAccessCondition = AccessConditionWrapper.GenerateIfNotExistsCondition(); // Act await _targetB.CopyFileAsync( srcUri, destFolderName, destFileName, destAccessCondition); // Assert var finalDestFileReference = await _targetB.GetFileReferenceAsync(destFolderName, destFileName); var finalDestETag = finalDestFileReference.ContentId; Assert.Equal(originalDestETag, finalDestETag); }
private static async Task CopyFileWithUriAsync( CloudBlobCoreFileStorageService srcService, string srcFolderName, string srcFileName, CloudBlobCoreFileStorageService destService, string destFolderName, string destFileName) { var endOfAccess = DateTimeOffset.UtcNow.AddHours(1); var srcUri = await srcService.GetFileReadUriAsync(srcFolderName, srcFileName, endOfAccess); var destAccessCondition = AccessConditionWrapper.GenerateIfNotExistsCondition(); await destService.CopyFileAsync( srcUri, destFolderName, destFileName, destAccessCondition); }
public async Task DoesNotCopyWhenSourceAndDestinationHaveSameHash() { // Arrange var srcFolderName = CoreConstants.Folders.ValidationFolderName; var srcFileName = $"{_prefixA}/src"; var srcContent = "Hello, world."; var srcSha512 = "AD0C37C31D69B315F3A81F13C8CDE701094AD91725BA1B0DC3199CA9713661B8280" + "D6EF7E68F133E6211E2E5A9A3150445D76F1708E04521B0EE034F0B0BAF26"; var destFolderName = CoreConstants.Folders.PackagesFolderName; var destFileName = $"{_prefixB}/dest"; await _targetA.SaveFileAsync( srcFolderName, srcFileName, new MemoryStream(Encoding.ASCII.GetBytes(srcContent)), overwrite : false); await _targetA.SetMetadataAsync(srcFolderName, srcFileName, (lazyStream, metadata) => { metadata[CoreConstants.Sha512HashAlgorithmId] = srcSha512; return(Task.FromResult(true)); }); await _targetB.SaveFileAsync( destFolderName, destFileName, new MemoryStream(Encoding.ASCII.GetBytes(srcContent)), overwrite : false); await _targetB.SetMetadataAsync(destFolderName, destFileName, (lazyStream, metadata) => { metadata[CoreConstants.Sha512HashAlgorithmId] = srcSha512; return(Task.FromResult(true)); }); var originalDestFileReference = await _targetB.GetFileReferenceAsync(destFolderName, destFileName); var originalDestETag = originalDestFileReference.ContentId; var srcUri = await _targetA.GetFileReadUriAsync( srcFolderName, srcFileName, DateTimeOffset.UtcNow.AddHours(1)); var destAccessCondition = AccessConditionWrapper.GenerateIfNotExistsCondition(); // Act await _targetB.CopyFileAsync( srcUri, destFolderName, destFileName, destAccessCondition); // Assert var finalDestFileReference = await _targetB.GetFileReferenceAsync(destFolderName, destFileName); var finalDestETag = finalDestFileReference.ContentId; Assert.Equal(originalDestETag, finalDestETag); }