public void WillCopyMetadataFromSourceWherePresent(string source, string destination)
        {
            var buffer     = Encoding.UTF8.GetBytes("File content");
            var sourceBlob = new StandaloneAzureBlockBlob(BasePath, source);

            sourceBlob.UploadFromByteArrayAsync(buffer, 0, buffer.Length).Wait();
            sourceBlob.Metadata["thing"]      = "something";
            sourceBlob.Properties.ContentType = "whatever";
            sourceBlob.SetMetadata();
            sourceBlob.SetProperties();

            var destinationBlob = new StandaloneAzureBlockBlob(BasePath, destination);

            destinationBlob.StartCopyFromBlob(sourceBlob.Uri);
            destinationBlob.FetchAttributes();

            new
            {
                Metadata = new Dictionary <string, string>
                {
                    { "thing", "something" }
                },
                Properties = new
                {
                    ContentType = "whatever",
                    Length      = (long)12
                }
            }.ToExpectedObject().ShouldMatch(destinationBlob);
        }
Example #2
0
        public void CanAppendToExistingPersistedMetadata(string blobName)
        {
            var sourceBlob = new StandaloneAzureBlockBlob(BasePath, blobName);

            CreateBlobContent(sourceBlob);

            sourceBlob.Metadata["thing"] = "something";
            sourceBlob.SetMetadata();

            sourceBlob.FetchAttributes();
            sourceBlob.Metadata["other thing"] = "whatever";
            sourceBlob.SetMetadata();

            var loadedBlob = new StandaloneAzureBlockBlob(BasePath, blobName);

            loadedBlob.FetchAttributes();
            new
            {
                Metadata = new Dictionary <string, string>
                {
                    { "thing", "something" },
                    { "other thing", "whatever" }
                }
            }.ToExpectedObject().ShouldMatch(loadedBlob);
        }
Example #3
0
        public void SavingPreservesUnknownMetadata(string blobName)
        {
            var sourceBlob = new StandaloneAzureBlockBlob(BasePath, blobName);

            CreateBlobContent(sourceBlob);
            sourceBlob.Metadata["thing"] = "something";
            sourceBlob.SetMetadata();

            var metadataPath       = Path.Combine(BasePath, ".meta", blobName);
            var expectedProperties = new Dictionary <string, string>
            {
                { "foo", "bar" }, { "couci-couça", "svo-svo" }
            };

            WriteJsonPropertiesToFile(metadataPath, expectedProperties);

            var loadedBlob = new StandaloneAzureBlockBlob(BasePath, blobName);

            loadedBlob.FetchAttributes();
            loadedBlob.Metadata["another thing"] = "whatever else";
            loadedBlob.SetMetadata();

            using (var reader = new StreamReader(metadataPath))
            {
                var loaded         = JObject.Load(new JsonTextReader(reader));
                var actualMetadata = loaded["Metadata"];
                Assert.Equal("something", actualMetadata["thing"]);
                Assert.Equal("whatever else", actualMetadata["another thing"]);
                expectedProperties.ToList().ForEach(kvp =>
                                                    Assert.Equal(kvp.Value, loaded[kvp.Key])
                                                    );
            }
        }
Example #4
0
        public void CanUploadContentFromFullByteArray(string blobName)
        {
            var blob = new StandaloneAzureBlockBlob(BasePath, blobName);

            blob.UploadFromByteArrayAsync(Encoding.UTF8.GetBytes("File content")).Wait();

            Assert.Equal("File content", File.ReadAllText(blob.Uri.LocalPath));
        }
Example #5
0
        public void CanUploadContentFromByteArrayWithRangeSpecifier(int index, int count, string expectedContent, string blobName)
        {
            var buffer = Encoding.UTF8.GetBytes("File content");

            var blob = new StandaloneAzureBlockBlob(BasePath, blobName);

            blob.UploadFromByteArrayAsync(buffer, index, count).Wait();

            Assert.Equal(expectedContent, File.ReadAllText(blob.Uri.LocalPath));
        }
        public void CanDeleteBlob(string blobName)
        {
            var buffer = Encoding.UTF8.GetBytes("File content");

            var blob = new StandaloneAzureBlockBlob(BasePath, blobName);

            blob.UploadFromByteArrayAsync(buffer, 0, buffer.Length).Wait();

            blob.Delete();

            Assert.False(File.Exists(blob.Uri.LocalPath));
        }
