public void IHierarchy_child_of_root_has_root_as_parent_on_traversal(IHierarchy <string, string> hierarchy) { // ARRANGE hierarchy.Add(HierarchyPath.Create("a"), "v1"); var root = hierarchy.Traverse(HierarchyPath.Create <string>()); // ACT var result = hierarchy.Traverse(HierarchyPath.Create <string>()).Children().Single().Parent(); // ASSERT Assert.Equal(root, result); }
public void IHierarchy_throw_if_start_path_doesnt_exist(IHierarchy <string, string> hierarchy) { // ARRANGE hierarchy.Add(HierarchyPath.Create("a"), "v1"); var node_a = hierarchy.Traverse(HierarchyPath.Create <string>()).Children().First(); // ACT var result = Assert.Throws <KeyNotFoundException>(() => hierarchy.Traverse(HierarchyPath.Create("b"))); // ASSERT Assert.True(result.Message.Contains("'b'")); }
public void IHierarchy_start_at_child_of_root_on_traversal(IHierarchy <string, string> hierarchy) { // ARRANGE hierarchy.Add(HierarchyPath.Create("a"), "v1"); var node_a = hierarchy.Traverse(HierarchyPath.Create <string>()).Children().Single(); // ACT var result = hierarchy.Traverse(HierarchyPath.Create("a")); // ASSERT Assert.NotNull(result); Assert.Equal(HierarchyPath.Create("a"), result.Path); }
public void IHierarchy_root_node_has_no_parent_on_traversal(IHierarchy <string, string> hierarchy) { // ACT var traverser = hierarchy.Traverse(HierarchyPath.Create <string>()); // ACT & ASSERT Assert.False(traverser.HasParentNode); }
public void IHierarchy_root_node_has_no_children_on_traversal(IHierarchy <string, string> hierarchy) { // ACT var result = hierarchy.Traverse(HierarchyPath.Create <string>()).HasChildNodes; // ASSERT Assert.False(result); }
public void IHierarchy_root_node_has_empty_path_on_traversal(IHierarchy <string, string> hierarchy) { // ACT var result = hierarchy.Traverse(HierarchyPath.Create <string>()); // ASSERT Assert.Equal(HierarchyPath.Create <string>(), result.Path); }
public void IHierarchy_root_node_has_no_value_on_traversal(IHierarchy <string, string> hierarchy) { // ACT var traverser = hierarchy.Traverse(HierarchyPath.Create <string>()); // ACT & ASSERT Assert.False(traverser.TryGetValue(out var value)); }
public void IHierarchy_root_has_no_parent(IHierarchy <string, string> hierarchy) { // ACT var result = hierarchy.Traverse(HierarchyPath.Create <string>()).HasParentNode; // ASSERT Assert.False(result); }
public void IHierarchy_child_node_knows_its_path_on_traversal(IHierarchy <string, string> hierarchy) { // ARRANGE hierarchy.Add(HierarchyPath.Create("a"), "v1"); // ACT var result = hierarchy.Traverse(HierarchyPath.Create <string>()).ChildNodes.Single().Path; // ASSERT Assert.Equal(HierarchyPath.Create("a"), result); }
public void IHierarchy_get_root_nodes_value_on_traversal(IHierarchy <string, string> hierarchy) { // ARRANGE hierarchy.Add(HierarchyPath.Create <string>(), "v1"); // ACT var result = hierarchy.Traverse(HierarchyPath.Create <string>()).TryGetValue(out var result_value); // ASSERT Assert.Equal("v1", result_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_get_children_of_root_node_on_traversal(IHierarchy <string, string> hierarchy) { // ARRANGE hierarchy.Add(HierarchyPath.Create("a"), "v1"); hierarchy.Add(HierarchyPath.Create("b"), "v2"); // ACT var result = hierarchy.Traverse(HierarchyPath.Create <string>()).ChildNodes.ToArray(); // ASSERT Assert.Equal(2, result.Length); }
public void IHierarchy_start_at_inner_node_stil_allows_to_ascend(IHierarchy <string, string> hierarchy) { // ARRANGE hierarchy.Add(HierarchyPath.Create("a"), "v1"); hierarchy.Add(HierarchyPath.Create("a", "b", "c"), "v2"); // ACT var result = hierarchy.Traverse(HierarchyPath.Create("a", "b", "c")); // ASSERT Assert.NotNull(result); Assert.Equal(new[] { HierarchyPath.Create("a", "b", "c"), HierarchyPath.Create("a", "b"), HierarchyPath.Create("a"), HierarchyPath.Create <string>(), }, result.AncestorsAndSelf().Select(n => n.Path).ToArray()); }
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)); }