public void SortChildrenWithComparison()
        {
            using DummyNavigable parent    = new DummyNavigable("Parent");
            using DummyNavigable child1    = new DummyNavigable("Child1");
            using DummyNavigable child2    = new DummyNavigable("Child2");
            using DummyNavigable subchild1 = new DummyNavigable("Subchild1");
            using DummyNavigable subchild2 = new DummyNavigable("Subchild2");

            child1.Add(subchild1);
            child1.Add(subchild2);
            parent.Add(child1);
            parent.Add(child2);

            Assert.That(parent.Children[0].Name, Is.EqualTo("Child1"));
            Assert.That(parent.Children[1].Name, Is.EqualTo("Child2"));
            Assert.That(child1.Children[0].Name, Is.EqualTo("Subchild1"));
            Assert.That(child1.Children[1].Name, Is.EqualTo("Subchild2"));

            parent.SortChildren((x, y) => string.Compare(y.Name, x.Name, StringComparison.CurrentCulture));

            Assert.That(parent.Children[0].Name, Is.EqualTo("Child2"));
            Assert.That(parent.Children[1].Name, Is.EqualTo("Child1"));
            Assert.That(child1.Children[0].Name, Is.EqualTo("Subchild2"));
            Assert.That(child1.Children[1].Name, Is.EqualTo("Subchild1"));
        }
Exemple #2
0
        public void AddChildrenThrowExceptionIfNull()
        {
            var node = new DummyNavigable("MyParent");
            List <DummyNavigable> children = null;

            Assert.Throws <ArgumentNullException>(() => node.Add(children));
        }
Exemple #3
0
        public void TagsAllowAdding()
        {
            var node = new DummyNavigable("MyNameTest");

            node.Tags["MyTag"] = 5;
            Assert.AreEqual(5, node.Tags["MyTag"]);
        }
        public void AddChildUpdatesChildrenAndParent()
        {
            using var parent1 = new DummyNavigable("parent1");
            using var parent2 = new DummyNavigable("parent2");
            using var child1  = new DummyNavigable("child1");
            using var child2  = new DummyNavigable("child2");

            parent1.Add(child1);
            parent2.Add(child2);

            Assert.AreSame(parent1, child1.Parent);
            Assert.AreSame(parent2, child2.Parent);
            Assert.AreEqual(1, parent1.Children.Count);
            Assert.AreEqual(1, parent2.Children.Count);
            Assert.AreSame(child1, parent1.Children[0]);
            Assert.AreSame(child2, parent2.Children[0]);

            parent1.Add(child2);

            Assert.AreSame(parent1, child1.Parent);
            Assert.AreSame(parent1, child2.Parent);
            Assert.AreEqual(2, parent1.Children.Count);
            Assert.AreEqual(0, parent2.Children.Count);
            Assert.AreSame(child1, parent1.Children[0]);
            Assert.AreSame(child2, parent1.Children[1]);
        }
Exemple #5
0
        public void ExceptionIfNullChild()
        {
            var            node  = new DummyNavigable("MyParent");
            DummyNavigable child = null;

            Assert.Throws <ArgumentNullException>(() => node.Add(child));
        }
Exemple #6
0
        public void DisposeTwiceDoesNotThrowException()
        {
            var node = new DummyNavigable("node");

            node.Dispose();
            Assert.That(node.Dispose, Throws.Nothing);
        }
        public void SortChildrenWithCustomComparer()
        {
            using DummyNavigable parent    = new DummyNavigable("Parent");
            using DummyNavigable child1    = new DummyNavigable("Child1");
            using DummyNavigable child2    = new DummyNavigable("Child2");
            using DummyNavigable subchild1 = new DummyNavigable("Subchild1");
            using DummyNavigable subchild2 = new DummyNavigable("Subchild2");

            child1.Add(subchild1);
            child1.Add(subchild2);
            parent.Add(child1);
            parent.Add(child2);

            Assert.That(parent.Children[0].Name, Is.EqualTo("Child1"));
            Assert.That(parent.Children[1].Name, Is.EqualTo("Child2"));
            Assert.That(child1.Children[0].Name, Is.EqualTo("Subchild1"));
            Assert.That(child1.Children[1].Name, Is.EqualTo("Subchild2"));

            parent.SortChildren(new ReverseNodeComparer());

            Assert.That(parent.Children[0].Name, Is.EqualTo("Child2"));
            Assert.That(parent.Children[1].Name, Is.EqualTo("Child1"));
            Assert.That(child1.Children[0].Name, Is.EqualTo("Subchild2"));
            Assert.That(child1.Children[1].Name, Is.EqualTo("Subchild1"));
        }
Exemple #8
0
        public void ChildrenGetsByName()
        {
            var node       = new DummyNavigable("MyChild");
            var parentNode = new DummyNavigable("MyParent");

            parentNode.Add(node);
            Assert.AreSame(node, parentNode.Children["MyChild"]);
        }
