Example #1
0
        public void GetOrAdd_NewTemplate_AddsTemplateToCache()
        {
            string fileName = "test.haml";
            var    cache    = new SimpleTemplateCache();

            cache.GetOrAdd(fileName, DateTime.Now, () => new TemplateFactory(typeof(DummyTemplate)));
            Assert.That(cache.ContainsTemplate(fileName), Is.True);
        }
Example #2
0
        private static TemplateEngine GetTemplateEngine(ITemplateContentProvider templateContentProvider, NHamlConfigurationSection nhamlConfiguration, IEnumerable<string> imports, IEnumerable<string> referencedAssemblies)
        {
            var templateCache = new SimpleTemplateCache();

            var templateFactoryFactory = new TemplateFactoryFactory(
                templateContentProvider,
                new HamlTreeParser(new HamlFileLexer()),
                new HamlDocumentWalker(new CodeDomClassBuilder()),
                new CodeDomTemplateCompiler(new CSharp2TemplateTypeBuilder()),
                nhamlConfiguration.ImportsList.Concat(imports),
                nhamlConfiguration.ReferencedAssembliesList.Concat(referencedAssemblies));

            return new TemplateEngine(templateCache, templateFactoryFactory);
        }
Example #3
0
        private static TemplateEngine GetTemplateEngine(ITemplateContentProvider templateContentProvider, NHamlConfigurationSection nhamlConfiguration, IEnumerable <string> imports, IEnumerable <string> referencedAssemblies)
        {
            var templateCache = new SimpleTemplateCache();

            var templateFactoryFactory = new TemplateFactoryFactory(
                templateContentProvider,
                new HamlTreeParser(new HamlFileLexer()),
                new HamlDocumentWalker(new CodeDomClassBuilder()),
                new CodeDomTemplateCompiler(new CSharp2TemplateTypeBuilder()),
                nhamlConfiguration.ImportsList.Concat(imports),
                nhamlConfiguration.ReferencedAssembliesList.Concat(referencedAssemblies));

            return(new TemplateEngine(templateCache, templateFactoryFactory));
        }
Example #4
0
        public void GetOrAdd_DifferentTemplateAddedTwice_CreatesTemplateTwice()
        {
            string fileName = "test2.haml";
            int    count    = 0;
            var    cache    = new SimpleTemplateCache();

            for (int c = 0; c < 2; c++)
            {
                cache.GetOrAdd(fileName, DateTime.Now.AddDays(c), () =>
                {
                    count++;
                    return(new TemplateFactory(typeof(DummyTemplate)));
                });
            }

            Assert.That(count, Is.EqualTo(2));
        }
Example #5
0
        public void GetOrAdd_SameTemplateAddedTwice_CreatesTemplateOnce()
        {
            string fileName  = "test1.haml";
            int    count     = 0;
            var    timeStamp = new DateTime(2012, 1, 1);
            var    cache     = new SimpleTemplateCache();

            for (int c = 0; c < 2; c++)
            {
                cache.GetOrAdd(fileName, timeStamp, () =>
                {
                    count++;
                    return(new TemplateFactory(typeof(DummyTemplate)));
                });
            }

            Assert.That(count, Is.EqualTo(1));
        }