public void GetBlobCopyStateTest() { CloudBlobUtil blobUtil = new CloudBlobUtil(CommonStorageAccount); blobUtil.SetupTestContainerAndBlob(); ICloudBlob destBlob = CopyBlobAndWaitForComplete(blobUtil); try { Test.Assert(destBlob.CopyState.Status == CopyStatus.Success, String.Format("The blob copy using storage client should be success, actually it's {0}", destBlob.CopyState.Status)); PowerShellAgent agent = new PowerShellAgent(); Test.Assert(agent.GetAzureStorageBlobCopyState(blobUtil.ContainerName, destBlob.Name, false), "Get copy state should be success"); int expectedStateCount = 1; Test.Assert(agent.Output.Count == expectedStateCount, String.Format("Expected to get {0} copy state, actually it's {1}", expectedStateCount, agent.Output.Count)); CopyStatus copyStatus = (CopyStatus)agent.Output[0]["Status"]; Test.Assert(copyStatus == CopyStatus.Success, String.Format("The blob copy should be success, actually it's {0}", copyStatus)); Uri sourceUri = (Uri)agent.Output[0]["Source"]; string expectedUri = CloudBlobUtil.ConvertCopySourceUri(blobUtil.Blob.Uri.ToString()); Test.Assert(sourceUri.ToString() == expectedUri, String.Format("Expected source uri is {0}, actully it's {1}", expectedUri, sourceUri.ToString())); Test.Assert(!agent.GetAzureStorageBlobCopyState(blobUtil.ContainerName, blobUtil.BlobName, false), "Get copy state should be fail since the specified blob don't have any copy operation"); Test.Assert(agent.ErrorMessages.Count > 0, "Should return error message"); string errorMessage = "Can not find copy task on specified blob"; Test.Assert(agent.ErrorMessages[0].StartsWith(errorMessage), String.Format("Error message should start with {0}, and actually it's {1}", errorMessage, agent.ErrorMessages[0])); } finally { blobUtil.CleanupTestContainerAndBlob(); } }
private ICloudBlob AssertCopyBlobCrossContainer(ICloudBlob srcBlob, CloudBlobContainer destContainer, string destBlobName, object destContext, Func <bool> StartFunc = null) { if (StartFunc == null) { Test.Assert(agent.StartAzureStorageBlobCopy(srcBlob.Container.Name, srcBlob.Name, destContainer.Name, destBlobName, destContext), "blob copy should start sucessfully"); } else { Test.Assert(StartFunc(), "blob copy should start sucessfully"); } int expectedBlobCount = 1; Test.Assert(agent.Output.Count == expectedBlobCount, String.Format("Expected get {0} copy state, and actually it's {1}", expectedBlobCount, agent.Output.Count)); ICloudBlob destBlob = (ICloudBlob)agent.Output[0]["ICloudBlob"]; string expectedBlobName = destBlobName; if (string.IsNullOrEmpty(expectedBlobName)) { expectedBlobName = srcBlob.Name; } Test.Assert(expectedBlobName == destBlob.Name, string.Format("Expected destination blob name is {0}, and actually it's {1}", expectedBlobName, destBlob.Name)); Test.Assert(CloudBlobUtil.WaitForCopyOperationComplete(destBlob), "Copy Operation should finished"); destBlob.FetchAttributes(); string expectedSourceUri = CloudBlobUtil.ConvertCopySourceUri(srcBlob.Uri.ToString()); string sourceUri = destBlob.CopyState.Source.ToString(); Test.Assert(sourceUri.StartsWith(expectedSourceUri), String.Format("source uri should start with {0}, and actualy it's {1}", expectedSourceUri, sourceUri)); Test.Assert(destBlob.Metadata.Count > 0, "destination blob should contain meta data"); Test.Assert(destBlob.Metadata.SequenceEqual(srcBlob.Metadata), "Copied blob's meta data should be equal with origin metadata"); Test.Assert(destBlob.Properties.ContentEncoding == srcBlob.Properties.ContentEncoding, String.Format("expected content encoding is {0}, and actually it's {1}", srcBlob.Properties.ContentEncoding, destBlob.Properties.ContentEncoding)); return(destBlob); }
private void AssertFinishedCopyState(Uri SourceUri, int startIndex = 0) { string expectedSourceUri = CloudBlobUtil.ConvertCopySourceUri(SourceUri.ToString()); Test.Assert(agent.Output.Count > startIndex, String.Format("Should contain the great than {0} copy state, and actually it's {1}", startIndex, agent.Output.Count)); string sourceUri = ((Uri)agent.Output[startIndex]["Source"]).ToString(); Test.Assert(sourceUri.StartsWith(expectedSourceUri), String.Format("source uri should start with {0}, and actualy it's {1}", expectedSourceUri, sourceUri)); StorageBlob.CopyStatus status = (StorageBlob.CopyStatus)agent.Output[startIndex]["Status"]; Test.Assert(status != StorageBlob.CopyStatus.Pending, String.Format("Copy status should not be Pending, actually it's {0}", status)); string copyId = (string)agent.Output[startIndex]["CopyId"]; Test.Assert(!String.IsNullOrEmpty(copyId), "Copy ID should be not empty"); }
internal void StartCopyBlobTest(Agent agent, bool useUri) { CloudBlobUtil blobUtil = new CloudBlobUtil(CommonStorageAccount); blobUtil.SetupTestContainerAndBlob(); string copiedName = Utility.GenNameString("copied"); if (useUri) { //Set the blob permission, so the copy task could directly copy by uri BlobContainerPermissions permission = new BlobContainerPermissions(); permission.PublicAccess = BlobContainerPublicAccessType.Blob; blobUtil.Container.SetPermissions(permission); } try { if (useUri) { Test.Assert(agent.StartAzureStorageBlobCopy(blobUtil.Blob.Uri.ToString(), blobUtil.ContainerName, copiedName, PowerShellAgent.Context), Utility.GenComparisonData("Start copy blob using source uri", true)); } else { Test.Assert(agent.StartAzureStorageBlobCopy(blobUtil.ContainerName, blobUtil.BlobName, blobUtil.ContainerName, copiedName), Utility.GenComparisonData("Start copy blob using blob name", true)); } Test.Info("Get destination blob in copy task"); ICloudBlob blob = blobUtil.Container.GetBlobReferenceFromServer(copiedName); Test.Assert(blob != null, "Destination blob should exist after start copy. If not, please check it's a test issue or dev issue."); string sourceUri = CloudBlobUtil.ConvertCopySourceUri(blobUtil.Blob.Uri.ToString()); Test.Assert(blob.BlobType == blobUtil.Blob.BlobType, String.Format("The destination blob type should be {0}, actually {1}.", blobUtil.Blob.BlobType, blob.BlobType)); Test.Assert(blob.CopyState.Source.ToString().StartsWith(sourceUri), String.Format("The source of destination blob should start with {0}, and actually it's {1}", sourceUri, blob.CopyState.Source.ToString())); } finally { blobUtil.CleanupTestContainerAndBlob(); } }
private void AssertFinishedCopyState(Uri SourceUri, int startIndex = 0) { string expectedSourceUri = CloudBlobUtil.ConvertCopySourceUri(SourceUri.ToString()); Test.Assert(CommandAgent.Output.Count > startIndex, String.Format("Should contain the great than {0} copy state, and actually it's {1}", startIndex, CommandAgent.Output.Count)); if (lang == Language.PowerShell) { string sourceUri = ((Uri)CommandAgent.Output[startIndex]["Source"]).ToString(); Test.Assert(sourceUri.StartsWith(expectedSourceUri), String.Format("source uri should start with {0}, and actually it's {1}", expectedSourceUri, sourceUri)); CopyStatus status = (CopyStatus)CommandAgent.Output[startIndex]["Status"]; Test.Assert(status != CopyStatus.Pending, String.Format("Copy status should not be Pending, actually it's {0}", status)); string copyId = (string)CommandAgent.Output[startIndex]["CopyId"]; Test.Assert(!String.IsNullOrEmpty(copyId), "Copy ID should be not empty"); } else { string status = ((JObject)CommandAgent.Output[0]["copy"])["status"].ToString(); Test.Assert(status != "pending", String.Format("Copy status should not be Pending, actually it's {0}", status)); string copyId = ((JObject)CommandAgent.Output[0]["copy"])["id"].ToString(); Test.Assert(!String.IsNullOrEmpty(copyId), "Copy ID should be not empty"); } }