Exemple #9
0
        public void RemoveChildrenAfterDisposeThrowsException()
        {
            var node = new DummyNavigable("node");

            node.Add(new DummyNavigable("child"));
            node.Dispose();
            Assert.That(node.RemoveChildren, Throws.TypeOf <ObjectDisposedException>());
        }
Exemple #10
0
        public void DisposeChangesProperty()
        {
            var node = new DummyNavigable("node");

            Assert.That(node.Disposed, Is.False);
            node.Dispose();
            Assert.That(node.Disposed, Is.True);
        }
        public void RemoveChildByNameDisposes()
        {
            using var node   = new DummyNavigable("My parent");
            using var child1 = new DummyNavigable("Child1");
            node.Add(child1);

            Assert.That(node.Remove("Child1"), Is.True);
            Assert.That(child1.Disposed, Is.True);
        }
 public void DefaultValues()
 {
     using var node = new DummyNavigable("NodeName");
     Assert.AreEqual("NodeName", node.Name);
     Assert.AreEqual("/NodeName", node.Path);
     Assert.IsNull(node.Parent);
     Assert.IsEmpty(node.Children);
     Assert.IsEmpty(node.Tags);
 }
        public void AddNodeWithSameNameRootIsNotParent()
        {
            using var node1 = new DummyNavigable("Node");
            using var node2 = new DummyNavigable("Node");
            node1.Add(node2);

            Assert.AreSame(node1, node2.Parent);
            Assert.AreEqual(1, node1.Children.Count);
            Assert.AreSame(node2, node1.Children[0]);
        }
Exemple #14
0
        public void AddThrowsExceptionAfterDispose()
        {
            var            node  = new DummyNavigable("MyParent");
            DummyNavigable child = null;

            node.Dispose();
            Assert.That(
                () => node.Add(child),
                Throws.TypeOf <ObjectDisposedException>());
        }
Exemple #15
0
        public void PathWithParent()
        {
            var node       = new DummyNavigable("MyChild");
            var parentNode = new DummyNavigable("MyParent");

            parentNode.Add(node);

            Assert.AreEqual("/MyParent/MyChild", node.Path);
            Assert.AreEqual("/MyParent", parentNode.Path);
        }
Exemple #16
0
        public void RemoveChildByNodeDoesNotDispose()
        {
            var node   = new DummyNavigable("My parent");
            var child1 = new DummyNavigable("Child1");

            node.Add(child1);

            Assert.That(node.Remove(child1), Is.True);

            Assert.That(child1.Disposed, Is.False);
        }
Exemple #17
0
        public void AddChildUpdatesChildrenAndParent()
        {
            var node       = new DummyNavigable("MyChild");
            var parentNode = new DummyNavigable("MyParent");

            parentNode.Add(node);

            Assert.AreSame(parentNode, node.Parent);
            Assert.AreEqual(1, parentNode.Children.Count);
            Assert.AreSame(node, parentNode.Children[0]);
        }
Exemple #18
0
        public void RemoveChildByNodeThrowsWhenNull()
        {
            var node   = new DummyNavigable("My parent");
            var child1 = new DummyNavigable("Child1");

            node.Add(child1);

            Assert.That(
                () => node.Remove((DummyNavigable)null),
                Throws.ArgumentNullException);
        }
        public void AddParentThrowException()
        {
            using var grandparent = new DummyNavigable("Grandparent");
            using var parent      = new DummyNavigable("Parent");
            using var child       = new DummyNavigable("Child");
            grandparent.Add(parent);
            parent.Add(child);

            Assert.That(() => child.Add(parent), Throws.ArgumentException);
            Assert.That(() => child.Add(grandparent), Throws.ArgumentException);
            Assert.That(() => parent.Add(grandparent), Throws.ArgumentException);
        }
Exemple #20
0
        public void RemoveChildByNameThrowsWhenDisposed()
        {
            var node   = new DummyNavigable("My parent");
            var child1 = new DummyNavigable("Child1");

            node.Add(child1);
            node.Dispose();

            Assert.That(
                () => node.Remove("Child1"),
                Throws.InstanceOf <ObjectDisposedException>());
        }
