public void IHierarchy_adds_grandchild_under_existing_nodes_returns_hierachy_with_same_values(IHierarchy <string, string> hierarchy)
        {
            // ARRANGE

            string test  = "test";
            string test1 = "test1";
            string test2 = "test2";
            string test3 = "test3";

            hierarchy.Add(HierarchyPath.Create <string>(), test);
            hierarchy.Add(HierarchyPath.Create("a"), test1);
            hierarchy.Add(HierarchyPath.Create("b"), test2);

            // ACT

            hierarchy.Add(HierarchyPath.Create("a", "c"), test3);

            // ASSERT
            // new hierarchy contains the root date and the new node.
            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create <string>(), out var value1));
            Assert.Same(test, value1);
            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create("a"), out var value2));
            Assert.Equal(test1, value2);
            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create("b"), out var value3));
            Assert.Equal(test2, value3);
            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create("a", "c"), out var value4));
            Assert.Equal(test3, value4);
        }
        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 IHierarchy_set_value_at_grandchild(IHierarchy <string, string> hierarchy)
        {
            // ARRANGE

            string test  = "test";
            string test1 = "test1";
            string test2 = "test2";
            string test3 = "test3";

            hierarchy[HierarchyPath.Create <string>()] = test;
            hierarchy[HierarchyPath.Create("a")]       = test1;
            hierarchy[HierarchyPath.Create("b")]       = test2;

            // ACT

            hierarchy[HierarchyPath.Create("a", "c")] = test3;

            // ASSERT
            // hierarchy contains the root date and the new node.
            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create <string>(), out var value1));
            Assert.Equal(test, value1);
            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create("a"), out var value2));
            Assert.Equal(test1, value2);
            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create("b"), out var value3));
            Assert.Equal(test2, value3);
            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create("a", "c"), out var value4));
            Assert.Equal(test3, value4);
        }
Exemplo n.º 4
0
        public void IHierarchy_remove_value_from_child_returns_true(IHierarchy <string, string> hierarchy)
        {
            // ARRANGE

            string test  = "test";
            string test1 = "test1";
            string test2 = "test2";

            hierarchy.Add(HierarchyPath.Create <string>(), test);
            hierarchy.Add(HierarchyPath.Create("a"), test1);
            hierarchy.Add(HierarchyPath.Create("a", "b"), test2);

            // ACT

            var result = hierarchy.Remove(HierarchyPath.Create("a"));

            // ASSERT

            Assert.True(result);

            string value;

            // new node has no value
            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create <string>(), out value));
            Assert.Equal(test, value);
            Assert.False(hierarchy.TryGetValue(HierarchyPath.Create("a"), out value));
            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create("a", "b"), out value));
            Assert.Equal(test2, value);
        }
        public void IHierarchy_adds_child_sibling_value_twice_throws_ArgumentException(IHierarchy <string, string> hierarchy)
        {
            // ARRANGE

            string test  = "test";
            string test1 = "test1";
            string test2 = "test2";
            string test3 = "test3";

            hierarchy.Add(HierarchyPath.Create <string>(), test);
            hierarchy.Add(HierarchyPath.Create("a"), test1);
            hierarchy.Add(HierarchyPath.Create("b"), test2);

            // ACT & ASSERT

            var result = Assert.Throws <ArgumentException>(() => hierarchy.Add(HierarchyPath.Create("b"), test3));

            // ASSERT

            Assert.True(result.Message.Contains("already has a value"));
            Assert.True(result.Message.Contains("'b'"));
            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create("b"), out var value));
            Assert.Equal(test2, value);
            Assert.Equal("path", result.ParamName);
        }
