/// <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 #2
0
        /// <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);
            }
        }