Beispiel #1
0
        public void LiteDbMutableNode_fails_on_removing_if_node_has_child_nodes()
        {
            // ARRANGE

            var child       = new LiteDbMutableNode <int>(this.nodes, new BsonDocument(), "a");
            var secondChild = new LiteDbMutableNode <int>(this.nodes, new BsonDocument(), "b");
            var node        = new LiteDbMutableNode <int>(this.nodes, this.rootDocument).AddChild(child).AddChild(secondChild);
            var grandChild  = new LiteDbMutableNode <int>(this.nodes, new BsonDocument(), "c");

            child.AddChild(grandChild);

            // ACT

            var result = node.RemoveAllChildNodes(recurse: false);

            // ASSERT
            // node has a child now

            Assert.False(result);
            Assert.True(node.HasChildNodes);

            // check db
            // all nodes are still there

            Assert.Equal(4, this.nodes.FindAll().Count());
        }
Beispiel #2
0
        public void LiteDbMutableNode_RemoveAllChildNodes_returns_false_if_no_nodes_have_been_deleted()
        {
            // ARRANGE

            var node = new LiteDbMutableNode <int>(this.nodes, this.rootDocument);

            // ACT

            var result = node.RemoveAllChildNodes(recurse: false);

            // ASSERT
            // node has a child now

            Assert.False(result);
            Assert.False(node.HasChildNodes);
        }
Beispiel #3
0
        public void LiteDbMutableNode_removes_all_childnodes_recursivly()
        {
            // ARRANGE
            //           <node>
            //           /   \
            //          a     b
            //         /
            //        c

            var grandChild  = new LiteDbMutableNode <int>(this.nodes, new BsonDocument(), "c");
            var child       = new LiteDbMutableNode <int>(this.nodes, new BsonDocument(), "a").AddChild(grandChild);
            var secondChild = new LiteDbMutableNode <int>(this.nodes, new BsonDocument(), "b");
            var node        = new LiteDbMutableNode <int>(this.nodes, this.rootDocument).AddChild(child).AddChild(secondChild);

            // ACT

            var result = node.RemoveAllChildNodes(recurse: true);

            // ASSERT
            // descendants have been removed

            Assert.True(result);
            Assert.False(node.HasChildNodes);

            var(found, addedChild) = node.TryGetChildNode("a");

            Assert.False(found);
            Assert.False(node.ChildNodes.Any());

            // check db
            // only the node is there

            var rootDoc = this.nodes.FindAll().Single();

            Assert.NotNull(rootDoc);
            Assert.True(rootDoc.TryGetValue("cn", out var childNodesDoc));
            Assert.Equal(0, childNodesDoc.AsDocument.Count);
        }