Esempio n. 1
0
        public void SetBlobContentWithProperties(StorageBlob.BlobType blobType)
        {
            string             filePath   = FileUtil.GenerateOneTempTestFile();
            CloudBlobContainer container  = blobUtil.CreateContainer();
            Hashtable          properties = new Hashtable();

            properties.Add("CacheControl", Utility.GenNameString(string.Empty));
            properties.Add("ContentEncoding", Utility.GenNameString(string.Empty));
            properties.Add("ContentLanguage", Utility.GenNameString(string.Empty));
            properties.Add("ContentType", Utility.GenNameString(string.Empty));

            try
            {
                Test.Assert(CommandAgent.SetAzureStorageBlobContent(filePath, container.Name, blobType, string.Empty, true, -1, properties), "set blob content with property should succeed");
                CloudBlob blob = StorageExtensions.GetBlobReferenceFromServer(container, Path.GetFileName(filePath));
                blob.FetchAttributes();
                ExpectEqual(properties["CacheControl"].ToString(), blob.Properties.CacheControl, "Cache control");
                ExpectEqual(properties["ContentEncoding"].ToString(), blob.Properties.ContentEncoding, "Content Encoding");
                ExpectEqual(properties["ContentLanguage"].ToString(), blob.Properties.ContentLanguage, "Content Language");
                ExpectEqual(properties["ContentType"].ToString(), blob.Properties.ContentType, "Content Type");
            }
            finally
            {
                blobUtil.RemoveContainer(container.Name);
                FileUtil.RemoveFile(filePath);
            }
        }
Esempio n. 2
0
        public void SetBlobContentWithSubDirectory()
        {
            DirectoryInfo rootDir = new DirectoryInfo(uploadDirRoot);

            DirectoryInfo[] dirs = rootDir.GetDirectories();

            foreach (DirectoryInfo dir in dirs)
            {
                string             containerName = Utility.GenNameString("container");
                CloudBlobContainer container     = blobUtil.CreateContainer(containerName);

                try
                {
                    List <IListBlobItem> blobLists = container.ListBlobs(string.Empty, true, BlobListingDetails.All).ToList();
                    Test.Assert(blobLists.Count == 0, string.Format("container {0} should contain {1} blobs, and actually it contain {2} blobs", containerName, 0, blobLists.Count));

                    StorageBlob.BlobType blobType = StorageBlob.BlobType.BlockBlob;

                    if (dir.Name.StartsWith("dirpage"))
                    {
                        blobType = Microsoft.WindowsAzure.Storage.Blob.BlobType.PageBlob;
                    }

                    ((PowerShellAgent)CommandAgent).AddPipelineScript(string.Format("ls -File -Recurse -Path {0}", dir.FullName));
                    Test.Info("Upload files...");
                    Test.Assert(CommandAgent.SetAzureStorageBlobContent(string.Empty, containerName, blobType), "upload multiple files should be successsed");
                    Test.Info("Upload finished...");

                    blobLists = container.ListBlobs(string.Empty, true, BlobListingDetails.All).ToList();
                    List <string> dirFiles = files.FindAll(item => item.StartsWith(dir.Name));
                    Test.Assert(blobLists.Count == dirFiles.Count(), string.Format("set-azurestorageblobcontent should upload {0} files, and actually it's {1}", dirFiles.Count(), blobLists.Count));

                    CloudBlob blob = null;
                    for (int i = 0, count = dirFiles.Count(); i < count; i++)
                    {
                        blob = blobLists[i] as CloudBlob;

                        if (blob == null)
                        {
                            Test.AssertFail("blob can't be null");
                        }

                        string convertedName = blobUtil.ConvertBlobNameToFileName(blob.Name, dir.Name);
                        Test.Assert(dirFiles[i] == convertedName, string.Format("blob name should be {0}, and actually it's {1}", dirFiles[i], convertedName));
                        string localMd5 = Helper.GetFileContentMD5(Path.Combine(uploadDirRoot, dirFiles[i]));
                        Test.Assert(blob.BlobType == blobType, "Destination blob type should be the same with the one input in option.");

                        if (blobType == BlobType.BlockBlob)
                        {
                            Test.Assert(localMd5 == blob.Properties.ContentMD5, string.Format("blob content md5 should be {0}, and actually it's {1}", localMd5, blob.Properties.ContentMD5));
                        }
                    }
                }
                finally
                {
                    blobUtil.RemoveContainer(containerName);
                }
            }
        }
