コード例 #1
0
        public async Task CloudBlobSnapshotMetadataTask()
        {
            CloudBlobContainer container = GetRandomContainerReference();

            try
            {
                await container.CreateAsync();

                var             blobName   = GetRandomBlobName();
                CloudAppendBlob appendBlob = container.GetAppendBlobReference(blobName);
                await appendBlob.CreateOrReplaceAsync(null, null, new OperationContext());

                CloudBlob blob = container.GetBlobReference(blobName);
                blob.Metadata["Hello"] = "World";
                blob.Metadata["Marco"] = "Polo";
                await blob.SetMetadataAsync();

                IDictionary <string, string> snapshotMetadata = new Dictionary <string, string>();
                snapshotMetadata["Hello"] = "Dolly";
                snapshotMetadata["Yoyo"]  = "Ma";

                CloudBlob snapshot = await blob.SnapshotAsync(snapshotMetadata, null, null, null);

                // Test the client view against the expected metadata
                // Metadata keys should be case-insensitive
                // None of the original metadata should be present
                Assert.AreEqual("Dolly", snapshot.Metadata["Hello"]);
                Assert.AreEqual("Dolly", snapshot.Metadata["HELLO"]);
                Assert.AreEqual("Ma", snapshot.Metadata["Yoyo"]);
                Assert.IsFalse(snapshot.Metadata.ContainsKey("Marco"));

                // Test the server view against the expected metadata
                await snapshot.FetchAttributesAsync();

                Assert.AreEqual("Dolly", snapshot.Metadata["Hello"]);
                Assert.AreEqual("Dolly", snapshot.Metadata["HELLO"]);
                Assert.AreEqual("Ma", snapshot.Metadata["Yoyo"]);
                Assert.IsFalse(snapshot.Metadata.ContainsKey("Marco"));
            }
            finally
            {
                await container.DeleteIfExistsAsync();
            }
        }
コード例 #2
0
        public async Task CloudBlobSnapshotMetadataAsync()
        {
            CloudBlobContainer container = GetRandomContainerReference();

            try
            {
                await container.CreateAsync();

                CloudBlockBlob blockBlob = container.GetBlockBlobReference(BlobName);
                await CloudBlockBlobTest.CreateForTestAsync(blockBlob, 2, 1024);

                CloudBlob blob = container.GetBlockBlobReference(BlobName);
                blob.Metadata["Hello"] = "World";
                blob.Metadata["Marco"] = "Polo";
                await blob.SetMetadataAsync();

                IDictionary <string, string> snapshotMetadata = new Dictionary <string, string>();
                snapshotMetadata["Hello"] = "Dolly";
                snapshotMetadata["Yoyo"]  = "Ma";

                CloudBlob snapshot = await blob.SnapshotAsync(snapshotMetadata, null, null, null);

                // Test the client view against the expected metadata
                // None of the original metadata should be present
                Assert.AreEqual("Dolly", snapshot.Metadata["Hello"]);
                Assert.AreEqual("Ma", snapshot.Metadata["Yoyo"]);
                Assert.IsFalse(snapshot.Metadata.ContainsKey("Marco"));

                // Test the server view against the expected metadata
                await snapshot.FetchAttributesAsync();

                Assert.AreEqual("Dolly", snapshot.Metadata["Hello"]);
                Assert.AreEqual("Ma", snapshot.Metadata["Yoyo"]);
                Assert.IsFalse(snapshot.Metadata.ContainsKey("Marco"));
            }
            finally
            {
                container.DeleteIfExistsAsync().Wait();
            }
        }