Exemplo n.º 1
0
        /// <summary>
        /// Negative Functional Cases : for Get-AzureStorageBlob 
        /// 1. Get a non-existing blob (Negative 1)
        /// </summary>
        internal void GetNonExistingBlob(Agent agent)
        {
            string CONTAINER_NAME = Utility.GenNameString("upload-");

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

            try
            {
                string BLOB_NAME = Utility.GenNameString("nonexisting");

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

                //--------------Get operation--------------
                Test.Assert(!agent.GetAzureStorageBlob(BLOB_NAME, CONTAINER_NAME), Utility.GenComparisonData("GetAzureStorageBlob", 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
            {
                // cleanup
                container.DeleteIfExists();
            }
        }
Exemplo n.º 2
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);
        }
        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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        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);
        }