internal void UploadBlobTestGB(Agent agent, StorageBlob.BlobType blobType)
        {
            string uploadFilePath = @".\" + Utility.GenNameString("gbupload");
            string containerName = Utility.GenNameString("gbupload-");
            string blobName = Path.GetFileName(uploadFilePath);

            // create the container
            StorageBlob.CloudBlobContainer container = blobUtil.CreateContainer(containerName);

            // Generate a 512 bytes file which contains GB18030 characters
            File.WriteAllText(uploadFilePath, GB18030String);

            try
            {
                //--------------Upload operation--------------
                Test.Assert(agent.SetAzureStorageBlobContent(uploadFilePath, containerName, blobType), 
                    Utility.GenComparisonData("SendAzureStorageBlob", true));

                StorageBlob.ICloudBlob blob = CloudBlobUtil.GetBlob(container, blobName, blobType);
                Test.Assert(blob != null && blob.Exists(), "blob " + blobName + " should exist!");

                // Check MD5
                string localMd5 = Helper.GetFileContentMD5(uploadFilePath);
                blob.FetchAttributes();
                Test.Assert(localMd5 == blob.Properties.ContentMD5, 
                    string.Format("blob content md5 should be {0}, and actualy it's {1}", localMd5, blob.Properties.ContentMD5));
            }
            finally
            {
                // cleanup
                container.DeleteIfExists();
                File.Delete(uploadFilePath);
            }
        }
        internal void DownloadBlobTestGB(Agent agent, StorageBlob.BlobType blobType)
        {
            string uploadFilePath = @".\" + Utility.GenNameString("gbupload");
            string downloadFilePath = @".\" + Utility.GenNameString("gbdownload");
            string containerName = Utility.GenNameString("gbupload-");
            string blobName = Path.GetFileName(uploadFilePath);

            // create the container
            StorageBlob.CloudBlobContainer container = blobUtil.CreateContainer(containerName);

            // Generate a 512 bytes file which contains GB18030 characters
            File.WriteAllText(uploadFilePath, GB18030String);

            try
            {
                // create source blob
                StorageBlob.ICloudBlob blob = CloudBlobUtil.GetBlob(container, blobName, blobType);

                // upload file data
                using (var fileStream = System.IO.File.OpenRead(uploadFilePath))
                {
                    blob.UploadFromStream(fileStream);
                }

                //--------------Download operation--------------
                Test.Assert(agent.GetAzureStorageBlobContent(blobName, downloadFilePath, containerName, true), "download blob should be successful");

                // Check MD5
                string localMd5 = Helper.GetFileContentMD5(downloadFilePath);
                string uploadMd5 = Helper.GetFileContentMD5(uploadFilePath);
                blob.FetchAttributes();
                Test.Assert(localMd5 == uploadMd5, string.Format("blob content md5 should be {0}, and actualy it's {1}", localMd5, uploadMd5));
            }
            finally
            {
                // cleanup
                container.DeleteIfExists();
                File.Delete(uploadFilePath);
                File.Delete(downloadFilePath);
            }
        }
        internal void CopyBlobTestGB(Agent agent, StorageBlob.BlobType blobType)
        {
            string uploadFilePath = @".\" + Utility.GenNameString("gbupload");
            string srcContainerName = Utility.GenNameString("gbupload-", 15);
            string destContainerName = Utility.GenNameString("gbupload-", 15);
            string blobName = Path.GetFileName(uploadFilePath);

            // create the container
            StorageBlob.CloudBlobContainer srcContainer = blobUtil.CreateContainer(srcContainerName);
            StorageBlob.CloudBlobContainer destContainer = blobUtil.CreateContainer(destContainerName);

            // Generate a 512 bytes file which contains GB18030 characters
            File.WriteAllText(uploadFilePath, GB18030String);

            string localMd5 = Helper.GetFileContentMD5(uploadFilePath);

            try
            {
                // create source blob
                StorageBlob.ICloudBlob blob = CloudBlobUtil.GetBlob(srcContainer, blobName, blobType);

                // upload file data
                using (var fileStream = System.IO.File.OpenRead(uploadFilePath))
                {
                    blob.UploadFromStream(fileStream);
                    // need to set MD5 as for page blob, it won't set MD5 automatically
                    blob.Properties.ContentMD5 = localMd5;
                    blob.SetProperties();
                }

                //--------------Copy blob operation--------------
                Test.Assert(agent.StartAzureStorageBlobCopy(srcContainerName, blobName, destContainerName, blobName), Utility.GenComparisonData("Start copy blob using blob name", true));

                // Get destination blob
                blob = CloudBlobUtil.GetBlob(destContainer, blobName, blobType);

                // Check MD5               
                blob.FetchAttributes();
                Test.Assert(localMd5 == blob.Properties.ContentMD5,
                    string.Format("blob content md5 should be {0}, and actualy it's {1}", localMd5, blob.Properties.ContentMD5));
            }
            finally
            {
                // cleanup
                srcContainer.DeleteIfExists();
                destContainer.DeleteIfExists();
                File.Delete(uploadFilePath);
            }
        }