Exemplo n.º 6
0
        public void IHierarchy_tryget_value_fails_on_null_path(IHierarchy <string, string> hierarchy)
        {
            // ACT

            var result = Assert.Throws <ArgumentNullException>(() => hierarchy.TryGetValue(null, out var value));

            // ASSERT

            Assert.Equal("path", result.ParamName);
        }
        public void IHierarchy_set_child_sets_value_at_child_node(IHierarchy <string, string> hierarchy)
        {
            // ARRANGE

            string test  = "test";
            string test1 = "test1";

            hierarchy[HierarchyPath.Create <string>()] = test;

            // ACT

            hierarchy[HierarchyPath.Create("a")] = test1;

            // ASSERT
            // hierarchy contains the root date and the new node.
            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create <string>(), out var value));
            Assert.Equal(test, value);
            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create("a"), out value));
            Assert.Equal(test1, value);
        }
        public void IHierarchy_set_child_twice_throws_ArgumentException(IHierarchy <string, string> hierarchy)
        {
            // ARRANGE

            string test  = "test";
            string test1 = "test1";

            hierarchy[HierarchyPath.Create <string>()] = test;
            hierarchy[HierarchyPath.Create("a")]       = test1;

            // ACT

            hierarchy[HierarchyPath.Create("a")] = test1;

            // ASSERT
            // hierarchy contains the root date and the new node.
            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create <string>(), out var value1));
            Assert.Equal(test, value1);
            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create("a"), out var value2));
            Assert.Equal(test1, value2);
        }
Exemplo n.º 9
0
        public void IHierarchy_removes_value_from_root(IHierarchy <string, string> hierarchy)
        {
            // ARRANGE
            string test  = "test";
            string test1 = "test1";

            hierarchy.Add(HierarchyPath.Create <string>(), test);
            hierarchy.Add(HierarchyPath.Create("a"), test1);

            // ACT

            var result = hierarchy.Remove(HierarchyPath.Create <string>());

            // ASSERT

            Assert.True(result);

            string value;

            Assert.False(hierarchy.TryGetValue(HierarchyPath.Create <string>(), out value));
            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create("a"), out value));
            Assert.Equal(test1, 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_set_value_at_root_node(IHierarchy <string, string> hierarchy)
        {
            // ARRANGE

            string test = "test";

            // ACT

            hierarchy[HierarchyPath.Create <string>()] = test;

            // ASSERT
            // hierarchy contains the value
            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create <string>(), out var value));
            Assert.Same(test, value);
        }
        public void IHierarchy_adds_child_sibling(IHierarchy <string, string> hierarchy)
        {
            // ARRANGE

            string test  = "test";
            string test1 = "test1";
            string test2 = "test2";

            hierarchy.Add(HierarchyPath.Create <string>(), test);
            hierarchy.Add(HierarchyPath.Create("a"), test1);

            // ACT

            hierarchy.Add(HierarchyPath.Create("b"), test2);

            // ASSERT
            // new hierarchy contains the root date and the new node.
            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create <string>(), out var value1));
            Assert.Same(test, value1);
            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create("a"), out var value2));
            Assert.Equal(test1, value2);
            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create("b"), out var value3));
            Assert.Equal(test2, value3);
        }
        public void IHierarchy_set_value_at_root_node_twice_overwrites_value(IHierarchy <string, string> hierarchy)
        {
            // ARRANGE

            string test  = "test";
            string test2 = "test2";

            hierarchy[HierarchyPath.Create <string>()] = test;

            // ACT & ASSERT

            hierarchy[HierarchyPath.Create <string>()] = test2;

            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create <string>(), out var value));
            Assert.Same(test2, value);
        }
        public void IHierarchy_adds_value_to_root_node(IHierarchy <string, string> hierarchy)
        {
            // ARRANGE

            string test = "test";

            // ACT

            hierarchy.Add(HierarchyPath.Create <string>(), test);

            // ASSERT
            // new hierarchy contains all values

            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create <string>(), out var value));
            Assert.Same(test, value);
        }
        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));
        }
Exemplo n.º 16
0
        public void IHierarchy_removes_false_if_no_value_was_removed(IHierarchy <string, string> hierarchy)
        {
            // ARRANGE

            string test2 = "test2";

            hierarchy.Add(HierarchyPath.Create("a", "b"), test2);

            // ACT

            var result = hierarchy.Remove(HierarchyPath.Create <string>());

            // ASSERT

            Assert.False(result);

            string value;

            // new node has no value
            Assert.True(hierarchy.TryGetValue(HierarchyPath.Create("a", "b"), out value));
            Assert.Equal(test2, value);
        }
        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));
        }
        public void IHierarchy_root_node_has_no_value_on_TryGetValue(IHierarchy <string, string> hierarchy)
        {
            // ACT & ASSERT

            Assert.False(hierarchy.TryGetValue(HierarchyPath.Create <string>(), out var value));
        }