public void PipelineCreatingMultipleDirectoriesWhileSomeDirectoryExistsTest()
        {
            int numberOfDirectories = this.randomProvider.Next(2, 33);

            int[]    indexes = Enumerable.Range(0, numberOfDirectories).ToArray();
            string[] names   = indexes.Select(i => CloudFileUtil.GenerateUniqueDirectoryName()).ToArray();
            int      numberOfExistingDirectories = this.randomProvider.Next(1, numberOfDirectories);

            List <int> indexToBeRemoved = new List <int>(indexes);

            for (int i = 0; i < numberOfExistingDirectories; i++)
            {
                int id = this.randomProvider.Next(indexToBeRemoved.Count);
                fileUtil.EnsureDirectoryExists(this.fileShare, names[indexToBeRemoved[id]]);
                indexToBeRemoved.RemoveAt(id);
            }

            CommandAgent.NewDirectoryFromPipeline(this.fileShare.Name);
            var result = CommandAgent.Invoke(names);

            // A total number of "numberOfExistingDirectories" errors should throw while others should success.
            CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.ResourceAlreadyExistsFullQualifiedErrorId), numberOfExistingDirectories);

            // Assert all directories are created
            foreach (string name in names)
            {
                fileUtil.AssertDirectoryExists(this.fileShare, name, string.Format("Directory {0} should exist after created.", name));
            }
        }
        public void CreateDirectoryUnderRootsParent()
        {
            string dirName = CloudFileUtil.GenerateUniqueDirectoryName();

            this.CreateDirectoryInternal("../" + dirName, false);
            CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.InvalidResourceFullQualifiedErrorId, AssertUtil.AuthenticationFailedFullQualifiedErrorId));
        }
        public void CreateDirectoryWhichHasJustBeenDeleted()
        {
            string dirName   = CloudFileUtil.GenerateUniqueDirectoryName();
            var    directory = fileUtil.EnsureDirectoryExists(this.fileShare, dirName);

            directory.Delete();
            this.CreateDirectoryInternal(dirName);
        }
        public void CreateExistingDirectoryTest()
        {
            string dirName   = CloudFileUtil.GenerateUniqueDirectoryName();
            var    directory = fileUtil.EnsureDirectoryExists(this.fileShare, dirName);

            CommandAgent.NewDirectory(this.fileShare, dirName);
            var result = CommandAgent.Invoke();

            CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.ResourceAlreadyExistsFullQualifiedErrorId));
        }
示例#5
0
        public void CreateDirectoryAndListThroughSMBTest()
        {
            string directoryName = CloudFileUtil.GenerateUniqueDirectoryName();

            CommandAgent.NewDirectory(this.fileShare, directoryName);
            CommandAgent.Invoke();
            CommandAgent.AssertNoError();
            SMBValidationRetry(
                () => this.mountedShareRoot.GetDirectories().Select(x => x.Name).Contains(directoryName),
                "list the newly created directory through SMB protocol");
        }
        public void CreateDirectoryUnderExistingDirectory()
        {
            string dirName    = CloudFileUtil.GenerateUniqueDirectoryName();
            var    directory  = fileUtil.EnsureDirectoryExists(this.fileShare, dirName);
            string subDirName = CloudFileUtil.GenerateUniqueDirectoryName();
            string fullPath   = CloudFileUtil.GetFullPath(directory.GetDirectoryReference(subDirName));

            this.CreateDirectoryInternal(
                () => CommandAgent.NewDirectory(directory, subDirName),
                fullPath.TrimEnd('/'));
        }
        public void RemoveDirectoryUnderNonExistingShareTest()
        {
            string shareName = CloudFileUtil.GenerateUniqueFileShareName();
            string dir       = CloudFileUtil.GenerateUniqueDirectoryName();

            fileUtil.DeleteFileShareIfExists(shareName);
            CommandAgent.RemoveDirectory(shareName, dir);
            var result = CommandAgent.Invoke();

            CommandAgent.AssertErrors(record => record.AssertError(AssertUtil.ShareNotFoundFullQualifiedErrorId));
        }
        public void RemoveNonExistingDirectoryTest()
        {
            string dir = CloudFileUtil.GenerateUniqueDirectoryName();

            fileUtil.DeleteDirectoryIfExists(this.fileShare, dir);

            CommandAgent.RemoveDirectory(this.fileShare, dir);
            var result = CommandAgent.Invoke();

            CommandAgent.AssertErrors(record => record.AssertError(AssertUtil.ResourceNotFoundFullQualifiedErrorId));
        }