Example #7
0
        public void CanUploadContentFromFile(string blobName)
        {
            var sourceFilePath = Path.Combine(BasePath, "source");

            File.WriteAllText(sourceFilePath, "Source file");

            var blob = new StandaloneAzureBlockBlob(BasePath, blobName);

            blob.UploadFromFileAsync(sourceFilePath);

            Assert.Equal("Source file", File.ReadAllText(blob.Uri.LocalPath));
        }
        public void WillNotCopyMetadataWhereItDoesNotExist(string source, string destination)
        {
            var buffer     = Encoding.UTF8.GetBytes("File content");
            var sourceBlob = new StandaloneAzureBlockBlob(BasePath, source);

            sourceBlob.UploadFromByteArrayAsync(buffer, 0, buffer.Length).Wait();

            var destinationBlob = new StandaloneAzureBlockBlob(BasePath, destination);

            destinationBlob.StartCopyFromBlob(sourceBlob.Uri);

            Assert.False(File.Exists(Path.Combine(BasePath, ".meta", destination)));
        }
        public void CopyStateIsSuccessAfterCopy(string source, string destination)
        {
            var buffer     = Encoding.UTF8.GetBytes("File content");
            var sourceBlob = new StandaloneAzureBlockBlob(BasePath, source);

            sourceBlob.UploadFromByteArrayAsync(buffer, 0, buffer.Length).Wait();

            var destinationBlob = new StandaloneAzureBlockBlob(BasePath, destination);

            destinationBlob.StartCopyFromBlob(sourceBlob.Uri);

            Assert.Equal(CopyStatus.Success, destinationBlob.CopyState.Status);
        }
Example #10
0
        public void DefaultsToEmptyMetadataOnFetchWithNoSavedMetadata(string blobName)
        {
            var sourceBlob = new StandaloneAzureBlockBlob(BasePath, blobName);

            CreateBlobContent(sourceBlob);

            sourceBlob.FetchAttributes();

            new
            {
                Metadata = new Dictionary <string, string>()
            }.ToExpectedObject().ShouldMatch(sourceBlob);
        }
        public void CanCopyBlob(string source, string destination)
        {
            var buffer     = Encoding.UTF8.GetBytes("File content");
            var sourceBlob = new StandaloneAzureBlockBlob(BasePath, source);

            sourceBlob.UploadFromByteArrayAsync(buffer, 0, buffer.Length).Wait();

            var destinationBlob = new StandaloneAzureBlockBlob(BasePath, destination);

            destinationBlob.StartCopyFromBlob(sourceBlob.Uri);

            Assert.Equal("File content", File.ReadAllText(destinationBlob.Uri.LocalPath));
        }
        public void CanDeleteBlobMetadata(string blobName)
        {
            var buffer = Encoding.UTF8.GetBytes("File content");

            var blob = new StandaloneAzureBlockBlob(BasePath, blobName);

            blob.UploadFromByteArrayAsync(buffer, 0, buffer.Length).Wait();
            blob.Metadata["thing"] = "something";
            blob.SetMetadata();

            blob.Delete();

            Assert.False(File.Exists(Path.Combine(BasePath, ".meta", blobName)));
        }
Example #13
0
        public ListMetadataTests()
            : base(DirectoryType.Container)
        {
            var flatBlob = new StandaloneAzureBlockBlob(BasePath, "flat");

            flatBlob.UploadFromByteArrayAsync(Encoding.UTF8.GetBytes("flat"));
            flatBlob.Metadata["thing"] = "flat";
            flatBlob.SetMetadata();

            var withPath = new StandaloneAzureBlockBlob(BasePath, @"random\path\blob");

            withPath.UploadFromByteArrayAsync(Encoding.UTF8.GetBytes("withPath"));
            withPath.Metadata["thing"] = "withPath";
            withPath.SetMetadata();
        }
        public async Task CanDownloadBlboToStream(string blobName)
        {
            var blob = new StandaloneAzureBlockBlob(BasePath, blobName);
            await blob.UploadFromByteArrayAsync(Encoding.UTF8.GetBytes("Streamable content"));

            using (var memoryStream = new MemoryStream())
            {
                blob.DownloadToStream(memoryStream);
                memoryStream.Position = 0;

                using (var streamReader = new StreamReader(memoryStream))
                {
                    Assert.Equal("Streamable content", streamReader.ReadToEnd());
                }
            }
        }
Example #15
0
        public void CanUploadContentFromStream(string blobName)
        {
            using (var memoryStream = new MemoryStream())
            {
                var sourceContent = GenerateSourceContent();

                var buffer = Encoding.UTF8.GetBytes(sourceContent);
                memoryStream.Write(buffer, 0, buffer.Length);
                memoryStream.Position = 0;

                var blob = new StandaloneAzureBlockBlob(BasePath, blobName);
                blob.UploadFromStreamAsync(memoryStream).Wait();

                Assert.Equal(sourceContent, File.ReadAllText(blob.Uri.LocalPath));
            }
        }
