Exemple #1
0
        public void SimpleIntegrationTest()
        {
            // Arrange
            const string templateContent = @"This is a test";
            var          viewSource      = ViewSourceBuilder.Create(templateContent);

            // Act
            var      templateFactory = _templateFactoryFactory.CompileTemplateFactory(viewSource.GetClassName(), viewSource);
            Template template        = templateFactory.CreateTemplate();
            var      textWriter      = new StringWriter();

            template.Render(textWriter);

            // Assert
            Assert.AreEqual("This is a test", textWriter.ToString());
        }
        public void CompileTemplateFactory_CallsTreeParser()
        {
            // Arrange
            var fakeHamlSource = ViewSourceBuilder.Create();

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

            compiledTemplate.CompileTemplateFactory("className", fakeHamlSource);

            // Assert
            _parserMock.Verify(x => x.ParseViewSource(fakeHamlSource));
        }
        public void CompileTemplateFactory_CallsCompile()
        {
            // Arrange
            var fakeTemplateSource = "FakeTemplateSource";

            _documentWalkerMock.Setup(x => x.Walk(It.IsAny <HamlDocument>(), It.IsAny <string>(),
                                                  It.IsAny <Type>(), It.IsAny <IList <string> >()))
            .Returns(fakeTemplateSource);
            var viewSource = ViewSourceBuilder.Create();
            var assemblies = new List <string>();

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

            compiledTemplate.CompileTemplateFactory(viewSource.GetClassName(), viewSource);

            // Assert
            _compilerMock.Verify(x => x.Compile(fakeTemplateSource, viewSource.GetClassName(), assemblies));
        }
        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));
        }