示例#9
0
        public void CreateDirectoryWithNoPath_Directory()
        {
            var dir = fileUtil.EnsureDirectoryExists(this.fileShare, CloudFileUtil.GenerateUniqueDirectoryName());

            CommandAgent.SetVariable("dir", dir);
            ((PowerShellAgent)CommandAgent).PowerShellSession.AddScript("New-AzureStorageDirectory -Directory $dir");
            var result = CommandAgent.Invoke();

            result.AssertNoResult();
            CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.MissingMandatoryParameterFullQualifiedErrorId));
        }
示例#10
0
        public void CreateDirectoryAndListThroughPSHTest()
        {
            string directoryName = CloudFileUtil.GenerateUniqueDirectoryName();

            this.mountedShareRoot.CreateSubdirectory(directoryName);
            CommandAgent.GetFile(this.fileShare);
            var result = CommandAgent.Invoke();

            CommandAgent.AssertNoError();
            result.AssertObjectCollection(obj => obj.AssertCloudFileDirectory(directoryName));
        }
        public void RemoveNonEmptyDirectoryTest()
        {
            string dir       = CloudFileUtil.GenerateUniqueDirectoryName();
            var    directory = fileUtil.EnsureDirectoryExists(this.fileShare, dir);

            fileUtil.CreateFile(directory, CloudFileUtil.GenerateUniqueFileName());

            CommandAgent.RemoveDirectory(this.fileShare, dir);
            var result = CommandAgent.Invoke();

            CommandAgent.AssertErrors(record => record.AssertError(AssertUtil.DirectoryNotEmptyFullQualifiedErrorId));
        }
        public void CreateDirectoryWithPathStartsWithSlash()
        {
            string dir1 = CloudFileUtil.GenerateUniqueDirectoryName();

            this.CreateDirectoryInternal("/" + dir1);
            CommandAgent.Clear();

            string dir2 = CloudFileUtil.GenerateUniqueDirectoryName();

            this.CreateDirectoryInternal("\\" + dir2);
            CommandAgent.Clear();
        }
示例#13
0
        public void UploadToADeletedFolder()
        {
            string localFilePath = Path.Combine(Test.Data.Get("TempDir"), CloudFileUtil.GenerateUniqueFileName());

            FileUtil.GenerateSmallFile(localFilePath, Utility.GetRandomTestCount(5, 10), true);
            var dir = fileUtil.EnsureDirectoryExists(this.fileShare, CloudFileUtil.GenerateUniqueDirectoryName());

            dir.Delete();
            CommandAgent.UploadFile(this.fileShare, localFilePath, CloudFileUtil.GetFullPath(dir) + "/");
            CommandAgent.Invoke();
            CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.ParentNotFoundFullQualifiedErrorId));
        }
        public void CreateDirectoryUnderNonExistingFileShareTest()
        {
            string nonExistingFileShareName = CloudFileUtil.GenerateUniqueFileShareName();

            fileUtil.DeleteFileShareIfExists(nonExistingFileShareName);
            string dirName = CloudFileUtil.GenerateUniqueDirectoryName();

            CommandAgent.NewDirectory(nonExistingFileShareName, dirName);
            var result = CommandAgent.Invoke();

            CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.ShareNotFoundFullQualifiedErrorId));
        }
        public void CreateDirectoryUnderNonExistingShare()
        {
            string shareName = CloudFileUtil.GenerateUniqueFileShareName();
            string dirName   = CloudFileUtil.GenerateUniqueDirectoryName();

            fileUtil.DeleteFileShareIfExists(shareName);
            this.CreateDirectoryInternal(
                () => CommandAgent.NewDirectory(shareName, dirName),
                dirName,
                false);
            CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.ShareNotFoundFullQualifiedErrorId));
        }
