Пример #1
0
 public void ConfigIsLoadedFromFile()
 {
     var config = new RazorConfig();
     Assert.IsFalse(config.Templates.IncludeGeneratedSourceCode);
     config.Initializer.InitializeByXmlFileName("Xipton.Razor.UnitTest.dll.config");
     Assert.IsTrue(config.Templates.IncludeGeneratedSourceCode);
 }
Пример #2
0
 public void ConfigIsLoadedFromConfig()
 {
     var config = new RazorConfig();
     Assert.IsFalse(config.Templates.IncludeGeneratedSourceCode);
     config.Initializer.TryInitializeFromConfig();
     Assert.IsTrue(config.Templates.IncludeGeneratedSourceCode);
 }
Пример #3
0
 public void ConfigCanBeCreated()
 {
     var config = new RazorConfig();
     Assert.IsNotNull(config.ContentProviders);
     Assert.IsNotNull(config.Namespaces);
     Assert.IsNotNull(config.References);
     Assert.IsNotNull(config.RootOperator);
     Assert.IsNotNull(config.Templates);
 }
Пример #4
0
 public void ConfigCanBeCreatedWithoutWildcards()
 {
     var config = new RazorConfig(false);
     Assert.IsNotNull(config.ContentProviders);
     Assert.IsNotNull(config.Namespaces);
     Assert.IsNotNull(config.References);
     Assert.IsNotNull(config.RootOperator);
     Assert.IsNotNull(config.Templates);
     Assert.IsFalse(config.References.Any(r => r.Contains("*")));
 }
Пример #5
0
 public void ConfigIsLoadedFromXml()
 {
     var config = new RazorConfig();
     config.Initializer.InitializeByXmlContent(
         @"
     <xipton.razor>
     <rootOperator path=""/foo"" />
     </xipton.razor>
     "
         );
     Assert.AreEqual(config.RootOperator.Path, "/foo");
 }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XiptonEngineHost"/> class.
        /// </summary>
        /// <param name="config">The config holds all settings that are needed to initialzie the host.</param>
        public XiptonEngineHost(RazorConfig config)
            : base(config.Templates.Language)
        {
            if (config == null) throw new ArgumentNullException("config");
            _defaultNamespace = "Xipton.Razor.Generated";
            _config = config.AsReadonly();
            _defaultBaseClass = _config.Templates.NonGenericBaseTypeName;
            _namespaceImports = new HashSet<string>();
            _config.Namespaces.ToList().ForEach(ns => _namespaceImports.Add(ns));

            // the GeneratedClassContext defines the methods that are generated to handle the template
            // control like writing the generated output and also handle other control operations like
            // defining sections inside the template
            _generatedClassContext = new GeneratedClassContext("Execute", "Write", "WriteLiteral", "WriteTo", "WriteLiteralTo", typeof(HelperResult).FullName, "DefineSection") {
                ResolveUrlMethodName = "ResolveUrl",
            };
        }
Пример #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RazorContext"/> class.
 /// </summary>
 public RazorContext(RazorConfig config = null)
 {
     Config = (config ?? new RazorConfig().Initializer.TryInitializeFromConfig().CastTo<RazorConfig>()).AsReadonly();
     TemplateFactory = new TemplateFactory(this);
 }
Пример #8
0
 public RazorMachine(RazorConfig config)
 {
     Context = new RazorContext(config ?? new RazorConfig().Initializer.TryInitializeFromConfig().AsReadOnly());
 }
Пример #9
0
 public void ConfigIsLoadedFromValues()
 {
     var config = new RazorConfig();
     config.Initializer.InitializeByValues(defaultExtension: ".vb");
     Assert.AreEqual(config.Templates.DefaultExtension,".vb");
 }