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); } }
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); } }