示例#16
0
        public void DownloadingFromNonExistingDirectory()
        {
            string cloudDirectoryName = CloudFileUtil.GenerateUniqueDirectoryName();

            fileUtil.DeleteDirectoryIfExists(this.fileShare, cloudDirectoryName);
            string cloudFileName = CloudFileUtil.GenerateUniqueFileName();
            var    file          = this.fileShare.GetRootDirectoryReference().GetDirectoryReference(cloudDirectoryName).GetFileReference(cloudFileName);

            CommandAgent.DownloadFile(file, Test.Data.Get("TempDir"), true);
            var result = CommandAgent.Invoke();

            CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.InvalidOperationExceptionFullQualifiedErrorId, AssertUtil.PathNotFoundFullQualifiedErrorId, AssertUtil.ResourceNotFoundFullQualifiedErrorId));
        }
        public void RemoveNonExistingFileInANonExistingDirectory()
        {
            string directoryName = CloudFileUtil.GenerateUniqueDirectoryName();

            fileUtil.DeleteDirectoryIfExists(this.fileShare, directoryName);
            string fileName = CloudFileUtil.GenerateUniqueFileName();
            var    file     = this.fileShare.GetRootDirectoryReference().GetDirectoryReference(directoryName).GetFileReference(fileName);

            CommandAgent.RemoveFile(this.fileShare, file.Name);
            var result = CommandAgent.Invoke();

            CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.ParentNotFoundFullQualifiedErrorId, AssertUtil.ResourceNotFoundFullQualifiedErrorId));
        }
示例#18
0
        public void UploadToCloudDirectory()
        {
            string cloudFileName      = CloudFileUtil.GenerateUniqueFileName();
            string cloudDirectoryName = CloudFileUtil.GenerateUniqueDirectoryName();
            var    directory          = fileUtil.EnsureDirectoryExists(this.fileShare, cloudDirectoryName);
            string localFilePath      = Path.Combine(Test.Data.Get("TempDir"), CloudFileUtil.GenerateUniqueFileName());

            FileUtil.GenerateSmallFile(localFilePath, Utility.GetRandomTestCount(5, 10), true);
            CommandAgent.UploadFile(directory, localFilePath, cloudFileName, true);
            var result = CommandAgent.Invoke();

            CommandAgent.AssertNoError();
            result.AssertNoResult();
        }
        public void RemoveFileUnderADirectory()
        {
            string cloudFileName      = CloudFileUtil.GenerateUniqueFileName();
            string cloudDirectoryName = CloudFileUtil.GenerateUniqueDirectoryName();
            var    directory          = fileUtil.EnsureDirectoryExists(this.fileShare, cloudDirectoryName);
            var    file = fileUtil.CreateFile(directory, cloudFileName);

            CommandAgent.RemoveFile(file);
            var result = CommandAgent.Invoke();

            CommandAgent.AssertNoError();
            result.AssertNoResult();
            fileUtil.AssertFileNotExists(this.fileShare, file.Name, "File should not exist after deleting.");
        }
        public void PipelineMultipleDirectoryNamesTest()
        {
            // TODO: Generate more random names for file shares after the
            // naming rules is settled down.
            int numberOfDirectories = this.randomProvider.Next(2, 33);

            string[] names = Enumerable.Range(0, numberOfDirectories)
                             .Select(i => CloudFileUtil.GenerateUniqueDirectoryName()).ToArray();

            CommandAgent.NewDirectoryFromPipeline(this.fileShare.Name);
            var result = CommandAgent.Invoke(names);

            CommandAgent.AssertNoError();
            result.AssertObjectCollection(obj => obj.AssertCloudFileDirectory(new List <string>(names)), numberOfDirectories);
        }
示例#21
0
        public void DownloadFileInASubDirectory()
        {
            string cloudFileName = CloudFileUtil.GenerateUniqueFileName();
            string directoryName = CloudFileUtil.GenerateUniqueDirectoryName();
            string localFilePath = Path.Combine(Test.Data.Get("TempDir"), CloudFileUtil.GenerateUniqueFileName());

            FileUtil.GenerateSmallFile(localFilePath, Utility.GetRandomTestCount(5, 10), true);
            var subDirectory = fileUtil.EnsureDirectoryExists(this.fileShare, directoryName);
            var sourceFile   = fileUtil.CreateFile(subDirectory, cloudFileName, localFilePath);

            UploadAndDownloadFileInternal(
                sourceFile,
                FileUtil.GetFileContentMD5(localFilePath),
                destination => CommandAgent.DownloadFile(sourceFile, destination, true));
        }
