Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        public void InsertAfter_SingleNode_AddsNodeAfterNode_AtEnd()
        {
            // Arrange
            var parent = new BasicIntermediateNode("Parent");

            var node1 = new BasicIntermediateNode("Node1");
            var node2 = new BasicIntermediateNode("Node2");
            var node3 = new BasicIntermediateNode("Node3");

            parent.Children.Add(node1);
            parent.Children.Add(node2);

            var reference = new IntermediateNodeReference(parent, node2);

            // Act
            reference.InsertAfter(node3);

            // Assert
            Assert.Equal(new[] { node1, node2, node3, }, parent.Children);
        }
Exemple #5
0
        public void InsertAfter_MultipleNodes_AddsNodesAfterNode()
        {
            // 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);

            var reference = new IntermediateNodeReference(parent, node1);

            // Act
            reference.InsertAfter(new[] { node2, node3 });

            // Assert
            Assert.Equal(new[] { node1, node2, node3, node4, }, parent.Children);
        }
Exemple #6
0
        public void Remove_RemovesNode()
        {
            // Arrange
            var parent = new BasicIntermediateNode("Parent");

            var node1 = new BasicIntermediateNode("Node1");
            var node2 = new BasicIntermediateNode("Node2");
            var node3 = new BasicIntermediateNode("Node3");

            parent.Children.Add(node1);
            parent.Children.Add(node3);
            parent.Children.Add(node2);

            var reference = new IntermediateNodeReference(parent, node3);

            // Act
            reference.Remove();

            // Assert
            Assert.Equal(new[] { node1, node2, }, parent.Children);
        }