public void Replace_ThrowsForReferenceNotInitialized() { // Arrange var reference = new IntermediateNodeReference(); // Act & Assert var exception = Assert.Throws <InvalidOperationException>(() => reference.Replace(new BasicIntermediateNode("_"))); Assert.Equal("The reference is invalid. References initialized with the default constructor cannot modify nodes.", exception.Message); }
public void Replace_ThrowsForNodeNotFound() { // Arrange var parent = new BasicIntermediateNode("Parent"); var node1 = new BasicIntermediateNode("Node1"); var reference = new IntermediateNodeReference(parent, node1); // Act & Assert var exception = Assert.Throws <InvalidOperationException>(() => reference.Replace(new BasicIntermediateNode("_"))); Assert.Equal("The reference is invalid. The node 'Node1' could not be found as a child of 'Parent'.", exception.Message); }
public void Replace_ThrowsForReadOnlyCollection() { // Arrange var parent = new BasicIntermediateNode("Parent", IntermediateNodeCollection.ReadOnly); var node1 = new BasicIntermediateNode("Node1"); var reference = new IntermediateNodeReference(parent, node1); // Act & Assert var exception = Assert.Throws <InvalidOperationException>(() => reference.Replace(new BasicIntermediateNode("_"))); Assert.Equal("The node 'Parent' has a read-only child collection and cannot be modified.", exception.Message); }
public void Replace_ReplacesNode() { // Arrange var parent = new BasicIntermediateNode("Parent"); var node1 = new BasicIntermediateNode("Node1"); var node2 = new BasicIntermediateNode("Node2"); var node3 = new BasicIntermediateNode("Node3"); var node4 = new BasicIntermediateNode("Node4"); parent.Children.Add(node1); parent.Children.Add(node4); parent.Children.Add(node3); var reference = new IntermediateNodeReference(parent, node4); // Act reference.Replace(node2); // Assert Assert.Equal(new[] { node1, node2, node3, }, parent.Children); }