示例#22
0
        public void GetFilesFromDirectoryTest()
        {
            var fileNames     = Enumerable.Range(0, this.randomProvider.Next(5, 20)).Select(x => CloudFileUtil.GenerateUniqueFileName()).ToList();
            var directoryName = CloudFileUtil.GenerateUniqueDirectoryName();
            var dir           = fileUtil.EnsureDirectoryExists(this.fileShare, directoryName);

            fileUtil.CleanupDirectory(dir);
            var files = fileNames.Select(name => fileUtil.CreateFile(dir, name)).ToList();

            CommandAgent.GetFile(dir);
            var result = CommandAgent.Invoke();

            CommandAgent.AssertNoError();
            result.AssertFileListItems(files, Enumerable.Empty <CloudFileDirectory>());
        }
        public void RemoveDirectoryWithInvalidKeyValueTest()
        {
            string dir = CloudFileUtil.GenerateUniqueDirectoryName();

            fileUtil.EnsureDirectoryExists(this.fileShare, dir);

            // Creates an storage context object with invalid key value
            var    invalidAccount = CloudFileUtil.MockupStorageAccount(StorageAccount, mockupAccountKey: true);
            object invalidStorageContextObject = CommandAgent.CreateStorageContextObject(invalidAccount.ToString(true));

            CommandAgent.RemoveDirectory(this.fileShare.Name, dir, invalidStorageContextObject);
            var result = CommandAgent.Invoke();

            CommandAgent.AssertErrors(record => record.AssertError(AssertUtil.AuthenticationFailedFullQualifiedErrorId, AssertUtil.ProtocolErrorFullQualifiedErrorId));
            fileUtil.AssertDirectoryExists(this.fileShare, dir, "Directory should not be created when providing invalid credentials.");
        }
        public void CreateDirectoryPipeline()
        {
            string dir1            = CloudFileUtil.GenerateUniqueDirectoryName();
            string dir2            = CloudFileUtil.GenerateUniqueDirectoryName();
            string fullPathForDir2 = string.Concat(dir1, "/", dir2);

            CommandAgent.NewDirectory(this.fileShare, dir1);
            ((PowerShellAgent)CommandAgent).PowerShellSession.AddCommand("New-AzureStorageDirectory");
            ((PowerShellAgent)CommandAgent).PowerShellSession.AddParameter("Path", dir2);
            var result = CommandAgent.Invoke();

            CommandAgent.AssertNoError();
            result.AssertObjectCollection(obj => obj.AssertCloudFileDirectory(fullPathForDir2));
            fileUtil.AssertDirectoryExists(this.fileShare, dir1, "Base directory should be created.");
            fileUtil.AssertDirectoryExists(this.fileShare, fullPathForDir2, "Sub directory should be created.");
        }
示例#25
0
        public void UploadingToNonExistingDirectory()
        {
            string localFilePath = Path.Combine(Test.Data.Get("TempDir"), CloudFileUtil.GenerateUniqueFileName());

            FileUtil.GenerateSmallFile(localFilePath, Utility.GetRandomTestCount(5, 10), true);

            string cloudDirectoryName = CloudFileUtil.GenerateUniqueDirectoryName();

            fileUtil.DeleteDirectoryIfExists(this.fileShare, cloudDirectoryName);
            string cloudFileName = CloudFileUtil.GenerateUniqueFileName();
            var    file          = this.fileShare.GetRootDirectoryReference().GetDirectoryReference(cloudDirectoryName).GetFileReference(cloudFileName);

            CommandAgent.UploadFile(this.fileShare, localFilePath, CloudFileUtil.GetFullPath(file));
            CommandAgent.Invoke();
            CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.ParentNotFoundFullQualifiedErrorId));
        }
        public void CreateDirectoryWithRelativePath()
        {
            var baseDir = fileUtil.EnsureDirectoryExists(this.fileShare, CloudFileUtil.GenerateUniqueDirectoryName());

            string dir1 = CloudFileUtil.GenerateUniqueDirectoryName();

            this.CreateDirectoryInternal(
                () => CommandAgent.NewDirectory(baseDir, "../" + dir1),
                dir1);
            CommandAgent.Clear();

            string dir2 = CloudFileUtil.GenerateUniqueDirectoryName();

            this.CreateDirectoryInternal(
                () => CommandAgent.NewDirectory(baseDir, "./c/../../" + dir2),
                dir2);
            CommandAgent.Clear();
        }
        public void NewDirectoryWithInvalidAccountTest()
        {
            string dir       = CloudFileUtil.GenerateUniqueDirectoryName();
            var    directory = this.fileShare.GetRootDirectoryReference().GetDirectoryReference(dir);

            directory.DeleteIfExists();

            // Creates an storage context object with invalid account
            // name.
            var    invalidAccount = CloudFileUtil.MockupStorageAccount(StorageAccount, mockupAccountName: true);
            object invalidStorageContextObject = CommandAgent.CreateStorageContextObject(invalidAccount.ToString(true));

            CommandAgent.NewDirectory(this.fileShare.Name, dir, invalidStorageContextObject);
            var result = CommandAgent.Invoke();

            CommandAgent.AssertErrors(record => record.AssertError(AssertUtil.AccountIsDisabledFullQualifiedErrorId, AssertUtil.NameResolutionFailureFullQualifiedErrorId, AssertUtil.ResourceNotFoundFullQualifiedErrorId, AssertUtil.ProtocolErrorFullQualifiedErrorId, AssertUtil.InvalidResourceFullQualifiedErrorId));
            fileUtil.AssertDirectoryNotExists(this.fileShare, dir, "Directory should not be created when providing invalid credentials.");
        }
