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);
        }
        public async Task ReturnsCurrentETagForIfMatch()
        {
            // Arrange
            var folderName = CoreConstants.Folders.ValidationFolderName;
            var fileName   = _prefixA;
            await _targetA.SaveFileAsync(folderName, fileName, new MemoryStream(new byte[0]));

            var initialReference = await _targetA.GetFileReferenceAsync(folderName, fileName);

            initialReference.OpenRead().Dispose();

            // Act
            var reference = await _targetA.GetFileReferenceAsync(folderName, fileName, initialReference.ContentId);

            // Assert
            Assert.NotNull(reference);
            Assert.Null(reference.OpenRead());
            Assert.Equal(initialReference.ContentId, reference.ContentId);
        }
예제 #3
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);
        }