Example #1
0
            public async Task WillCopyBlobFromSourceUri()
            {
                // Arrange
                _blobClient
                .Setup(x => x.GetBlobFromUri(It.IsAny <Uri>()))
                .Returns(_srcBlobMock.Object);

                _destBlobMock
                .Setup(x => x.StartCopyAsync(It.IsAny <ISimpleCloudBlob>(), It.IsAny <AccessCondition>(), It.IsAny <AccessCondition>()))
                .Returns(Task.FromResult(0))
                .Callback <ISimpleCloudBlob, AccessCondition, AccessCondition>((_, __, ___) =>
                {
                    SetDestCopyStatus(CopyStatus.Success);
                });

                // Act
                await _target.CopyFileAsync(
                    _srcUri,
                    _destFolderName,
                    _destFileName,
                    AccessConditionWrapper.GenerateIfNotExistsCondition());

                // Assert
                _destBlobMock.Verify(
                    x => x.StartCopyAsync(_srcBlobMock.Object, It.IsAny <AccessCondition>(), It.IsAny <AccessCondition>()),
                    Times.Once);
                _destBlobMock.Verify(
                    x => x.StartCopyAsync(It.IsAny <ISimpleCloudBlob>(), It.IsAny <AccessCondition>(), It.IsAny <AccessCondition>()),
                    Times.Once);
                _blobClient.Verify(
                    x => x.GetBlobFromUri(_srcUri),
                    Times.Once);
            }
        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 CopyFileWithNamesAsync(
            CloudBlobCoreFileStorageService srcService,
            string srcFolderName,
            string srcFileName,
            CloudBlobCoreFileStorageService destService,
            string destFolderName,
            string destFileName)
        {
            var destAccessCondition = AccessConditionWrapper.GenerateIfNotExistsCondition();

            await destService.CopyFileAsync(
                srcFolderName,
                srcFileName,
                destFolderName,
                destFileName,
                destAccessCondition);
        }
        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);
        }
Example #5
0
        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);
        }