Esempio n. 3
0
        public void SetBlobContentWithMetadata(StorageBlob.BlobType blobType)
        {
            string             filePath  = FileUtil.GenerateOneTempTestFile();
            CloudBlobContainer container = blobUtil.CreateContainer();
            Hashtable          metadata  = new Hashtable();
            int metaCount = Utility.GetRandomTestCount();

            for (int i = 0; i < metaCount; i++)
            {
                string key   = Utility.GenRandomAlphabetString();
                string value = Utility.GenNameString(string.Empty);

                if (!metadata.ContainsKey(key))
                {
                    Test.Info(string.Format("Add meta key: {0} value : {1}", key, value));
                    metadata.Add(key, value);
                }
            }

            try
            {
                Test.Assert(CommandAgent.SetAzureStorageBlobContent(filePath, container.Name, blobType, string.Empty, true, -1, null, metadata), "set blob content with meta should succeed");
                CloudBlob blob = StorageExtensions.GetBlobReferenceFromServer(container, Path.GetFileName(filePath));
                blob.FetchAttributes();
                ExpectEqual(metadata.Count, blob.Metadata.Count, "meta data count");

                foreach (string key in metadata.Keys)
                {
                    if (blob.Metadata.ContainsKey(key))
                    {
                        ExpectEqual(metadata[key].ToString(), blob.Metadata[key], "Meta data key " + key);
                    }
                    else if (blob.Metadata.ContainsKey(key.ToLower()))
                    {
                        // NodeJS stores key in lower case
                        ExpectEqual(metadata[key].ToString().ToLower(), blob.Metadata[key.ToLower()], "Meta data key " + key);
                    }
                    else
                    {
                        Test.AssertFail("Could not find meta data key " + key + " in blob entity");
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(container.Name);
                FileUtil.RemoveFile(filePath);
            }
        }
Esempio n. 4
0
        internal void SetBlobContentByMultipleFiles(StorageBlob.BlobType blobType)
        {
            string             containerName = Utility.GenNameString("container");
            CloudBlobContainer container     = blobUtil.CreateContainer(containerName);

            try
            {
                List <IListBlobItem> blobLists = container.ListBlobs(string.Empty, true, BlobListingDetails.All).ToList();
                Test.Assert(blobLists.Count == 0, string.Format("container {0} should contain {1} blobs, and actually it contain {2} blobs", containerName, 0, blobLists.Count));

                DirectoryInfo rootDir = new DirectoryInfo(uploadDirRoot);

                FileInfo[] rootFiles = rootDir.GetFiles();

                Test.Info("Upload files...");
                Test.Assert(CommandAgent.UploadLocalFiles(uploadDirRoot, containerName, blobType), "upload multiple files should be successful");
                Test.Info("Upload finished...");
                blobLists = container.ListBlobs(string.Empty, true, BlobListingDetails.All).ToList();
                Test.Assert(blobLists.Count == rootFiles.Count(), string.Format("set-azurestorageblobcontent should upload {0} files, and actually it's {1}", rootFiles.Count(), blobLists.Count));

                CloudBlob blob = null;
                for (int i = 0, count = rootFiles.Count(); i < count; i++)
                {
                    blob = blobLists[i] as CloudBlob;

                    if (blob == null)
                    {
                        Test.AssertFail("blob can't be null");
                    }

                    Test.Assert(rootFiles[i].Name == blob.Name, string.Format("blob name should be {0}, and actually it's {1}", rootFiles[i].Name, blob.Name));
                    string localMd5 = FileUtil.GetFileContentMD5(Path.Combine(uploadDirRoot, rootFiles[i].Name));
                    Test.Assert(blob.BlobType == blobType, string.Format("blob type should be equal {0} = {1}", blob.BlobType, blobType));

                    if (blobType == BlobType.BlockBlob)
                    {
                        Test.Assert(localMd5 == blob.Properties.ContentMD5, string.Format("blob content md5 should be {0}, and actually it's {1}", localMd5, blob.Properties.ContentMD5));
                    }
                }
            }
            finally
            {
                blobUtil.RemoveContainer(containerName);
            }
        }
Esempio n. 5
0
        public void UploadBlobWithSpeicialChars(StorageBlob.BlobType blobType)
        {
            string             filePath  = FileUtil.GenerateOneTempTestFile();
            CloudBlobContainer container = blobUtil.CreateContainer();
            string             blobName  = SpecialChars;

            try
            {
                string localMD5 = FileUtil.GetFileContentMD5(filePath);
                Test.Assert(CommandAgent.SetAzureStorageBlobContent(filePath, container.Name, blobType, blobName, true), "upload a blob name with special chars should succeed");
                CloudBlob blob = CloudBlobUtil.GetBlob(container, blobName, blobType);
                blob.FetchAttributes();

                ExpectEqual(localMD5, blob.Properties.ContentMD5, "content md5");
            }
            finally
            {
                blobUtil.RemoveContainer(container.Name);
                FileUtil.RemoveFile(filePath);
            }
        }
Esempio n. 6
0
        public void UploadBlobWithZeroSize(StorageBlob.BlobType blobType)
        {
            string             filePath  = FileUtil.GenerateOneTempTestFile(0, 0);
            CloudBlobContainer container = blobUtil.CreateContainer();
            string             blobName  = Utility.GenNameString("blob");

            try
            {
                string localMD5 = FileUtil.GetFileContentMD5(filePath);
                Test.Assert(CommandAgent.SetAzureStorageBlobContent(filePath, container.Name, blobType, blobName, true), "upload blob with zero size should succeed");
                CloudBlob blob = CloudBlobUtil.GetBlob(container, blobName, blobType);
                blob.FetchAttributes();

                ExpectEqual(localMD5, blob.Properties.ContentMD5, "content md5");
            }
            finally
            {
                blobUtil.RemoveContainer(container.Name);
                FileUtil.RemoveFile(filePath);
            }
        }