示例#28
0
        public void DownloadFileFromShareSnapshot_dir()
        {
            string shareName = CloudFileUtil.GenerateUniqueFileShareName();
            string dirName   = CloudFileUtil.GenerateUniqueDirectoryName();
            string fileName  = CloudFileUtil.GenerateUniqueFileName();

            try
            {
                CloudFileShare     share          = fileUtil.EnsureFileShareExists(shareName);
                CloudFileShare     shareSnapshot1 = share.Snapshot();
                CloudFileDirectory dir            = fileUtil.EnsureDirectoryExists(share, dirName);
                CloudFile          file           = fileUtil.CreateFile(dir, fileName);
                CloudFileShare     shareSnapshot2 = share.Snapshot();
                file.Delete();
                dir.Delete();

                //Get File content
                string StorageConnectionString = Test.Data.Get("StorageConnectionString");
                Test.Assert((CommandAgent as PowerShellAgent).InvokePSScript(string.Format(",(New-AzureStorageContext -ConnectionString \"{5}\" | Get-AzureStorageShare -Name {0} -SnapshotTime \"{1}\").GetRootDirectoryReference().GetDirectoryReference(\"{4}\") | Get-AzureStorageFileContent -Path {2} -Destination {3} -Force",
                                                                                           shareName,
                                                                                           shareSnapshot2.SnapshotTime.Value,
                                                                                           fileName,
                                                                                           fileName,
                                                                                           dirName,
                                                                                           StorageConnectionString)),
                            string.Format("Download File {0} from share snapshot {1}, {2} should success.", dirName + "\\" + fileName, shareName, shareSnapshot2.SnapshotTime.Value));

                //validate MD5
                CloudFile file2 = shareSnapshot2.GetRootDirectoryReference().GetDirectoryReference(dirName).GetFileReference(fileName);
                file2.FetchAttributes();
                Test.Assert(file2.Properties.ContentMD5 == FileUtil.GetFileContentMD5(fileName), "Expected MD5: {0}, real MD5: {1}", file2.Properties.ContentMD5, FileUtil.GetFileContentMD5(fileName));
            }
            finally
            {
                try
                {
                    fileUtil.DeleteFileShareIfExists(shareName);
                }
                catch (Exception e)
                {
                    Test.Warn("Unexpected exception when cleanup file share {0}: {1}", shareName, e);
                }
            }
        }
        public void CreateDirectoryWithRelativePathContainsDoubleSlash()
        {
            var baseDir = fileUtil.EnsureDirectoryExists(this.fileShare, CloudFileUtil.GenerateUniqueDirectoryName());

            string dir1 = CloudFileUtil.GenerateUniqueDirectoryName();

            this.CreateDirectoryInternal(
                () => CommandAgent.NewDirectory(baseDir, "..//" + dir1),
                dir1);
            CommandAgent.Clear();

            baseDir.GetDirectoryReference("a").CreateIfNotExists();
            string dir2 = CloudFileUtil.GenerateUniqueDirectoryName();

            this.CreateDirectoryInternal(
                () => CommandAgent.NewDirectory(baseDir, @"//a\\" + dir2),
                string.Format("{0}/a/{1}", baseDir.Name, dir2));
            CommandAgent.Clear();
        }
        public void PipelineMultipleDirectoriesToRemoveTest()
        {
            int numberOfDirectories = this.randomProvider.Next(2, 33);

            string[] names = Enumerable.Range(0, numberOfDirectories)
                             .Select(i => CloudFileUtil.GenerateUniqueDirectoryName()).ToArray();
            foreach (var name in names)
            {
                fileUtil.EnsureDirectoryExists(this.fileShare, name);
            }

            CommandAgent.RemoveDirectoriesFromPipeline(this.fileShare.Name);
            var result = CommandAgent.Invoke(names);

            CommandAgent.AssertNoError();
            result.AssertNoResult();

            foreach (var name in names)
            {
                fileUtil.AssertDirectoryNotExists(this.fileShare, name, string.Format(CultureInfo.InvariantCulture, "Directory {0} should be removed.", name));
            }
        }