Example #16
0
        public void WillHaveCorrectValuesWhenGivenContainerDirectoryAndBlobName(string blobName)
        {
            var blob = new StandaloneAzureBlockBlob(BasePath, blobName);

            new
            {
                Uri        = ToUri(blobName),
                Name       = blobName,
                Properties = new
                {
                    Length      = (long)-1,
                    ContentType = (string)null
                },
                Metadata = new Dictionary <string, string>()
            }.ToExpectedObject().ShouldMatch(blob);
        }
Example #17
0
        public void MetadataNotPersistedUntilSet(string blobName)
        {
            var sourceBlob = new StandaloneAzureBlockBlob(BasePath, blobName);

            CreateBlobContent(sourceBlob);

            sourceBlob.Metadata["thing"] = "something";

            var loadedBlob = new StandaloneAzureBlockBlob(BasePath, blobName);

            loadedBlob.FetchAttributes();

            new
            {
                Metadata = new Dictionary <string, string>()
            }.ToExpectedObject().ShouldMatch(loadedBlob);
        }
        public void WillRemoveExistingMetadataWhereSourceDoesNotHaveMetadata(string source, string destination)
        {
            var buffer     = Encoding.UTF8.GetBytes("File content");
            var sourceBlob = new StandaloneAzureBlockBlob(BasePath, source);

            sourceBlob.UploadFromByteArrayAsync(buffer, 0, buffer.Length).Wait();

            var originalContentBuffer = Encoding.UTF8.GetBytes("Original content");
            var destinationBlob       = new StandaloneAzureBlockBlob(BasePath, destination);

            destinationBlob.UploadFromByteArrayAsync(originalContentBuffer, 0, originalContentBuffer.Length).Wait();
            destinationBlob.Metadata["thing"] = "other thing";
            destinationBlob.SetMetadata();
            destinationBlob.StartCopyFromBlob(sourceBlob.Uri);

            Assert.False(File.Exists(Path.Combine(BasePath, ".meta", destination)));
        }
        public void DefaultsToOctetStreamWhenLoadingPropertiesWhenPreviouslyUnset(string blobName)
        {
            var blob = new StandaloneAzureBlockBlob(BasePath, blobName);

            CreateBlobContent(blob);

            blob.FetchAttributes();

            new
            {
                Properties = new
                {
                    ContentType = "application/octet-stream",
                    Length      = (long)12
                }
            }.ToExpectedObject().ShouldMatch(blob);
        }
        public void CopyStateIsFailedIfBlobLocked(string source, string destination)
        {
            var buffer     = Encoding.UTF8.GetBytes("File content");
            var sourceBlob = new StandaloneAzureBlockBlob(BasePath, source);

            sourceBlob.UploadFromByteArrayAsync(buffer, 0, buffer.Length).Wait();

            using (new FileStream(sourceBlob.Uri.LocalPath, FileMode.Append, FileAccess.Write, FileShare.None))
            {
                var destinationBlob = new StandaloneAzureBlockBlob(BasePath, destination);
                destinationBlob.StartCopyFromBlob(sourceBlob.Uri);

                new
                {
                    Status            = CopyStatus.Failed,
                    StatusDescription = new NotNullComparison()
                }.ToExpectedObject().ShouldMatch(destinationBlob.CopyState);
            }
        }
        public void WillThrowOnSaveOfMetadataWhenFileWriteRetriesExhausted(string blobName)
        {
            var metadataPath = Path.Combine(BasePath, ".meta", blobName);
            var sourceBlob   = new StandaloneAzureBlockBlob(BasePath, blobName);

            CreateBlobContent(sourceBlob);

            sourceBlob.Properties.ContentType = "thing";
            sourceBlob.SetProperties();

            var loadedBlob = new StandaloneAzureBlockBlob(BasePath, blobName);

            loadedBlob.FetchAttributes();
            loadedBlob.Properties.ContentType = "otherthing";

            using (File.Open(metadataPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
            {
                Assert.Throws <StorageException>(() => loadedBlob.SetProperties());
            }
        }
        public void PropertiesNotPersistedUntilSet(string blobName)
        {
            var sourceBlob = new StandaloneAzureBlockBlob(BasePath, blobName);

            CreateBlobContent(sourceBlob);

            sourceBlob.Properties.ContentType = "something";

            var loadedBlob = new StandaloneAzureBlockBlob(BasePath, blobName);

            loadedBlob.FetchAttributes();

            new
            {
                Properties = new
                {
                    ContentType = "application/octet-stream",
                }
            }.ToExpectedObject().ShouldMatch(loadedBlob);
        }
Example #23
0
        public async Task CanPersistAndRetrieveMetadataAsync(string blobName)
        {
            var sourceBlob = new StandaloneAzureBlockBlob(BasePath, blobName);

            CreateBlobContent(sourceBlob);

            sourceBlob.Metadata["thing"] = "something";
            sourceBlob.SetMetadata();

            var loadedBlob = new StandaloneAzureBlockBlob(BasePath, blobName);
            await loadedBlob.FetchAttributesAsync();

            new
            {
                Metadata = new Dictionary <string, string>
                {
                    { "thing", "something" }
                }
            }.ToExpectedObject().ShouldMatch(loadedBlob);
        }
        public async Task CanPersistAndRetrievePropertiesAsync(string blobName)
        {
            var sourceBlob = new StandaloneAzureBlockBlob(BasePath, blobName);

            CreateBlobContent(sourceBlob);

            sourceBlob.Properties.ContentType = "something";
            sourceBlob.SetProperties();

            var loadedBlob = new StandaloneAzureBlockBlob(BasePath, blobName);
            await loadedBlob.FetchAttributesAsync();

            new
            {
                Properties = new
                {
                    ContentType = "something",
                    Length      = (long)12
                }
            }.ToExpectedObject().ShouldMatch(loadedBlob);
        }
        public void PropertiesCanBeSetRepeatedly(string blobName)
        {
            var sourceBlob = new StandaloneAzureBlockBlob(BasePath, blobName);

            CreateBlobContent(sourceBlob);

            sourceBlob.Properties.ContentType = "something";
            sourceBlob.SetProperties();
            sourceBlob.Properties.ContentType = "something else";
            sourceBlob.SetProperties();

            var loadedBlob = new StandaloneAzureBlockBlob(BasePath, blobName);

            loadedBlob.FetchAttributes();

            new
            {
                Properties = new
                {
                    ContentType = "something else"
                }
            }.ToExpectedObject().ShouldMatch(loadedBlob);
        }
Example #26
0
        public void FetchingPropertiesOverwritesAnyUnsavedMetadataValues(string blobName)
        {
            var sourceBlob = new StandaloneAzureBlockBlob(BasePath, blobName);

            CreateBlobContent(sourceBlob);

            sourceBlob.Metadata["thing"] = "something";
            sourceBlob.SetMetadata();

            var loadedBlob = new StandaloneAzureBlockBlob(BasePath, blobName);

            loadedBlob.FetchAttributes();
            loadedBlob.Metadata["other thing"] = "whatever";
            loadedBlob.FetchAttributes();

            new
            {
                Metadata = new Dictionary <string, string>
                {
                    { "thing", "something" }
                }
            }.ToExpectedObject().ShouldMatch(loadedBlob);
        }
        public void FetchingAttributesOverwritesAnyUnsavedPropertyValues(string blobName)
        {
            var sourceBlob = new StandaloneAzureBlockBlob(BasePath, blobName);

            CreateBlobContent(sourceBlob);

            sourceBlob.Properties.ContentType = "something";
            sourceBlob.SetProperties();

            var loadedBlob = new StandaloneAzureBlockBlob(BasePath, blobName);

            loadedBlob.FetchAttributes();
            sourceBlob.Properties.ContentType = "something else";
            loadedBlob.FetchAttributes();

            new
            {
                Properties = new
                {
                    ContentType = "something",
                    Length      = (long)12
                }
            }.ToExpectedObject().ShouldMatch(loadedBlob);
        }
        public void WillThrowOnAsyncSaveOfPropertiesIfBlobDoesNotExist(string blobName)
        {
            var blob = new StandaloneAzureBlockBlob(BasePath, blobName);

            AssertEx.Throws <StorageException>(() => blob.SetPropertiesAsync());
        }
Example #29
0
        public void WillThrowOnSaveOfMetadataIfBlobDoesNotExist(string blobName)
        {
            var blob = new StandaloneAzureBlockBlob(BasePath, blobName);

            Assert.Throws <StorageException>(() => blob.SetMetadata());
        }
        public void CopyStateIsNullBeforeCopy(string blobName)
        {
            var blob = new StandaloneAzureBlockBlob(BasePath, blobName);

            Assert.Null(blob.CopyState);
        }