private void promoteNode(ITreeNode <IClassifiable> nodeToPromote, ITreeNode <IClassification> nodeToRemove) { var parentClassification = nodeToRemove.Tag.Parent; var classifiableToPromote = nodeToPromote.Tag; var parentNode = nodeToRemove.ParentNode; SetParentClassificationIfRequired(parentClassification, classifiableToPromote); // In case removing this node will result in the newly promoted nodes having the same path as an existing node, we will move children and delete instead moveChildrenToEquivalentNode(nodeToPromote, nodeToRemove); // If the item being promoted is a classification type but has nothing within to classify, we can remove the tag from the project if (classifiableToPromote.IsAnImplementationOf <IClassification>() && !nodeToPromote.HasChildren) { _projectRetriever.CurrentProject.RemoveClassification(classifiableToPromote.DowncastTo <IClassification>()); return; } nodeToRemove.RemoveChild(nodeToPromote); if (parentNode != null) { parentNode.AddChild(nodeToPromote); } _explorerPresenter.AddNode(nodeToPromote); }
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); } }); }