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")); }
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]); }
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")); }
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); }
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); }
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 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 ExceptionIfNullChild() { var node = new DummyNavigable("MyParent"); DummyNavigable child = null; Assert.Throws <ArgumentNullException>(() => node.Add(child)); }
public void AddChildrenThrowExceptionIfNull() { var node = new DummyNavigable("MyParent"); List <DummyNavigable> children = null; Assert.Throws <ArgumentNullException>(() => node.Add(children)); }
public void ChildrenGetsByName() { var node = new DummyNavigable("MyChild"); var parentNode = new DummyNavigable("MyParent"); parentNode.Add(node); Assert.AreSame(node, parentNode.Children["MyChild"]); }
public void RemoveChildrenAfterDisposeThrowsException() { var node = new DummyNavigable("node"); node.Add(new DummyNavigable("child")); node.Dispose(); Assert.That(node.RemoveChildren, Throws.TypeOf <ObjectDisposedException>()); }
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 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); }
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]); }
public void AddThrowsExceptionAfterDispose() { var node = new DummyNavigable("MyParent"); DummyNavigable child = null; node.Dispose(); Assert.That( () => node.Add(child), Throws.TypeOf <ObjectDisposedException>()); }
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); }
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); }
public void DisposeRemoveChildrens() { DummyNavigable parent = new DummyNavigable("Parent"); DummyNavigable child1 = new DummyNavigable("Child1"); DummyNavigable child2 = new DummyNavigable("Child2"); DummyNavigable subchild1 = new DummyNavigable("Subchild1"); child1.Add(subchild1); parent.Add(child1); parent.Add(child2); parent.Dispose(); Assert.IsEmpty(parent.Children); Assert.IsEmpty(child1.Children); Assert.IsTrue(parent.Disposed); Assert.IsTrue(child1.Disposed); Assert.IsTrue(child2.Disposed); Assert.IsTrue(subchild1.Disposed); }
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 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]); }
public void RemoveChildrenDisposeChildren() { 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); Assert.IsFalse(parent.Disposed); Assert.IsFalse(child1.Disposed); Assert.IsFalse(child2.Disposed); Assert.IsFalse(subchild1.Disposed); parent.RemoveChildren(); Assert.IsFalse(parent.Disposed); Assert.IsTrue(child1.Disposed); Assert.IsTrue(child2.Disposed); Assert.IsTrue(subchild1.Disposed); }
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>()); }
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 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); }
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 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]); }
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)); }