Exemplo n.º 1
0
        public void BuildHamlDocument_UnnamedPartialReference_UsesFollowingPartial()
        {
            var rootViewSource = ViewSourceBuilder.Create("MainFile");
            var rootDocument   = HamlDocumentBuilder.Create("MainFile",
                                                            new HamlNodePartial(new HamlLine("", HamlRuleEnum.Partial, "", 0)));

            _treeParserMock.Setup(x => x.ParseViewSource(rootViewSource))
            .Returns(rootDocument);

            var childViewSource = ViewSourceBuilder.Create("SubDocument", "SubDocument");
            var childDocument   = HamlDocumentBuilder.Create("SubDocument)",
                                                             new HamlNodeTextContainer(0, "Child Test"));

            _treeParserMock.Setup(x => x.ParseViewSource(childViewSource))
            .Returns(childDocument);

            var viewSourceList = new ViewSourceCollection {
                rootViewSource, childViewSource
            };

            var result = _templateFactoryFactory.BuildHamlDocument(viewSourceList);

            Assert.That(result, Is.SameAs(rootDocument));
            Assert.That(((HamlNodePartial)result.Children.First()).IsResolved, Is.True);
            Assert.That(result.Children.First().Children.First(), Is.SameAs(childDocument.Children.First()));
        }
Exemplo n.º 2
0
        public void BuildHamlDocument_UnknownPartial_UsesTemplateContentProvider()
        {
            const string partialName    = "SubDocument";
            var          rootViewSource = ViewSourceBuilder.Create("MainFile");
            var          rootDocument   = HamlDocumentBuilder.Create("MainFile",
                                                                     new HamlNodePartial(new HamlLine(partialName, HamlRuleEnum.Partial, "", 0)));

            _treeParserMock.Setup(x => x.ParseViewSource(rootViewSource))
            .Returns(rootDocument);
            var viewSourceList = new ViewSourceCollection {
                rootViewSource
            };

            var childViewSource = ViewSourceBuilder.Create("SubDocument", partialName);
            var childDocument   = HamlDocumentBuilder.Create("SubDocument)",
                                                             new HamlNodeTextContainer(0, "Child Test"));

            _treeParserMock.Setup(x => x.ParseViewSource(childViewSource))
            .Returns(childDocument);

            _templateContentProviderMock.Setup(x => x.GetViewSource(partialName))
            .Returns(childViewSource);

            var result = _templateFactoryFactory.BuildHamlDocument(viewSourceList);

            _templateContentProviderMock.Verify(x => x.GetViewSource(partialName));
        }
Exemplo n.º 3
0
 public void SetUp()
 {
     _parserMock = new Mock <ITreeParser>();
     _parserMock.Setup(x => x.ParseViewSource(It.IsAny <ViewSource>()))
     .Returns(HamlDocumentBuilder.Create());
     _compilerMock                = new Mock <ITemplateFactoryCompiler>();
     _documentWalkerMock          = new Mock <IDocumentWalker>();
     _templateContentProviderMock = new Mock <ITemplateContentProvider>();
     _contentProviderMock         = new Mock <ITemplateContentProvider>();
 }
Exemplo n.º 4
0
        public void WalkChildren_HtmlCommentNode_WalksHtmlCommentNode()
        {
            const string comment  = "test";
            var          document = HamlDocumentBuilder.Create("",
                                                               new HamlNodeHtmlComment(new HamlLine(comment, HamlRuleEnum.HtmlComment, "", 0)));

            _walker.Walk(document);

            Assert.That(_classBuilderMock.Build(""), Is.StringContaining(comment));
        }
Exemplo n.º 5
0
        public void WalkChildren_TagNode_WalksTagNode()
        {
            const string tagName  = "div";
            var          document = HamlDocumentBuilder.Create("",
                                                               new HamlNodeTag(new HamlLine(tagName, HamlRuleEnum.PlainText, "", 0)));

            _walker.Walk(document);

            Assert.That(_classBuilderMock.Build(""), Is.StringContaining(tagName));
        }
