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);
        }
        internal void StorageContainerTest(Agent agent)
        {
            string NEW_CONTAINER_NAME = Utility.GenNameString("astoria-");

            //--------------New operation--------------
            Test.Assert(!agent.NewAzureStorageContainer(NEW_CONTAINER_NAME), Utility.GenComparisonData("NewAzureStorageContainer", false));
            CheckErrorOutput(agent);

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

            //--------------Set operation--------------
            Test.Assert(!agent.SetAzureStorageContainerACL(NEW_CONTAINER_NAME, BlobContainerPublicAccessType.Blob),
                "SetAzureStorageContainerACL operation should fail");
            CheckErrorOutput(agent);

            Test.Assert(!agent.SetAzureStorageContainerACL(NEW_CONTAINER_NAME, BlobContainerPublicAccessType.Container),
                "SetAzureStorageContainerACL operation should fail");
            CheckErrorOutput(agent);
        }
        /// <summary>
        /// Negative Functional Cases : for Remove-AzureStorageContainer 
        /// 1. Remove a non-existing blob container (Negative 2)
        /// </summary>
        internal void RemoveNonExistingContainer(Agent agent)
        {
            string CONTAINER_NAME = Utility.GenNameString("nonexisting");

            // Delete the container if it exists
            CloudBlobClient blobClient = StorageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = blobClient.GetContainerReference(CONTAINER_NAME);
            container.DeleteIfExists();

            //--------------Remove operation--------------
            Test.Assert(!agent.RemoveAzureStorageContainer(CONTAINER_NAME), Utility.GenComparisonData("RemoveAzureStorageContainer", false));
            // Verification for returned values
            Test.Assert(agent.Output.Count == 0, "Only 0 row returned : {0}", agent.Output.Count);
            Test.Assert(agent.ErrorMessages[0].Equals(String.Format("Can not find the container '{0}'.", CONTAINER_NAME)), agent.ErrorMessages[0]);
        }
        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
            CloudBlobContainer srcContainer = blobUtil.CreateContainer(srcContainerName);
            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
                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);
            }
        }
        /// <summary>
        /// Negative Functional Cases : for New-AzureStorageContainer 
        /// 1. Create a blob container that already exists (Negative 3)
        /// </summary>
        internal void CreateExistingContainer(Agent agent)
        {
            string CONTAINER_NAME = Utility.GenNameString("existing");

            // create container if not exists
            CloudBlobContainer container = StorageAccount.CreateCloudBlobClient().GetContainerReference(CONTAINER_NAME);
            container.CreateIfNotExists();

            try
            {
                //--------------New operation--------------
                Test.Assert(!agent.NewAzureStorageContainer(CONTAINER_NAME), Utility.GenComparisonData("NewAzureStorageContainer", false));
                // Verification for returned values
                Test.Assert(agent.Output.Count == 0, "Only 0 row returned : {0}", agent.Output.Count);
                Test.Assert(agent.ErrorMessages[0].Equals(String.Format("Container '{0}' already exists.", CONTAINER_NAME)), agent.ErrorMessages[0]);
            }
            finally
            {
                // Recover the environment
                container.DeleteIfExists();
            }
        }
        /// <summary>
        /// Functional Cases : for Get-AzureStorageContainer 
        /// 1. Validate that all the containers can be enumerated (Positive 5)
        /// </summary>
        internal void EnumerateAllContainers(Agent agent)
        {
            //--------------Get operation--------------
            Test.Assert(agent.GetAzureStorageContainer(""), Utility.GenComparisonData("GetAzureStorageContainer", false));

            // Verification for returned values
            agent.OutputValidation(StorageAccount.CreateCloudBlobClient().ListContainers());
        }
        /// <summary>
        /// Functional Cases : for New-AzureStorageQueue
        /// 1. Create a list of new Queues (Positive 2)
        /// 2. Create a list of Queues that already exist (Negative 4)
        /// 3. Create a list of Queues that some of them already exist (Negative 5)
        /// 
        /// Functional Cases : for Get-AzureStorageQueue
        /// 4.	Get a list of Queues by using wildcards in the name (Positive 2)
        /// 
        /// Functional Cases : for Remove-AzureStorageQueue
        /// 5.	Remove a list of existing Queues by using pipeline (Positive 3)
        /// </summary>
        internal void QueueListOperations(Agent agent)
        {
            string PREFIX = Utility.GenNameString("uniqueprefix-") + "-";
            string[] QUEUE_NAMES = new string[] { Utility.GenNameString(PREFIX), Utility.GenNameString(PREFIX), Utility.GenNameString(PREFIX) };

            // PART_EXISTING_NAMES differs only the last element with Queue_NAMES
            string[] PARTLY_EXISTING_NAMES = new string[QUEUE_NAMES.Length];
            Array.Copy(QUEUE_NAMES, PARTLY_EXISTING_NAMES, QUEUE_NAMES.Length - 1);
            PARTLY_EXISTING_NAMES[QUEUE_NAMES.Length - 1] = Utility.GenNameString(PREFIX);

            string[] MERGED_NAMES = QUEUE_NAMES.Union(PARTLY_EXISTING_NAMES).ToArray();
            Array.Sort(MERGED_NAMES);

            // Generate the comparison data
            Collection<Dictionary<string, object>> comp = new Collection<Dictionary<string, object>>();
            foreach (string name in MERGED_NAMES)
            {
                comp.Add(Utility.GenComparisonData(StorageObjectType.Queue, name));
            }

            CloudQueueClient queueClient = _StorageAccount.CreateCloudQueueClient();

            // Check if all the above Queues have been removed
            foreach (string name in MERGED_NAMES)
            {
                CloudQueue Queue = queueClient.GetQueueReference(name);
                Queue.DeleteIfExists();
            }

            //--------------1. New operation--------------
            Test.Assert(agent.NewAzureStorageQueue(QUEUE_NAMES), Utility.GenComparisonData("NewAzureStorageQueue", true));
            // Verification for returned values
            Test.Assert(agent.Output.Count == 3, "3 row returned : {0}", agent.Output.Count);

            // Check if all the above queues have been created
            foreach (string name in QUEUE_NAMES)
            {
                CloudQueue queue = queueClient.GetQueueReference(name);
                Test.Assert(queue.Exists(), "queue {0} should exist", name);
            }

            try
            {
                //--------------2. New operation--------------
                Test.Assert(!agent.NewAzureStorageQueue(QUEUE_NAMES), Utility.GenComparisonData("NewAzureStorageQueue", false));
                // Verification for returned values
                Test.Assert(agent.Output.Count == 0, "0 row returned : {0}", agent.Output.Count);
                int i = 0;
                foreach (string name in QUEUE_NAMES)
                {
                    Test.Assert(agent.ErrorMessages[i].Equals(String.Format("Queue '{0}' already exists.", name)), agent.ErrorMessages[i]);
                    ++i;
                }

                //--------------3. New operation--------------
                Test.Assert(!agent.NewAzureStorageQueue(PARTLY_EXISTING_NAMES), Utility.GenComparisonData("NewAzureStorageQueue", false));
                // Verification for returned values
                Test.Assert(agent.Output.Count == 1, "1 row returned : {0}", agent.Output.Count);

                // Check if all the above queues have been created
                foreach (string name in QUEUE_NAMES)
                {
                    CloudQueue queue = queueClient.GetQueueReference(name);
                    Test.Assert(queue.Exists(), "queue {0} should exist", name);
                }

                //--------------4. Get operation--------------
                Test.Assert(agent.GetAzureStorageQueue("*" + PREFIX + "*"), Utility.GenComparisonData("GetAzureStorageQueue", true));
                // Verification for returned values
                agent.OutputValidation(_StorageAccount.CreateCloudQueueClient().ListQueues(PREFIX, QueueListingDetails.All));

                // use Prefix parameter
                Test.Assert(agent.GetAzureStorageQueueByPrefix(PREFIX), Utility.GenComparisonData("GetAzureStorageQueueByPrefix", true));
                // Verification for returned values
                agent.OutputValidation(_StorageAccount.CreateCloudQueueClient().ListQueues(PREFIX, QueueListingDetails.All));
            }
            finally {
                //--------------5. Remove operation--------------
                Test.Assert(agent.RemoveAzureStorageQueue(MERGED_NAMES), Utility.GenComparisonData("RemoveAzureStorageQueue", true));
                // Check if all the above queues have been removed
                foreach (string name in QUEUE_NAMES)
                {
                    CloudQueue queue = queueClient.GetQueueReference(name);
                    Test.Assert(!queue.Exists(), "queue {0} should not exist", name);
                }
            }
        }
        internal void StorageTableTest(Agent agent)
        {
            string NEW_TABLE_NAME = Utility.GenNameString("Washington");

            //--------------New operation--------------
            Test.Assert(!agent.NewAzureStorageTable(NEW_TABLE_NAME), Utility.GenComparisonData("NewAzureStorageTable", false));
            CheckErrorOutput(agent);

            //--------------Get operation--------------
            Test.Assert(!agent.GetAzureStorageTable(NEW_TABLE_NAME), Utility.GenComparisonData("GetAzureStorageTable", false));
            CheckErrorOutput(agent);

            //--------------Remove operation--------------
            Test.Assert(!agent.RemoveAzureStorageTable(NEW_TABLE_NAME), Utility.GenComparisonData("RemoveAzureStorageTable", false));
            CheckErrorOutput(agent);
        }
        /// <summary>
        /// Functional Cases : for Get-AzureStorageQueue
        /// 1. Validate that all the queues can be enumerated (Positive 5)
        /// </summary>
        internal void EnumerateAllQueues(Agent agent)
        {
            //--------------Get operation--------------
            Test.Assert(agent.GetAzureStorageQueue(""), Utility.GenComparisonData("EnumerateAllQueues", false));

            // Verification for returned values
            agent.OutputValidation(_StorageAccount.CreateCloudQueueClient().ListQueues());
        }
        /// <summary>
        /// Positive Functional Cases : for Get-AzureStorageQueue 
        /// 1. Get the ApproximateMessageCount of the queue (Positive 5)
        /// </summary>
        internal void GetMessageCount(Agent agent)
        {
            const int MAX_SIZE = 32;
            string QUEUE_NAME = Utility.GenNameString("messagecount-");

            // create queue if not exists
            CloudQueue queue = _StorageAccount.CreateCloudQueueClient().GetQueueReference(QUEUE_NAME);
            queue.CreateIfNotExists();
            // insert random count queues
            Random random = new Random();
            int count = random.Next(MAX_SIZE) + 1;  // count >= 1
            for (int i = 1; i <= count; ++i)
                queue.AddMessage(new CloudQueueMessage("message " + i));

            // generate comparsion data
            Collection<Dictionary<string, object>> comp = new Collection<Dictionary<string, object>>();
            var dic = Utility.GenComparisonData(StorageObjectType.Queue, QUEUE_NAME);
            dic["ApproximateMessageCount"] = count;
            comp.Add(dic);

            try
            {
                //--------------Get operation--------------
                Test.Assert(agent.GetAzureStorageQueue(QUEUE_NAME), Utility.GenComparisonData("GetAzureStorageQueue", true));
                // Verification for returned values
                agent.OutputValidation(comp);
            }
            finally
            {
                queue.DeleteIfExists();
            }
        }
        /// <summary>
        /// Negative Functional Cases : for New-AzureStorageQueue 
        /// 1. Create a Queue that already exists (Negative 3)
        /// </summary>
        internal void CreateExistingQueue(Agent agent)
        {
            string QUEUE_NAME = Utility.GenNameString("existing");

            // create queue if not exists
            CloudQueue queue = _StorageAccount.CreateCloudQueueClient().GetQueueReference(QUEUE_NAME);
            queue.CreateIfNotExists();

            try
            {
                //--------------New operation--------------
                Test.Assert(!agent.NewAzureStorageQueue(QUEUE_NAME), Utility.GenComparisonData("NewAzureStorageQueue", false));
                // Verification for returned values
                Test.Assert(agent.Output.Count == 0, "Only 0 row returned : {0}", agent.Output.Count);
                Test.Assert(agent.ErrorMessages[0].Equals(String.Format("Queue '{0}' already exists.", QUEUE_NAME)), agent.ErrorMessages[0]);
            }
            finally
            {
                // Recover the environment
                queue.DeleteIfExists();
            }
        }
        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
            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));

                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
            CloudBlobContainer container = blobUtil.CreateContainer(containerName);

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

            try
            {
                // create source blob
                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 StorageContextTest(Agent agent)
        {
            string StorageAccountName = Test.Data.Get("StorageAccountName");
            string StorageAccountKey = Test.Data.Get("StorageAccountKey");
            string StorageEndPoint = Test.Data.Get("StorageEndPoint");

            Collection<Dictionary<string, object>> comp = new Collection<Dictionary<string, object>>();
            bool useHttps = true; //default protocol is https
            string[] endPoints = Utility.GetStorageEndPoints(StorageAccountName, useHttps, StorageEndPoint);
            comp.Add(new Dictionary<string, object>{
                {"StorageAccountName", StorageAccountName},
                {"BlobEndPoint", endPoints[0]},
                {"QueueEndPoint", endPoints[1]},
                {"TableEndPoint", endPoints[2]}
            });

            //--------------New operation--------------
            Test.Assert(agent.NewAzureStorageContext(StorageAccountName, StorageAccountKey, StorageEndPoint), Utility.GenComparisonData("NewAzureStorageContext", true));
            // Verification for returned values
            agent.OutputValidation(comp);
        }
        /// <summary>
        /// Negative Functional Cases : for Remove-AzureStorageQueue 
        /// 1. Remove a non-existing queue (Negative 2)
        /// </summary>
        internal void RemoveNonExistingQueue(Agent agent)
        {
            string QUEUE_NAME = Utility.GenNameString("nonexisting");

            // Delete the queue if it exists
            CloudQueue queue = _StorageAccount.CreateCloudQueueClient().GetQueueReference(QUEUE_NAME);
            queue.DeleteIfExists();

            //--------------Remove operation--------------
            Test.Assert(!agent.RemoveAzureStorageQueue(QUEUE_NAME), Utility.GenComparisonData("RemoveAzureStorageQueue", false));
            // Verification for returned values
            Test.Assert(agent.Output.Count == 0, "Only 0 row returned : {0}", agent.Output.Count);
            Test.Assert(agent.ErrorMessages[0].Equals(String.Format("Can not find queue '{0}'.", QUEUE_NAME)), agent.ErrorMessages[0]);
        }
        internal void StorageQueueTest(Agent agent)
        {
            string NEW_QUEUE_NAME = Utility.GenNameString("redmond-");

            //--------------New operation--------------
            Test.Assert(!agent.NewAzureStorageQueue(NEW_QUEUE_NAME), Utility.GenComparisonData("NewAzureStorageQueue", false));
            CheckErrorOutput(agent);

            //--------------Get operation--------------
            Test.Assert(!agent.GetAzureStorageQueue(NEW_QUEUE_NAME), Utility.GenComparisonData("GetAzureStorageQueue", false));
            CheckErrorOutput(agent);

            //--------------Remove operation--------------
            Test.Assert(!agent.RemoveAzureStorageQueue(NEW_QUEUE_NAME), Utility.GenComparisonData("RemoveAzureStorageQueue", false));
            CheckErrorOutput(agent);
        }
        /// <summary>
        /// Negative Functional Cases : for Remove-AzureStorageQueue 
        /// 1. Remove the queue without by force (Negative 3)
        /// </summary>
        internal void RemoveQueueWithoutForce(Agent agent)
        {
            string QUEUE_NAME = Utility.GenNameString("withoutforce-");

            // create queue if not exists
            CloudQueue queue = _StorageAccount.CreateCloudQueueClient().GetQueueReference(QUEUE_NAME);
            queue.CreateIfNotExists();

            try
            {
                //--------------Remove operation--------------
                Test.Assert(!agent.RemoveAzureStorageQueue(QUEUE_NAME, false), Utility.GenComparisonData("RemoveAzureStorageQueue", false));
                // Verification for returned values
                Test.Assert(agent.Output.Count == 0, "Only 0 row returned : {0}", agent.Output.Count);
                Test.Assert(agent.ErrorMessages[0].StartsWith("A command that prompts the user failed because"), agent.ErrorMessages[0]);
            }
            finally
            {
                queue.DeleteIfExists();
            }
        }
        /// <summary>
        /// Functional Cases : for New-AzureStorageContainer
        /// 1. Create a list of new blob containers (Positive 2)
        /// 2. Create a list of containers that some of them already exist (Negative 4)
        /// 
        /// Functional Cases : for Get-AzureStorageContainer
        /// 3.	Get a list of blob containers by using wildcards in the name (Positive 2)
        /// 
        /// Functional Cases : for Remove-AzureStorageContainer
        /// 4.	Remove a list of existing blob containers by using pipeline (Positive 6)
        /// </summary>
        internal void ContainerListOperations(Agent agent)
        {
            string PREFIX = Utility.GenNameString("uniqueprefix-") + "-";
            string[] CONTAINER_NAMES = new string[] { Utility.GenNameString(PREFIX), Utility.GenNameString(PREFIX), Utility.GenNameString(PREFIX) };

            // PART_EXISTING_NAMES differs only the last element with CONTAINER_NAMES
            string[] PARTLY_EXISTING_NAMES = new string[CONTAINER_NAMES.Length];
            Array.Copy(CONTAINER_NAMES, PARTLY_EXISTING_NAMES, CONTAINER_NAMES.Length - 1);
            PARTLY_EXISTING_NAMES[CONTAINER_NAMES.Length - 1] = Utility.GenNameString(PREFIX);

            string[] MERGED_NAMES = CONTAINER_NAMES.Union(PARTLY_EXISTING_NAMES).ToArray();
            Array.Sort(MERGED_NAMES);

            // Generate the comparison data
            Collection<Dictionary<string, object>> comp = new Collection<Dictionary<string, object>>();
            foreach (string name in MERGED_NAMES)
                comp.Add(Utility.GenComparisonData(StorageObjectType.Container, name));

            CloudBlobClient blobClient = StorageAccount.CreateCloudBlobClient();

            // Check if all the above containers have been removed
            foreach (string name in MERGED_NAMES)
            {
                CloudBlobContainer container = blobClient.GetContainerReference(name);
                container.DeleteIfExists();
            }

            //--------------1. New operation--------------
            Test.Assert(agent.NewAzureStorageContainer(CONTAINER_NAMES), Utility.GenComparisonData("NewAzureStorageContainer", true));
            // Verification for returned values
            Test.Assert(agent.Output.Count == CONTAINER_NAMES.Count(), "3 row returned : {0}", agent.Output.Count);

            // Check if all the above containers have been created
            foreach (string name in CONTAINER_NAMES)
            {
                CloudBlobContainer container = blobClient.GetContainerReference(name);
                Test.Assert(container.Exists(), "container {0} should exist", name);
            }

            try
            {
                //--------------2. New operation--------------
                Test.Assert(!agent.NewAzureStorageContainer(CONTAINER_NAMES), Utility.GenComparisonData("NewAzureStorageContainer", false));
                // Verification for returned values
                Test.Assert(agent.Output.Count == 0, "0 row returned : {0}", agent.Output.Count);
                int i = 0;
                foreach (string name in CONTAINER_NAMES)
                {
                    Test.Assert(agent.ErrorMessages[i].Equals(String.Format("Container '{0}' already exists.", name)), agent.ErrorMessages[i]);
                    ++i;
                }

                //--------------3. New operation--------------
                Test.Assert(!agent.NewAzureStorageContainer(PARTLY_EXISTING_NAMES), Utility.GenComparisonData("NewAzureStorageContainer", false));
                // Verification for returned values
                Test.Assert(agent.Output.Count == 1, "1 row returned : {0}", agent.Output.Count);

                // Check if all the above containers have been created
                foreach (string name in CONTAINER_NAMES)
                {
                    CloudBlobContainer container = blobClient.GetContainerReference(name);
                    Test.Assert(container.Exists(), "container {0} should exist", name);
                }

                //--------------4. Get operation--------------
                // use wildcards
                Test.Assert(agent.GetAzureStorageContainer("*" + PREFIX + "*"), Utility.GenComparisonData("GetAzureStorageContainer", true));
                // Verification for returned values
                agent.OutputValidation(StorageAccount.CreateCloudBlobClient().ListContainers(PREFIX, ContainerListingDetails.All));

                // use Prefix parameter
                Test.Assert(agent.GetAzureStorageContainerByPrefix(PREFIX), Utility.GenComparisonData("GetAzureStorageContainerByPrefix", true));
                // Verification for returned values
                agent.OutputValidation(StorageAccount.CreateCloudBlobClient().ListContainers(PREFIX, ContainerListingDetails.All));
            }
            finally { }

            //--------------5. Remove operation--------------
            Test.Assert(agent.RemoveAzureStorageContainer(MERGED_NAMES), Utility.GenComparisonData("RemoveAzureStorageContainer", true));
            // Check if all the above containers have been removed
            foreach (string name in CONTAINER_NAMES)
            {
                CloudBlobContainer container = blobClient.GetContainerReference(name);
                Test.Assert(!container.Exists(), "container {0} should not exist", name);
            }
        }
Beispiel #19
0
        /// <summary>
        /// Negative Functional Cases : for Remove-AzureStorageBlob 
        /// 1. Remove a non-existing blob (Negative 2)
        /// </summary>
        internal void RemoveNonExistingBlob(Agent agent)
        {
            string CONTAINER_NAME = Utility.GenNameString("upload-");
            string BLOB_NAME = Utility.GenNameString("nonexisting");

            // create the container
            CloudBlobContainer container = StorageAccount.CreateCloudBlobClient().GetContainerReference(CONTAINER_NAME);
            container.CreateIfNotExists();

            try
            {
                // Delete the blob if it exists
                ICloudBlob blob = BlobHelper.QueryBlob(CONTAINER_NAME, BLOB_NAME);
                if (blob != null)
                    blob.DeleteIfExists();

                //--------------Remove operation--------------
                Test.Assert(!agent.RemoveAzureStorageBlob(BLOB_NAME, CONTAINER_NAME), Utility.GenComparisonData("RemoveAzureStorageBlob", false));
                // Verification for returned values
                Test.Assert(agent.Output.Count == 0, "Only 0 row returned : {0}", agent.Output.Count);
                Test.Assert(agent.ErrorMessages[0].Equals(String.Format("Can not find blob '{0}' in container '{1}'.", BLOB_NAME, CONTAINER_NAME)), agent.ErrorMessages[0]);
            }
            finally
            {
                container.DeleteIfExists();
            }
        }
        /// <summary>
        /// Negative Functional Cases : for New-AzureStorageContainer 
        /// 1. Create a new blob containter with an invalid blob container name (Negative 1)
        /// </summary>
        internal void CreateInvalidContainer(Agent agent)
        {
            string containerName = Utility.GenNameString("abc_");

            //--------------New operation--------------
            Test.Assert(!agent.NewAzureStorageContainer(containerName), Utility.GenComparisonData("NewAzureStorageContainer", false));
            // Verification for returned values
            Test.Assert(agent.Output.Count == 0, "Only 0 row returned : {0}", agent.Output.Count);
            Test.Assert(agent.ErrorMessages[0].StartsWith(String.Format("Container name '{0}' is invalid.", containerName)), agent.ErrorMessages[0]);
        }
Beispiel #21
0
        /// <summary>
        /// Functional Cases:
        /// 1. Upload a new blob file in the root container     (Set-AzureStorageBlobContent Positive 2)
        /// 2. Get an existing blob in the root container       (Get-AzureStorageBlob Positive 2)
        /// 3. Download an existing blob in the root container  (Get-AzureStorageBlobContent Positive 2)
        /// 4. Remove an existing blob in the root container    (Remove-AzureStorageBlob Positive 2)
        /// </summary>
        internal void RootBlobOperations(Agent agent, string UploadFilePath, string DownloadDirPath, Microsoft.WindowsAzure.Storage.Blob.BlobType Type)
        {
            const string ROOT_CONTAINER_NAME = "$root";
            string blobName = Path.GetFileName(UploadFilePath);
            string downloadFilePath = Path.Combine(DownloadDirPath, blobName);

            Collection<Dictionary<string, object>> comp = new Collection<Dictionary<string, object>>();
            Dictionary<string, object> dic = Utility.GenComparisonData(StorageObjectType.Blob, blobName);

            dic["BlobType"] = Type;
            comp.Add(dic);

            // create the container
            CloudBlobContainer container = StorageAccount.CreateCloudBlobClient().GetRootContainerReference();
            container.CreateIfNotExists();

            //--------------Upload operation--------------
            Test.Assert(agent.SetAzureStorageBlobContent(UploadFilePath, ROOT_CONTAINER_NAME, Type), Utility.GenComparisonData("SendAzureStorageBlob", true));
            ICloudBlob blob = BlobHelper.QueryBlob(ROOT_CONTAINER_NAME, blobName);
            blob.FetchAttributes();
            // Verification for returned values
            CloudBlobUtil.PackBlobCompareData(blob, dic);
            agent.OutputValidation(comp);

            Test.Assert(blob.Exists(), "blob " + blobName + " should exist!");

            // validate the ContentType value for GetAzureStorageBlob operation
            if (Type == Microsoft.WindowsAzure.Storage.Blob.BlobType.BlockBlob)
            {
                dic["ContentType"] = "application/octet-stream";
            }

            //--------------Get operation--------------
            Test.Assert(agent.GetAzureStorageBlob(blobName, ROOT_CONTAINER_NAME), Utility.GenComparisonData("GetAzureStorageBlob", true));
            // Verification for returned values
            agent.OutputValidation(comp);

            //--------------Download operation--------------
            downloadFilePath = Path.Combine(DownloadDirPath, blobName);
            Test.Assert(agent.GetAzureStorageBlobContent(blobName, downloadFilePath, ROOT_CONTAINER_NAME),
                Utility.GenComparisonData("GetAzureStorageBlobContent", true));
            // Verification for returned values
            agent.OutputValidation(comp);

            Test.Assert(Helper.CompareTwoFiles(downloadFilePath, UploadFilePath),
                String.Format("File '{0}' should be bit-wise identicial to '{1}'", downloadFilePath, UploadFilePath));

            //--------------Remove operation--------------
            Test.Assert(agent.RemoveAzureStorageBlob(blobName, ROOT_CONTAINER_NAME), Utility.GenComparisonData("RemoveAzureStorageBlob", true));
            blob = BlobHelper.QueryBlob(ROOT_CONTAINER_NAME, blobName);
            Test.Assert(blob == null, "blob {0} should not exist!", blobName);
        }
        /// <summary>
        /// Negative Functional Cases : for Remove-AzureStorageContainer 
        /// 1. Remove the blob container with blobs in it without by force (Negative 3)
        /// </summary>
        internal void RemoveContainerWithoutForce(Agent agent)
        {
            string CONTAINER_NAME = Utility.GenNameString("withoutforce-");

            // create container if not exists
            CloudBlobClient blobClient = StorageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = blobClient.GetContainerReference(CONTAINER_NAME);
            container.CreateIfNotExists();

            try
            {
                //--------------Remove operation--------------
                Test.Assert(!agent.RemoveAzureStorageContainer(CONTAINER_NAME, false), Utility.GenComparisonData("RemoveAzureStorageContainer", false));
                // Verification for returned values
                Test.Assert(agent.Output.Count == 0, "Only 0 row returned : {0}", agent.Output.Count);
                Test.Assert(agent.ErrorMessages[0].StartsWith("A command that prompts the user failed because"), agent.ErrorMessages[0]);
            }
            finally
            {
                // Recover the environment
                container.DeleteIfExists();
            }
        }
        internal void CheckErrorOutput(Agent agent)
        {
            Test.Assert(agent.Output.Count == 0, "Only 0 row returned : {0}", agent.Output.Count);

            //the same error may output different error messages in different environments
            bool expectedError = agent.ErrorMessages[0].StartsWith("The remote server returned an error: (502) Bad Gateway") ||
                agent.ErrorMessages[0].StartsWith("The remote name could not be resolved") ||
                agent.ErrorMessages[0].StartsWith("The operation has timed out");
            Test.Assert(expectedError, "use invalid storage account should return 502 or time out, actually it's {0}", agent.ErrorMessages[0]);
        }
        /// <summary>
        /// Functional Cases:
        /// 1. Create the root container  (New-AzureStorageContainer Positive 4)
        /// 2. Get the root container (Get-AzureStorageContainer Positive 4)
        /// 3. Remove the root container  (Remove-AzureStorageContainer Positive 4)
        /// </summary>
        internal void RootContainerOperations(Agent agent)
        {
            const string ROOT_CONTAINER_NAME = "$root";
            Dictionary<string, object> dic = Utility.GenComparisonData(StorageObjectType.Container, ROOT_CONTAINER_NAME);
            Collection<Dictionary<string, object>> comp = new Collection<Dictionary<string, object>> { dic };

            // delete container if it not exists
            CloudBlobContainer container = StorageAccount.CreateCloudBlobClient().GetRootContainerReference();
            bool bExists = container.Exists();
            if (bExists)
            {
                container.Delete();
            }

            try
            {
                //--------------New operation--------------
                bool created = false;
                int retryCount = 0;
                int maxRetryCount = 60; //retry ten minutes

                do
                {
                    if (retryCount > 0)
                    {
                        int sleepInterval = 10 * 1000;
                        Test.Info("Sleep and wait for retry...");
                        Thread.Sleep(sleepInterval);
                        Test.Info(string.Format("{0}th retry to create the $root container", retryCount));
                    }

                    bool successed = agent.NewAzureStorageContainer(ROOT_CONTAINER_NAME);

                    if (successed)
                    {
                        Test.Info("Create $root container successfully");
                        created = true;
                    }
                    else
                    {
                        if (agent.ErrorMessages.Count == 0)
                        {
                            Test.AssertFail("Can not create $root container and can't get any error messages");
                            break;
                        }

                        if (agent.ErrorMessages[0].StartsWith("The remote server returned an error: (409) Conflict."))
                        {
                            retryCount++;
                        }
                        else
                        {
                            Test.AssertFail(string.Format("Can not create $root container. Exception: {0}", agent.ErrorMessages[0]));
                            break;
                        }
                    }
                }
                while (!created && retryCount < maxRetryCount);

                if (!created && retryCount == maxRetryCount)
                {
                    Test.AssertFail(string.Format("Can not create $root container after {0} times retry", retryCount));
                }

                container.FetchAttributes();
                CloudBlobUtil.PackContainerCompareData(container, dic);
                // Verification for returned values
                agent.OutputValidation(comp);
                Test.Assert(container.Exists(), "container {0} should exist!", ROOT_CONTAINER_NAME);

                //--------------Get operation--------------
                Test.Assert(agent.GetAzureStorageContainer(ROOT_CONTAINER_NAME), Utility.GenComparisonData("GetAzureStorageContainer", true));
                // Verification for returned values
                agent.OutputValidation(comp);

                //--------------Remove operation--------------
                Test.Assert(agent.RemoveAzureStorageContainer(ROOT_CONTAINER_NAME), Utility.GenComparisonData("RemoveAzureStorageContainer", true));
                Test.Assert(!container.Exists(), "container {0} should not exist!", ROOT_CONTAINER_NAME);
            }
            finally
            {
                // Recover the environment
                try
                {
                    if (bExists)
                    {
                        Test.Info("Sleep for 150 seconds to wait for removing the root container");
                        System.Threading.Thread.Sleep(150000);
                        //The following statement often throw an 409 conflict exception
                        container.Create();
                    }
                }
                catch
                { }
            }
        }
Beispiel #25
0
        /// <summary>
        /// Negative Functional Cases : for Get-AzureStorageTable 
        /// 1. Get a non-existing table (Negative 1)
        /// </summary>
        internal void GetNonExistingTable(Agent agent)
        {
            string TABLE_NAME = Utility.GenNameString("nonexisting");

            // Delete the table if it exists
            CloudTable table = _StorageAccount.CreateCloudTableClient().GetTableReference(TABLE_NAME);
            table.DeleteIfExists();

            //--------------Get operation--------------
            Test.Assert(!agent.GetAzureStorageTable(TABLE_NAME), Utility.GenComparisonData("GetAzureStorageTable", false));
            // Verification for returned values
            Test.Assert(agent.Output.Count == 0, "Only 0 row returned : {0}", agent.Output.Count);
            Test.Assert(agent.ErrorMessages[0].Equals(String.Format("Can not find table '{0}'.", TABLE_NAME)), agent.ErrorMessages[0]);
        }