Пример #1
0
        public void RemoveChildByNameThrowsWhenNull()
        {
            var node   = new DummyNavigable("My parent");
            var child1 = new DummyNavigable("Child1");

            node.Add(child1);

            Assert.That(
                () => node.Remove((string)null),
                Throws.ArgumentNullException);
            Assert.That(
                () => node.Remove(string.Empty),
                Throws.ArgumentNullException);
        }
Пример #2
0
        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);
        }
Пример #3
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);
        }
Пример #4
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>());
        }
Пример #5
0
        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));
        }
Пример #6
0
        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));
        }