/// <summary> /// Rename the folder and it items related fields on file system and cache (recursive) /// </summary> /// <param name="newFolderName"></param> public override void RenameFolder(string newFolderName) { //update the folder name in file system string newFullPath = Path.Combine(Path.GetDirectoryName(PathHelper.GetLongPath(FolderFullPath)), newFolderName); if (FolderName.ToUpper() == newFolderName.ToUpper())//user just changed the name letters case { //move to temp folder string tempTargetPath = Path.Combine(Path.GetTempPath(), FolderName); Directory.Move(PathHelper.GetLongPath(FolderFullPath), PathHelper.GetLongPath(tempTargetPath)); Directory.Move(PathHelper.GetLongPath(tempTargetPath), PathHelper.GetLongPath(newFullPath)); } else { Directory.Move(PathHelper.GetLongPath(FolderFullPath), PathHelper.GetLongPath(newFullPath)); } //Enable file watcher to catch the change first, so it will be visible in UI Thread.Sleep(100); //update folder fields FolderRelativePath = Path.Combine(FolderRelativePath.Substring(0, FolderRelativePath.LastIndexOf(FolderName)), newFolderName); //parentFolderRelativePath + "/" + FolderName; OnPropertyChanged(nameof(FolderRelativePath)); OnPropertyChanged(nameof(FolderFullPath)); OnPropertyChanged(nameof(DisplayName)); OnPropertyChanged(nameof(FolderName)); mFileWatcher.Path = FolderFullPath; //updating the folder items cache with correct File Path UpdateFolderItemsCacheFilePath(); //update the sub folders and their items in cache if (mSubFoldersCache != null) { foreach (RepositoryFolder <T> sf in mSubFoldersCache) { sf.UpdateSubFolderFieldsAndItemsPath(FolderRelativePath); } } }
public void FolderRelativePath_Happy() { FolderRelativePath folder = "new/happy/movie"; }
public void FolderRelativePath_Unhappy(string folder, string expectedMessage) { if (expectedMessage == null) { var ex = Assert.Throws <ArgumentNullException>(() => { FolderRelativePath target = folder; }); ex.Message.Should().Be("Value cannot be null. (Parameter 'value')"); } else { var ex = Assert.Throws <ArgumentException>(() => { FolderRelativePath target = folder; }); ex.Message.Should().Be(expectedMessage); } }