Beispiel #4
0
        /// <summary>
        /// download specified blob
        /// </summary>
        /// <param name="container"></param>
        /// <param name="blob"></param>
        private void DownloadBlobFromContainer(CloudBlobContainer container, StorageBlob.BlobType type)
        {
            string blobName = Utility.GenNameString("blob");
            ICloudBlob blob = blobUtil.CreateBlob(container, blobName, type);

            string filePath = Path.Combine(downloadDirRoot, blob.Name);
            Test.Assert(agent.GetAzureStorageBlobContent(blob.Name, filePath, container.Name, true), "download blob should be successful");
            string localMd5 = Helper.GetFileContentMD5(filePath);
            Test.Assert(localMd5 == blob.Properties.ContentMD5, string.Format("local content md5 should be {0}, and actualy it's {1}", blob.Properties.ContentMD5, localMd5));
            agent.OutputValidation(new List<ICloudBlob> { blob });
        }
        public void SetBlobContentWithProperties(StorageBlob.BlobType blobType)
        {
            string filePath = FileUtil.GenerateOneTempTestFile();
            CloudBlobContainer container = blobUtil.CreateContainer();
            Hashtable properties = new Hashtable();
            properties.Add("CacheControl", Utility.GenNameString(string.Empty));
            properties.Add("ContentEncoding", Utility.GenNameString(string.Empty));
            properties.Add("ContentLanguage", Utility.GenNameString(string.Empty));
            properties.Add("ContentMD5", Utility.GenNameString(string.Empty));
            properties.Add("ContentType", Utility.GenNameString(string.Empty));

            try
            {
                Test.Assert(agent.SetAzureStorageBlobContent(filePath, container.Name, blobType, string.Empty, true, -1, properties), "set blob content with property should succeed");
                ICloudBlob blob = container.GetBlobReferenceFromServer(Path.GetFileName(filePath));
                blob.FetchAttributes();
                ExpectEqual(properties["CacheControl"].ToString(), blob.Properties.CacheControl, "Cache control");
                ExpectEqual(properties["ContentEncoding"].ToString(), blob.Properties.ContentEncoding, "Content Encoding");
                ExpectEqual(properties["ContentLanguage"].ToString(), blob.Properties.ContentLanguage, "Content Language");
                ExpectEqual(properties["ContentMD5"].ToString(), blob.Properties.ContentMD5, "Content MD5");
                ExpectEqual(properties["ContentType"].ToString(), blob.Properties.ContentType, "Content Type");
            }
            finally
            {
                blobUtil.RemoveContainer(container.Name);
                FileUtil.RemoveFile(filePath);
            }
        }
        public void SetBlobContentWithMetadata(StorageBlob.BlobType blobType)
        {
            string filePath = FileUtil.GenerateOneTempTestFile();
            CloudBlobContainer container = blobUtil.CreateContainer();
            Hashtable metadata = new Hashtable();
            int metaCount = GetRandomTestCount();

            for (int i = 0; i < metaCount; i++)
            {
                string key = Utility.GenRandomAlphabetString();
                string value = Utility.GenNameString(string.Empty);

                if (!metadata.ContainsKey(key))
                {
                    Test.Info(string.Format("Add meta key: {0} value : {1}", key, value));
                    metadata.Add(key, value);
                }
            }

            try
            {
                Test.Assert(agent.SetAzureStorageBlobContent(filePath, container.Name, blobType, string.Empty, true, -1, null, metadata), "set blob content with meta should succeed");
                ICloudBlob blob = container.GetBlobReferenceFromServer(Path.GetFileName(filePath));
                blob.FetchAttributes();
                ExpectEqual(metadata.Count, blob.Metadata.Count, "meta data count");

                foreach (string key in metadata.Keys)
                {
                    ExpectEqual(metadata[key].ToString(), blob.Metadata[key], "Meta data key " + key);
                }
            }
            finally
            {
                blobUtil.RemoveContainer(container.Name);
                FileUtil.RemoveFile(filePath);
            }
        }
        internal void StorageBlobTest(Agent agent, string FilePath, StorageBlob.BlobType Type)
        {
            string NEW_CONTAINER_NAME = Utility.GenNameString("upload-");
            string BlobName = Path.GetFileName(FilePath);

            //--------------Upload operation--------------
            Test.Assert(!agent.SetAzureStorageBlobContent(FilePath, NEW_CONTAINER_NAME, Type), Utility.GenComparisonData("SendAzureStorageBlob", false));
            CheckErrorOutput(agent);

            //--------------Get operation--------------
            Test.Assert(!agent.GetAzureStorageBlob(BlobName, NEW_CONTAINER_NAME), Utility.GenComparisonData("GetAzureStorageBlob", false));
            CheckErrorOutput(agent);

            //--------------Remove operation--------------
            Test.Assert(!agent.RemoveAzureStorageBlob(BlobName, NEW_CONTAINER_NAME), Utility.GenComparisonData("RemoveAzureStorageBlob", false));
            CheckErrorOutput(agent);
        }
 /// <summary>
 /// download test in specified container
 /// </summary>
 /// <param name="container">CloudBlobContainer object</param>
 private void DownloadBlobFromContainerTest(StorageBlob.CloudBlobContainer container)
 {
     DownloadBlobFromContainer(container, StorageBlob.BlobType.BlockBlob);
     DownloadBlobFromContainer(container, StorageBlob.BlobType.PageBlob);
 }