Esempio n. 1
0
        public void GetTemplateEngine_BasicHamlConfig_ReturnsTemplateEngine()
        {
            const string configFile = "Configuration/configWithReferencesAndImports.config";
            var          result     = XmlConfigurator.GetTemplateEngine(configFile);

            Assert.That(result, Is.InstanceOf <TemplateEngine>());
        }
Esempio n. 2
0
        public void GetTemplateEngine_NoNHamlConfigSpecified_ReturnsTemplateEngine()
        {
            const string configFile = "Configuration/NoNHaml.config";
            var          result     = XmlConfigurator.GetTemplateEngine(configFile);

            Assert.That(result, Is.InstanceOf <TemplateEngine>());
        }
Esempio n. 3
0
 public NHamlMvcViewEngine()
 {
     InitializeBaseViewLocations();
     _contentProvider = new MapPathTemplateContentProvider();
     _templateEngine  = XmlConfigurator.GetTemplateEngine(_contentProvider, GetDefaultUsings(), GetDefaultReferences());
     _templateEngine.TemplateContentProvider = _contentProvider;
     DefaultMaster = "Application";
 }
Esempio n. 4
0
        private Template CreateTemplate(string hamlTemplate)
        {
            var viewSource = ViewSourceBuilder.Create(hamlTemplate);

            var templateEngine   = XmlConfigurator.GetTemplateEngine(new FileTemplateContentProvider(), new List <string>(), new List <string>());
            var compiledTemplate = templateEngine.GetCompiledTemplate(viewSource, typeof(Template));

            return(compiledTemplate.CreateTemplate());
        }
Esempio n. 5
0
        public void GetTemplateEngine_AdditionalImportsAndReferencedAssemblies_ReturnsTemplateEngine()
        {
            var importsList          = new List <string>();
            var referencedAssemblies = new List <string>();
            var contentProviderMock  = new Mock <ITemplateContentProvider>();

            var result = XmlConfigurator.GetTemplateEngine(contentProviderMock.Object, importsList, referencedAssemblies);

            Assert.That(result, Is.InstanceOf <TemplateEngine>());
        }
Esempio n. 6
0
        public void GetTemplateEngine_BasicHamlConfig_ContainsExtraUsingStatement()
        {
            var viewSource      = ViewSourceBuilder.Create("= NHaml.IntegrationTests.XmlConfigurator_IntegrationTests.TestRenderMethod()");
            var templateEngine  = XmlConfigurator.GetTemplateEngine();
            var templateFactory = templateEngine.GetCompiledTemplate(viewSource, typeof(Template));
            var template        = templateFactory.CreateTemplate();
            var textWriter      = new StringWriter();

            template.Render(textWriter);
            Assert.That(textWriter.ToString(), Is.StringMatching("Test"));
        }
Esempio n. 7
0
        public void GetTemplateEngine_AdditionalUsingAndReferencedAssemblies_ContainsExtraUsingStatement()
        {
            var viewSource      = ViewSourceBuilder.Create("= new StringBuilder(\"Default\")");
            var contentProvider = new FileTemplateContentProvider();
            var importsList     = new List <string> {
                "System.Text"
            };
            var referencedAssembliesList = new List <string>();

            var templateEngine  = XmlConfigurator.GetTemplateEngine(contentProvider, importsList, referencedAssembliesList);
            var templateFactory = templateEngine.GetCompiledTemplate(viewSource, typeof(Template));
            var template        = templateFactory.CreateTemplate();
            var textWriter      = new StringWriter();

            template.Render(textWriter);
            Assert.That(textWriter.ToString(), Is.StringMatching("Default"));
        }
Esempio n. 8
0
        public void XmlConfigurator_TypedTemplate_CompilesValidTemplate()
        {
            // Arrange
            string templateContent = @"= Model.Date";
            var    viewSource      = ViewSourceBuilder.Create(templateContent);

            // Act
            var templateEngine          = XmlConfigurator.GetTemplateEngine();
            var compiledTemplateFactory = templateEngine.GetCompiledTemplate(viewSource, typeof(TypedTemplate <DateTime>));
            var template   = (TypedTemplate <DateTime>)compiledTemplateFactory.CreateTemplate();
            var textWriter = new StringWriter();

            template.Render(textWriter, DateTime.Now);

            // Assert
            Assert.AreEqual(DateTime.Today.ToString(), textWriter.ToString());
        }
Esempio n. 9
0
        public void XmlConfigurator_DefaultUsage_CompilesValidTemplate()
        {
            // Arrange
            string templateContent = @"This is a test";

            var viewSource = ViewSourceBuilder.Create(templateContent);

            // Act
            var      templateEngine          = XmlConfigurator.GetTemplateEngine();
            var      compiledTemplateFactory = templateEngine.GetCompiledTemplate(viewSource, typeof(Template));
            Template template   = compiledTemplateFactory.CreateTemplate();
            var      textWriter = new StringWriter();

            template.Render(textWriter);

            // Assert
            Assert.AreEqual("This is a test", textWriter.ToString());
        }
Esempio n. 10
0
        public void GetTemplateEngine_ReturnsTemplateEngine()
        {
            var result = XmlConfigurator.GetTemplateEngine();

            Assert.That(result, Is.InstanceOf <TemplateEngine>());
        }
Esempio n. 11
0
 public NHamlViewEngine()
     : this(XmlConfigurator.GetTemplateEngine())
 {
 }