private void removeClassification(ITreeNode <IClassification> classificationNodeToRemove, bool recursive) { if (classificationNodeToRemove == null) { return; } if (recursive) { classificationNodeToRemove.NodesWithTags <IClassification>().Each(c => removeClassification(c, recursive: true)); } var project = _projectRetriever.CurrentProject; var classificationToBeRemoved = classificationNodeToRemove.Tag; _explorerPresenter.RemoveNode(classificationNodeToRemove); project.RemoveClassification(classificationToBeRemoved); // Promote all children nodes classificationNodeToRemove.NodesWithTags <IClassifiable>().Each(childNode => promoteNode(childNode, classificationNodeToRemove)); var parentNode = classificationNodeToRemove.ParentNode; if (parentNode != null) { parentNode.RemoveChild(classificationNodeToRemove); } classificationNodeToRemove.Delete(); }
protected override void Context() { _rootNodeTypeMapper = A.Fake <IClassificationTypeToRootNodeTypeMapper>(); _projectRetriever = A.Fake <IProjectRetriever>(); _applicationController = A.Fake <IApplicationController>(); _project = new PKSimProject(); _classificationNodesCache = new Cache <IClassification, ITreeNode <IClassification> >(x => x.Tag, x => null); A.CallTo(() => _projectRetriever.CurrentProject).Returns(_project); sut = new ClassificationPresenter(_rootNodeTypeMapper, _applicationController, _projectRetriever); _explorerPresenter = A.Fake <IExplorerPresenter>(); sut.InitializeWith(_explorerPresenter); _simulationFolderNode = createRootNode(RootNodeTypes.SimulationFolder, ClassificationType.Simulation); _observedDataFolderNode = createRootNode(RootNodeTypes.ObservedDataFolder, ClassificationType.ObservedData); A.CallTo(() => _explorerPresenter.AddNode(A <ITreeNode> ._)) .Invokes(x => { var classificationNode = x.GetArgument <ITreeNode>(0) as ITreeNode <IClassification>; if (classificationNode != null) { addToCache(classificationNode); } }); A.CallTo(() => _explorerPresenter.RemoveNode(A <ITreeNode> ._)) .Invokes(x => { var classificationNode = x.GetArgument <ITreeNode>(0) as ITreeNode <IClassification>; if (classificationNode != null) { removeFromCache(classificationNode); } }); }