Exemplo n.º 6
0
        public void WalkChildren_TextNode_WalksTextNode()
        {
            const string testText = "Hello world";
            var          document = HamlDocumentBuilder.Create("",
                                                               new HamlNodeTextContainer(new HamlLine(testText, HamlRuleEnum.PlainText, "", 0)));

            _walker.Walk(document);

            Assert.That(_classBuilderMock.Build(""), Is.StringContaining(testText));
        }
Exemplo n.º 7
0
        public void Walk_NextTagHasSurroundingWhitespaceRemoved_RendersTag(string whiteSpace)
        {
            var node = HamlDocumentBuilder.Create("",
                                                  new HamlNodeTextContainer(new HamlLine("", HamlRuleEnum.PlainText, whiteSpace, -1)),
                                                  new HamlNodeTag(new HamlLine("p>", HamlRuleEnum.Tag, "", -1)));

            new HamlDocumentWalker(_mockClassBuilder).Walk(node);

            Assert.That(_mockClassBuilder.Build(""), Is.EqualTo("<p></p>"));
        }
Exemplo n.º 8
0
        public void Walk_TextNode_AppendsCorrectTag()
        {
            // Arrange
            var content  = new HamlLine("Simple content", HamlRuleEnum.PlainText, "", 0);
            var document = HamlDocumentBuilder.Create("",
                                                      new HamlNodeTextContainer(content));
            Type baseType = typeof(Template);

            // Act
            var builder = new ClassBuilderMock();

            new HamlDocumentWalker(builder).Walk(document, "", baseType, new List <string>());

            // Assert
            Assert.That(builder.Build(""), Is.EqualTo(content.Content));
        }
Exemplo n.º 9
0
        public void GetNextUnresolvedPartial_OneResolvedAndOneUnresolvedPartial_ReturnsCorrectPartial()
        {
            var resolvedPartial = new HamlNodePartial(new HamlLine("", HamlRuleEnum.Partial, "", -1));

            resolvedPartial.SetDocument(HamlDocumentBuilder.Create());

            var unresolvedPartial = new HamlNodePartial(new HamlLine("", HamlRuleEnum.Partial, "", -1));

            var rootNode = new HamlNodeDummy();

            rootNode.AddChild(resolvedPartial);
            rootNode.AddChild(unresolvedPartial);

            var result = rootNode.GetNextUnresolvedPartial();

            Assert.That(result, Is.EqualTo(unresolvedPartial));
        }
Exemplo n.º 10
0
        public void BuildHamlDocument_NoPartials_ReturnsSameDocument()
        {
            var viewSource   = ViewSourceBuilder.Create("Test");
            var hamlDocument = HamlDocumentBuilder.Create("MainFile",
                                                          new HamlNodeTextContainer(0, "Test"));

            _treeParserMock.Setup(x => x.ParseViewSource(viewSource))
            .Returns(hamlDocument);

            var viewSourceCollection = new ViewSourceCollection {
                viewSource
            };

            var result = _templateFactoryFactory.BuildHamlDocument(viewSourceCollection);

            Assert.That(result, Is.SameAs(hamlDocument));
            Assert.That(result.Children.First(), Is.SameAs(hamlDocument.Children.First()));
        }
Exemplo n.º 11
0
        public void CompileTemplateFactory_CallsDocumentWalker()
        {
            // Arrange
            const string className = "className";
            var          baseType  = typeof(Template);

            var fakeHamlDocument = HamlDocumentBuilder.Create("");

            _parserMock.Setup(x => x.ParseViewSource(It.IsAny <ViewSource>()))
            .Returns(fakeHamlDocument);
            var viewSource = ViewSourceBuilder.Create();
            var imports    = new List <string>();

            // Act
            var compiledTemplate = new TemplateFactoryFactory(_contentProviderMock.Object, _parserMock.Object,
                                                              _documentWalkerMock.Object, _compilerMock.Object, new List <string>(), imports);

            compiledTemplate.CompileTemplateFactory(className, new ViewSourceCollection {
                viewSource
            }, baseType);

            // Assert
            _documentWalkerMock.Verify(x => x.Walk(fakeHamlDocument, className, baseType, imports));
        }