Exemple #21
0
        public void AddChildrenThrowsExceptionAfterDispose()
        {
            var node     = new DummyNavigable("MyParent");
            var children = new List <DummyNavigable> {
                new DummyNavigable("child")
            };

            node.Dispose();
            Assert.That(
                () => node.Add(children),
                Throws.TypeOf <ObjectDisposedException>());
        }
        public void SortChildrenAfterDisposeThrowsException()
        {
            var node = new DummyNavigable("node");

            using var child = new DummyNavigable("child");
            node.Add(child);
            node.Dispose();
            Assert.That(() => node.SortChildren(), Throws.TypeOf <ObjectDisposedException>());
            Assert.That(() => node.SortChildren(new ReverseNodeComparer()), Throws.TypeOf <ObjectDisposedException>());
            Assert.That(
                () => node.SortChildren((x, y) => string.Compare(y.Name, x.Name, StringComparison.CurrentCulture)),
                Throws.TypeOf <ObjectDisposedException>());
        }
        public void RemoveChildByName()
        {
            using var node   = new DummyNavigable("My parent");
            using var child1 = new DummyNavigable("Child1");
            using var child2 = new DummyNavigable("Child2");
            node.Add(child1);
            node.Add(child2);

            Assert.That(node.Children.Count, Is.EqualTo(2));
            Assert.That(node.Remove("Child1"), Is.True);

            Assert.That(node.Children.Count, Is.EqualTo(1));
            Assert.That(node.Children[0], Is.SameAs(child2));
        }
        public void RemoveChildrenRemovesInnerChildren()
        {
            using DummyNavigable parent    = new DummyNavigable("Parent");
            using DummyNavigable child1    = new DummyNavigable("Child1");
            using DummyNavigable child2    = new DummyNavigable("Child2");
            using DummyNavigable subchild1 = new DummyNavigable("Subchild1");
            child1.Add(subchild1);
            parent.Add(child1);
            parent.Add(child2);

            parent.RemoveChildren();
            Assert.IsEmpty(parent.Children);
            Assert.IsEmpty(child1.Children);
        }
Exemple #25
0
        public void ReplaceIfSameName()
        {
            var children1 = new DummyNavigable("MyChild1");
            var children2 = new DummyNavigable("MyChild1");
            var parent    = new DummyNavigable("MyParent");

            parent.Add(children1);
            Assert.AreEqual(1, parent.Children.Count);
            Assert.AreSame(children1, parent.Children[0]);

            parent.Add(children2);
            Assert.AreEqual(1, parent.Children.Count);
            Assert.AreSame(children2, parent.Children[0]);
            Assert.AreNotSame(children1, parent.Children[0]);
        }
        public void AddNonRelatedNodesWithSimilarNames()
        {
            using var root1  = new DummyNavigable("data");
            using var root2  = new DummyNavigable("data");
            using var child1 = new DummyNavigable("node_parent");
            using var child2 = new DummyNavigable("node");

            root1.Add(child1);
            root2.Add(child2);
            child1.Add(child2);

            Assert.AreSame(child1, child2.Parent);
            Assert.AreEqual(1, child1.Children.Count);
            Assert.AreSame(child2, child1.Children[0]);
        }
Exemple #27
0
        public void RemoveChildren()
        {
            var children = new List <DummyNavigable>();

            children.Add(new DummyNavigable("MyChild1"));
            children.Add(new DummyNavigable("MyChild2"));
            children.Add(new DummyNavigable("MyChild3"));
            var parent = new DummyNavigable("MyParent");

            parent.Add(children);
            Assert.AreEqual(3, parent.Children.Count);

            parent.RemoveChildren();
            Assert.IsEmpty(parent.Children);
        }
Exemple #28
0
        public void AddAllChildren()
        {
            var children = new List <DummyNavigable>();

            children.Add(new DummyNavigable("MyChild1"));
            children.Add(new DummyNavigable("MyChild2"));
            children.Add(new DummyNavigable("MyChild3"));
            var parent = new DummyNavigable("MyParent");

            parent.Add(children);
            Assert.AreEqual(3, parent.Children.Count);
            Assert.AreSame(children[0], parent.Children[0]);
            Assert.AreSame(children[1], parent.Children[1]);
            Assert.AreSame(children[2], parent.Children[2]);
        }
        public void RemoveChildByNameReturnsFalseIfNoFound()
        {
            using var node   = new DummyNavigable("My parent");
            using var node2  = new DummyNavigable("My parent2");
            using var child1 = new DummyNavigable("Child1");
            node2.Add(child1);
            using var child2 = new DummyNavigable("Child2");
            node.Add(child2);

            Assert.That(node.Children.Count, Is.EqualTo(1));
            Assert.That(node.Children[0], Is.SameAs(child2));
            Assert.That(node.Remove("Child1"), Is.False);

            Assert.That(node.Children.Count, Is.EqualTo(1));
            Assert.That(child1.Disposed, Is.False);
            Assert.That(child1.Parent, Is.SameAs(node2));
        }
Exemple #30
0
        public void ReplaceDisposePreviousChild()
        {
            var child1 = new DummyNavigable("MyChild1");
            var child2 = new DummyNavigable("MyChild1");
            var parent = new DummyNavigable("MyParent");

            parent.Add(child1);
            Assert.AreEqual(1, parent.Children.Count);
            Assert.AreSame(child1, parent.Children[0]);
            Assert.That(child1.Disposed, Is.False);

            parent.Add(child2);
            Assert.AreEqual(1, parent.Children.Count);
            Assert.AreSame(child2, parent.Children[0]);
            Assert.AreNotSame(child1, parent.Children[0]);
            Assert.That(child1.Disposed, Is.True);
            Assert.That(child2.Disposed, Is.False);
        }