public void CreateCasePreservingExistingDirectoryTest()
        {
            int    length    = this.randomProvider.Next(5, 50);
            string dirName   = FileNamingGenerator.GenerateNameFromRange(length, new Tuple <int, int>((int)'a', (int)'z'));
            var    directory = fileUtil.EnsureDirectoryExists(this.fileShare, dirName);

            // Randomly up case some letters
            StringBuilder sb = new StringBuilder(dirName);

            for (int i = 0; i < sb.Length; i++)
            {
                // 1/3 chance to up case the letters
                if (this.randomProvider.Next(3) == 0)
                {
                    sb[i] = Char.ToUpperInvariant(sb[i]);
                }
            }

            string newDirName = sb.ToString();

            Test.Info("Original dir name: {0}. New dir name: {1}.", dirName, newDirName);
            CommandAgent.NewDirectory(this.fileShare, newDirName);
            var result = CommandAgent.Invoke();

            CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.ResourceAlreadyExistsFullQualifiedErrorId));
        }
        public void CreateDirectoryWithRelativePathWhereIntermediatePathMightNotExist()
        {
            var dir = fileUtil.EnsureFolderStructure(this.fileShare, "a/b/c");

            this.CreateDirectoryInternal(
                () => CommandAgent.NewDirectory(dir, "d/../e/./../../f"),
                "a/b/f");
        }
        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));
        }
        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('/'));
        }
Пример #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 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));
        }
        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.");
        }
        public void CreateChainsOfDirectoriesWithDepthTo251()
        {
            StringBuilder expectedPathBuilder = new StringBuilder("a");

            CommandAgent.NewDirectory(this.fileShare, "a");
            for (int i = 1; i < 251; i++)
            {
                ((PowerShellAgent)CommandAgent).PowerShellSession.AddCommand("New-AzureStorageDirectory");
                ((PowerShellAgent)CommandAgent).PowerShellSession.AddParameter("Path", "a");
                expectedPathBuilder.Append("/a");
            }

            var result = CommandAgent.Invoke();

            result.AssertNoResult();
            CommandAgent.AssertErrors(err => err.AssertError(AssertUtil.InvalidFileOrDirectoryPathNameFullQualifiedErrorId));
        }
        public void NewDirectoryWithInvalidKeyValueTest()
        {
            string dir       = CloudFileUtil.GenerateUniqueDirectoryName();
            var    directory = this.fileShare.GetRootDirectoryReference().GetDirectoryReference(dir);

            directory.DeleteIfExists();

            // Creates an storage context object with invalid key value
            var    invalidAccount = CloudFileUtil.MockupStorageAccount(StorageAccount, mockupAccountKey: 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.AuthenticationFailedFullQualifiedErrorId, AssertUtil.ProtocolErrorFullQualifiedErrorId));
            fileUtil.AssertDirectoryNotExists(this.fileShare, dir, "Directory should not be created when providing invalid credentials.");
        }
        public void CreateChainsOfDirectories()
        {
            StringBuilder expectedPathBuilder = new StringBuilder("a");

            CommandAgent.NewDirectory(this.fileShare, "a");
            for (int i = 1; i < 250; i++)
            {
                ((PowerShellAgent)CommandAgent).PowerShellSession.AddCommand("New-AzureStorageDirectory");
                ((PowerShellAgent)CommandAgent).PowerShellSession.AddParameter("Path", "a");
                expectedPathBuilder.Append("/a");
            }

            var result = CommandAgent.Invoke();

            CommandAgent.AssertNoError();
            result.AssertObjectCollection(obj => obj.AssertCloudFileDirectory(expectedPathBuilder.ToString()));
        }
        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 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 CreateChainsOfDirectoriesWithPathLengthTo1024()
        {
            // Create a 250 level depth chains of folder with each directory
            // named "123". And the first one is named "1234567890123456789012345678"
            // which is 28 characters long. So the total length would be
            // 249*(1+3)+28=1024.
            StringBuilder expectedPathBuilder = new StringBuilder("1234567890123456789012345678");

            CommandAgent.NewDirectory(this.fileShare, "1234567890123456789012345678");
            for (int i = 1; i < 250; i++)
            {
                ((PowerShellAgent)CommandAgent).PowerShellSession.AddCommand("New-AzureStorageDirectory");
                ((PowerShellAgent)CommandAgent).PowerShellSession.AddParameter("Path", "123");
                expectedPathBuilder.Append("/123");
            }

            string expectedPath = expectedPathBuilder.ToString();

            Test.Assert(expectedPath.Length == 1024, "Generated path should be 1024 while it is {0}.", expectedPath.Length);
            var result = CommandAgent.Invoke();

            CommandAgent.AssertNoError();
            result.AssertObjectCollection(obj => obj.AssertCloudFileDirectory(expectedPath));
        }
 private void CreateDirectoryInternal(string dirName, bool assertForSuccess = true, bool traceCommand = true)
 {
     this.CreateDirectoryInternal(() => CommandAgent.NewDirectory(this.fileShare, dirName), dirName, assertForSuccess, traceCommand);
 }