public void FolderStructHandler(bool useExtensionsFilter) { const string ROOT_ACTION_FOLDER_NAME = "TestFolderToStructObserve"; const string ROOT_ACTION_FOLDER_PATH = ROOT_TEST_PATH + "\\" + ROOT_ACTION_FOLDER_NAME; const string TEST_FOLDER_NAME = "TestSampleFolder"; const string TEST_FILE_TXT_NAME = "TestFile.txt"; const string TEST_FILE_JPG_NAME = "TestFile.jpg"; const string TEST_FOLDER_PATH = ROOT_ACTION_FOLDER_PATH + "\\" + TEST_FOLDER_NAME; const string TEST_FILE_TXT_PATH = ROOT_ACTION_FOLDER_PATH + "\\" + TEST_FILE_TXT_NAME; const string TEST_FILE_JPG_PATH = ROOT_ACTION_FOLDER_PATH + "\\" + TEST_FILE_JPG_NAME; Directory.CreateDirectory(TEST_FOLDER_PATH); FileIO.WriteData(TEST_FILE_TXT_PATH, "0"); FileIO.WriteData(TEST_FILE_JPG_PATH, "0"); var param = new FolderStructParam { CurrentFolderPath = ROOT_ACTION_FOLDER_NAME }; if (useExtensionsFilter) { param.FileExtensions = new string[] { ".jpg" }; } var result = new FolderStructHandler(CreateHostingEnv()).Run(param) as FolderStructResult; PrintErrors(result.Errors); Log.WriteLine("Folders:"); foreach (var f in result.Folders) { Log.WriteLine($"{f.Name}"); } Log.WriteLine(""); Log.WriteLine("Files:"); foreach (var f in result.Files) { Log.WriteLine($"{f.Name}"); } if (useExtensionsFilter) { Assert.Equal(1, result.FolderCount); Assert.Equal(1, result.FileCount); } else { Assert.Equal(1, result.FolderCount); Assert.Equal(2, result.FileCount); } Assert.True(result.Errors.Count == 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); }