public void InsertBefore_MulipleNodes_ThrowsForReferenceNotInitialized()
    {
        // Arrange
        var reference = new IntermediateNodeReference();

        // Act & Assert
        var exception = Assert.Throws <InvalidOperationException>(() => reference.InsertBefore(new[] { new BasicIntermediateNode("_") }));

        Assert.Equal("The reference is invalid. References initialized with the default constructor cannot modify nodes.", exception.Message);
    }
    public void InsertBefore_MulipleNodes_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.InsertBefore(new[] { new BasicIntermediateNode("_") }));

        Assert.Equal("The reference is invalid. The node 'Node1' could not be found as a child of 'Parent'.", exception.Message);
    }
    public void InsertBefore_MulipleNodes_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.InsertBefore(new[] { new BasicIntermediateNode("_") }));

        Assert.Equal("The node 'Parent' has a read-only child collection and cannot be modified.", exception.Message);
    }
    public void InsertBefore_SingleNode_AddsNodeBeforeNode_AtBeginning()
    {
        // Arrange
        var parent = new BasicIntermediateNode("Parent");

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

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

        var reference = new IntermediateNodeReference(parent, node2);

        // Act
        reference.InsertBefore(node1);

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

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

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