public void NodeShouldBeTakenFromTransformer()
        {
            var elementTransformer = MockRepository.GenerateStub<ISparkElementTransformer>();
            Node transformedNode = new ElementNode("transformed", new List<AttributeNode>(), false);
            IList<Node> body = new List<Node>();
            var extension = new SparkOverrideExtension(elementTransformer);

            extension.VisitNode(new StubNodeVisitor(), body, null);

            elementTransformer.AssertWasCalled(x => x.Transform(body));
        }
        public void ShouldAppendEndElementIfNodeIsNotEmpty()
        {
            var elementTransformer = MockRepository.GenerateStub<ISparkElementTransformer>();
            Node transformedNode = new ElementNode("transformed", new List<AttributeNode>(), false);
            elementTransformer.Stub(x => x.Transform(null)).IgnoreArguments().Return(transformedNode);
            var extension = new SparkOverrideExtension(elementTransformer);
            var stubNodeVisitor = new StubNodeVisitor();

            extension.VisitNode(stubNodeVisitor, new List<Node>(), null);

            stubNodeVisitor.Nodes.LastOrDefault().As<EndElementNode>().Name.ShouldEqual("transformed");
        }
        public void ShouldNotRet()
        {
            var elementTransformer = MockRepository.GenerateStub<ISparkElementTransformer>();
            var nodeVisitor = MockRepository.GenerateStub<INodeVisitor>();
            IList<Node> body = new List<Node>();
            Node transformedNode = new ElementNode("transformed", new List<AttributeNode>(), false);
            elementTransformer.Stub(x => x.Transform(body)).Return(transformedNode);
            var extension = new SparkOverrideExtension(elementTransformer);

            extension.VisitNode(nodeVisitor, body, null);

            nodeVisitor.AssertWasCalled(x => x.Accept(transformedNode));
            nodeVisitor.AssertWasCalled(x => x.Accept(body));
        }
        public void ShouldVisitTransformedNodeBodyIfNotEmpty()
        {
            var elementTransformer = MockRepository.GenerateStub<ISparkElementTransformer>();
            Node transformedNode = new ElementNode("transformed", new List<AttributeNode>(), false);
            elementTransformer.Stub(x => x.Transform(null)).IgnoreArguments().Return(transformedNode);
            var extension = new SparkOverrideExtension(elementTransformer);
            var stubNodeVisitor = new StubNodeVisitor();
            List<Node> body = new List<Node>() {new TextNode("Body text"), new TextNode("Another one")};
            List<Node> expectedNodes = new List<Node> { transformedNode };
            expectedNodes.AddRange(body);

            extension.VisitNode(stubNodeVisitor, body, null);

            stubNodeVisitor.Nodes.ShouldStartWith(expectedNodes);
        }
        public void ShouldVisitTransformedNodeOnlyIfItIsEmpty()
        {
            var elementTransformer = MockRepository.GenerateStub<ISparkElementTransformer>();
            Node transformedNode = new ElementNode("transformed", new List<AttributeNode>(), true);
            elementTransformer.Stub(x => x.Transform(null)).IgnoreArguments().Return(transformedNode);
            var extension = new SparkOverrideExtension(elementTransformer);
            var stubNodeVisitor = new StubNodeVisitor();

            extension.VisitNode(stubNodeVisitor, new List<Node>(){new TextNode("Ignore this body text")}, null);

            stubNodeVisitor.Nodes.ShouldOnlyContain(transformedNode);
        }