public void IHierarchy_RemoveNode_non_recursive_fails_if_childnode_is_present(string nodePath, string subNodePath, IHierarchy <string, string> hierarchy) { // ARRANGE string test = "test"; string test1 = "test1"; hierarchy.Add(HierarchyPath.Parse(nodePath, "/"), test); hierarchy.Add(HierarchyPath.Parse(subNodePath, "/"), test1); // ACT var result = hierarchy.RemoveNode(HierarchyPath.Parse(nodePath, "/"), recurse: false); // ASSERT Assert.False(result); string value; // node has no value Assert.True(hierarchy.TryGetValue(HierarchyPath.Parse(nodePath, "/"), out value)); Assert.Equal(test, value); Assert.True(hierarchy.TryGetValue(HierarchyPath.Parse(subNodePath, "/"), out value)); Assert.Equal(test1, value); }
public void Dispose() { if (_loadedUserInterface) { var node = _hierarchy.Lookup(_canvasEntity); _hierarchy.RemoveNode(node); } }
public void IHierarchy_RemoveNode_twice_returns_true_for_root_node(string path, bool recurse, IHierarchy <string, string> hierarchy) { // ARRANGE string test = "test"; hierarchy.Add(HierarchyPath.Parse(path, "/"), test); hierarchy.RemoveNode(HierarchyPath.Parse(path, "/"), recurse: recurse); // ACT var result = hierarchy.RemoveNode(HierarchyPath.Parse(path, "/"), recurse: recurse); // ASSERT Assert.True(result); }
public void IHierarchy_RemoveNode_unknown_node_returns_false(IHierarchy <string, string> hierarchy) { // ACT var result = hierarchy.RemoveNode(HierarchyPath.Create("a"), recurse: false); // ASSERT Assert.False(result); }
public async Task DiscardAsync(IPlan plan) { #endif var planAsNode = (DefaultNode)plan; planAsNode.Discarded = true; foreach (var plan1 in planAsNode.PlannedCreatedNodes) { var toCreate = (DefaultNode)plan1; var parent = toCreate.ParentPlan; if (parent != null) { _hierarchy.RemoveChildNode(parent, toCreate); } else { _hierarchy.RemoveRootNode(toCreate); } toCreate.Parent = null; toCreate.Discarded = true; } var nodeParent = planAsNode.ParentPlan; if (nodeParent != null) { _hierarchy.RemoveChildNode(nodeParent, planAsNode); } else { _hierarchy.RemoveRootNode(planAsNode); } if (plan.DiscardOnResolve.Count > 0) { foreach (var child in plan.DiscardOnResolve.ToList()) { _hierarchy.RemoveNode((INode)child); } } }
public void IHierarchy_removes_root_by_removing_its_value(IHierarchy <string, string> hierarchy) { // ARRANGE hierarchy.Add(HierarchyPath.Create <string>(), "test"); // ACT var result = hierarchy.RemoveNode(HierarchyPath.Create <string>(), recurse: false); // ASSERT Assert.True(result); // value is removed Assert.False(hierarchy.TryGetValue(HierarchyPath.Create <string>(), out var value)); }
public void IHierarchy_RemoveNode_removes_inner_node_from_hierarchy_and_descendants(string nodeToDelete, IHierarchy <string, string> hierarchy) { // ARRANGE // node // \ // subNode var nodePath = HierarchyPath.Parse(nodeToDelete, "/"); hierarchy.Add(nodePath, nodePath.ToString()); // add subnode with value var subNode = nodePath.Join("subNode"); hierarchy.Add(subNode, subNode.ToString()); // ACT // remove node and subNode var result = hierarchy.RemoveNode(nodePath, recurse: true); // ASSERT // node could be removed Assert.True(result); // values of node and subNode can't be read anymore Assert.False(hierarchy.TryGetValue(nodePath, out var valueNode)); Assert.False(hierarchy.TryGetValue(subNode, out var valueSubNode)); // nodes are no longer present if (!nodePath.IsRoot) { Assert.Throws <KeyNotFoundException>(() => hierarchy.Traverse(nodePath)); } Assert.Throws <KeyNotFoundException>(() => hierarchy.Traverse(subNode)); }
public void IHierarchy_RemoveNode_removes_leaf_from_hierarchy(string pathToDelete, bool recurse, IHierarchy <string, string> hierarchy) { // ARRANGE var path = HierarchyPath.Parse(pathToDelete, "/"); hierarchy.Add(path, pathToDelete); // ACT // the value of recurse doen't make difference var result = hierarchy.RemoveNode(path, recurse: recurse); // ASSERT // result must be true always Assert.True(result); // node has no value Assert.False(hierarchy.TryGetValue(path, out var _)); // nodes are no longer present Assert.Throws <KeyNotFoundException>(() => hierarchy.Traverse(path)); }