예제 #1
0
        public void RenameHandler()
        {
            const string TEST_FOLDER_NAME     = "TestFolderToRename";
            const string TEST_FOLDER_NEW_NAME = "TestFolderRenamed";
            const string TEST_FOLDER_PATH     = ROOT_TEST_PATH + "\\" + TEST_FOLDER_NAME;
            const string TEST_FOLDER_NEW_PATH = ROOT_TEST_PATH + "\\" + TEST_FOLDER_NEW_NAME;

            Directory.CreateDirectory(TEST_FOLDER_PATH);

            Assert.True(Directory.Exists(TEST_FOLDER_PATH));

            if (Directory.Exists(TEST_FOLDER_NEW_PATH))
            {
                Directory.Delete(TEST_FOLDER_NEW_PATH);
            }

            var targetToRename = new RenameActionTarget
            {
                OldName = TEST_FOLDER_NAME,
                Name    = TEST_FOLDER_NEW_NAME
            };

            var param = new RenameParam
            {
                CurrentFolderPath = "/",
                Targets           = new List <RenameActionTarget> {
                    targetToRename
                }
            };

            var result = new RenameHandler(CreateHostingEnv()).Run(param) as RenameResult;

            PrintErrors(result.Errors);

            Assert.Equal(1, result.Affected);
            Assert.True(Directory.Exists(TEST_FOLDER_NEW_PATH));
            Assert.False(Directory.Exists(TEST_FOLDER_PATH));
            Assert.True(result.Errors.Count == 0);
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Generating format...");

            #region Params

            var p_copy = new CopyParam
            {
                CurrentFolderPath    = "/",
                SourceDirectory      = "/",
                DestinationDirectory = "/",
                Overwrite            = false,
                Targets = new System.Collections.Generic.List <BaseActionTarget>
                {
                    new BaseActionTarget
                    {
                        IsFile = true,
                        Name   = "sample.txt"
                    }
                }
            };

            var p_move = new MoveParam
            {
                CurrentFolderPath    = "/",
                SourceDirectory      = "/",
                DestinationDirectory = "/",
                Overwrite            = false,
                Targets = new System.Collections.Generic.List <BaseActionTarget>
                {
                    new BaseActionTarget
                    {
                        IsFile = true,
                        Name   = "sample.txt"
                    }
                }
            };

            var p_createFolder = new CreateFolderParam
            {
                CurrentFolderPath = "/",
                Name = "new folder name"
            };

            var p_delete = new DeleteParam
            {
                CurrentFolderPath = "/",
                Targets           = new System.Collections.Generic.List <string>
                {
                    "itemNameToDelete"
                }
            };

            var p_folderStruct = new FolderStructParam
            {
                CurrentFolderPath = "/",
                FileExtensions    = new string[] { ".txt" }
            };

            var p_rename = new RenameParam
            {
                CurrentFolderPath = "/",
                Targets           = new System.Collections.Generic.List <RenameActionTarget>
                {
                    new RenameActionTarget
                    {
                        IsFile  = true,
                        Name    = "new name",
                        OldName = "old name"
                    }
                }
            };

            #endregion

            #region Results

            var r_copy = new CopyResult
            {
                Errors = new System.Collections.Generic.List <string>
                {
                    "Error message."
                }
            };

            var r_move = new MoveResult
            {
                Errors = new System.Collections.Generic.List <string>
                {
                    "Error message."
                }
            };

            var r_createFolder = new CreateFolderResult
            {
                Errors = new System.Collections.Generic.List <string>
                {
                    "Error message."
                }
            };

            var r_delete = new DeleteResult
            {
                Affected = 0,
                Errors   = new System.Collections.Generic.List <string>
                {
                    "Error message."
                }
            };

            var r_folderStruct = new FolderStructResult
            {
                Errors = new System.Collections.Generic.List <string>
                {
                    "Error message."
                },
                Files = new System.Collections.Generic.List <FileInfoProxy>
                {
                    new FileInfoProxy
                    {
                        Name       = "file.name",
                        Properties = new System.Collections.Generic.Dictionary <string, string>
                        {
                            { "Property", "Value" }
                        }
                    }
                },
                Folders = new System.Collections.Generic.List <FileInfoProxy>
                {
                    new FileInfoProxy
                    {
                        Name       = "folder name",
                        Properties = new System.Collections.Generic.Dictionary <string, string>
                        {
                            { "Property", "Value" }
                        }
                    }
                }
            };

            var r_rename = new RenameResult
            {
                Affected = 0,
                Errors   = new System.Collections.Generic.List <string>
                {
                    "Error message."
                },
                RenamedObjects = new System.Collections.Generic.List <RenameActionTarget>()
                {
                    new RenameActionTarget
                    {
                        IsFile  = true,
                        Name    = "new name",
                        OldName = "old name"
                    }
                }
            };

            #endregion

            SaveFormat("p_copy.json", p_copy);
            SaveFormat("p_move.json", p_move);
            SaveFormat("p_createFolder.json", p_createFolder);
            SaveFormat("p_delete.json", p_delete);
            SaveFormat("p_folderStruct.json", p_folderStruct);
            SaveFormat("p_rename.json", p_rename);

            SaveFormat("r_copy.json", r_copy);
            SaveFormat("r_move.json", r_move);
            SaveFormat("r_createFolder.json", r_createFolder);
            SaveFormat("r_delete.json", r_delete);
            SaveFormat("r_folderStruct.json", r_folderStruct);
            SaveFormat("r_rename.json", r_rename);
        }