示例#1
0
        public void WhenExecuteCommandWithValidPaths_CommandManager_ShouldRename()
        {
            var newPath           = "myNewPath";
            var oldPath           = "myOldPath";
            var storedDataService = new StoredDataServiceMock(false);

            var fileServiceMock   = new FileServiceMock();
            var commandDefinition = new RenameFolderCommand(fileServiceMock);
            var instance          = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(commandDefinition);

            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandPathOldFolderParameter.GetInvokeName(),
                oldPath,
                commandDefinition.CommandPathNewFolderParameter.GetInvokeName(),
                newPath);

            instance.ExecuteInputRequest(inputRequest);

            var expectedOldPath  = oldPath;
            var expectedONewPath = newPath;
            var actualOldPath    = fileServiceMock.RenamedOldFolder;
            var actualNewPath    = fileServiceMock.RenamedNewFolder;

            Assert.Equal(expectedOldPath, actualOldPath);
            Assert.Equal(expectedONewPath, actualNewPath);
        }
示例#2
0
        private void resetFolderName()
        {
            _engine       = new AutomationEngineInstance(null);
            _renameFolder = new RenameFolderCommand();

            string projectDirectory = Directory.GetParent(Environment.CurrentDirectory).Parent.FullName;
            string inputPath        = Path.Combine(projectDirectory, @"Resources\newName");

            VariableMethods.CreateTestVariable(inputPath, _engine, "inputPath", typeof(string));

            VariableMethods.CreateTestVariable("toRename", _engine, "newName", typeof(string));

            _renameFolder.v_SourceFolderPath = "{inputPath}";
            _renameFolder.v_NewName          = "{newName}";

            _renameFolder.RunCommand(_engine);
        }
示例#3
0
        public void HandlesInvalidSourceFolderInput()
        {
            _engine       = new AutomationEngineInstance(null);
            _renameFolder = new RenameFolderCommand();

            string projectDirectory = Directory.GetParent(Environment.CurrentDirectory).Parent.FullName;
            string inputPath        = Path.Combine(projectDirectory, @"Resources\doesNotExist");

            VariableMethods.CreateTestVariable(inputPath, _engine, "inputPath", typeof(string));

            VariableMethods.CreateTestVariable("newName", _engine, "newName", typeof(string));

            _renameFolder.v_SourceFolderPath = "{inputPath}";
            _renameFolder.v_NewName          = "{newName}";

            Assert.Throws <DirectoryNotFoundException>(() => _renameFolder.RunCommand(_engine));
        }
        public void RenameFolder(string parentSubPath, string folderName, string newFolderName)
        {
            // Darf noch nicht existieren
            var folderPath = Path.Combine(Path.GetDirectoryName(_projectFilePath), parentSubPath, newFolderName);

            if (Directory.Exists(folderPath))
            {
                throw new ArgumentException($"A folder named '{newFolderName}' already exists in this directory!");
            }

            _cmdProcessor.Execute(RenameFolderCommand.Create(_outputService, _projectFilePath, parentSubPath, folderName, newFolderName));

            ProjectItemChanged?.Invoke(new ProjectItemChangedArgs
            {
                ItemType      = ProjectItemType.Folder,
                Change        = ProjectItemChange.Rename,
                ItemName      = newFolderName,
                ItemNameOld   = folderName,
                ParentSubPath = parentSubPath
            });
        }
示例#5
0
        public void WhenExecuteCommandWithoutOldPathParameter_CommandManager_ShouldThrowException()
        {
            var newPath           = "myNewPath";
            var storedDataService = new StoredDataServiceMock(false);

            var fileServiceMock   = new FileServiceMock();
            var commandDefinition = new RenameFolderCommand(fileServiceMock);
            var instance          = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(commandDefinition);

            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandPathNewFolderParameter.GetInvokeName(),
                newPath);

            Assert.Throws <InvalidParamsException>(() =>
            {
                instance.ExecuteInputRequest(inputRequest);
            });
        }
示例#6
0
        private void treeView_AfterLabelEdit(object sender, VirtualNodeLabelEditEventArgs e)
        {
            VirtualTreeNode node = e.Node;

            treeView.LabelEdit = false;
            Folder      folder      = e.Node.Tag as Folder;
            GroupingTag groupingTag = e.Node.Tag as GroupingTag;
            Command     command     = null;
            object      newTag      = null;

            EventHandler <RenameCompletedEventArgs> completed = delegate(object s, RenameCompletedEventArgs ee)
            {
                Program.Invoke(this, delegate
                {
                    ResumeRefreshTreeView();

                    if (ee.Success)
                    {
                        // the new tag is updated on the node here. This ensures that the node stays selected
                        // when the treeview is refreshed. If you don't set the tag like this, the treeview refresh code notices
                        // that the tags are different and selects the parent node instead of this node.

                        // if the command fails for some reason, the refresh code will correctly revert the tag back to the original.
                        node.Tag = newTag;
                        RefreshTreeView();

                        // since the selected node doesn't actually change, then a selectionsChanged message doesn't get fired
                        // and the selection doesn't get updated to be the new tag/folder. Do it manually here instead.
                        treeView_SelectionsChanged(treeView, EventArgs.Empty);
                    }
                });
            };

            if (!string.IsNullOrEmpty(e.Label))
            {
                if (folder != null)
                {
                    RenameFolderCommand cmd = new RenameFolderCommand(Program.MainWindow, folder, e.Label);
                    command        = cmd;
                    cmd.Completed += completed;
                    newTag         = new Folder(null, e.Label);
                }
                else if (groupingTag != null)
                {
                    RenameTagCommand cmd = new RenameTagCommand(Program.MainWindow, groupingTag.Group.ToString(), e.Label);
                    command        = cmd;
                    cmd.Completed += completed;
                    newTag         = new GroupingTag(groupingTag.Grouping, groupingTag.Parent, e.Label);
                }
            }

            if (command != null && command.CanExecute())
            {
                command.Execute();
            }
            else
            {
                ResumeRefreshTreeView();
                e.CancelEdit = true;
            }
        }