/// <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> /// 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", true)); // Verification for returned values agent.OutputValidation(StorageAccount.CreateCloudBlobClient().ListContainers()); }
/// <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()); }
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> /// 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> /// 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 { } } }
/// <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-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); } }
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> /// 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> /// 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; } else if (agent.ErrorMessages[0].Contains("The remote server returned an error: (409) Conflict.")) { retryCount++; } else if (agent.ErrorMessages[0].Contains("The specified container is being deleted.")) { 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 { } } }
/// <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 /// 2. Get a list of blob containers by using wildcards in the name (Positive 2) /// 3. Get a list of blob containers by using Prefix (Positive 3) /// /// 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) { string errorMsg = String.Format("Container '{0}' already exists", name); Test.Assert(agent.ErrorMessages[i].Contains(errorMsg), "Expect error message {0}, actually it's: {1}", errorMsg, 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); } }
/// <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); } } }
/// <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> /// 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> /// 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); } } }