예제 #1
0
        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>());
        }
예제 #2
0
        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"));
        }
예제 #3
0
        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"));
        }