public void AutoGeneratedNamespace() { const string CLASS_NAMESPACE = ""; const string BASE_CLASS_FULLNAME = "NFX.NUnit.Templatization.TeztTemplate"; string templateSrc = @" #<conf><compiler base-class-name=""{0}"" namespace=""{1}"" abstract=""true"" summary=""Test master page""/> #</conf>".Args(BASE_CLASS_FULLNAME, CLASS_NAMESPACE); TemplateStringContentSource src = new TemplateStringContentSource(templateSrc); TextCSTemplateCompiler compiler = new TextCSTemplateCompiler(src) { CompileCode = true }; compiler.ReferenceAssembly(NFX_NUNIT_DLL); compiler.Compile(); CompileUnit cu = compiler.First(); compiler.CodeCompilerErrors.ForEach(e => Console.WriteLine(e.ToMessageWithType())); Assert.IsNotNullOrEmpty(cu.CompiledTemplateType.Namespace); }
public void NotAbstract() { const string CLASS_NAMESPACE = "NFX.NUnit.Templatization"; const string BASE_CLASS_FULLNAME = "NFX.NUnit.Templatization.TeztTemplate"; string templateStr = @" #<conf><compiler base-class-name=""{0}"" namespace=""{1}"" abstract=""false"" summary=""Test master page""/> #</conf>".Args(BASE_CLASS_FULLNAME, CLASS_NAMESPACE); TemplateStringContentSource src = new TemplateStringContentSource(templateStr); TextCSTemplateCompiler compiler = new TextCSTemplateCompiler(src) { CompileCode = true }; compiler.ReferenceAssembly(NFX_NUNIT_DLL); compiler.Compile(); CompileUnit cu = compiler.First(); Assert.IsFalse(cu.CompiledTemplateType.IsAbstract); }
private TextCSTemplateCompiler GetCompilerForSimpleTemplateSrc(string classNamespace, string baseClassFullName, params string[] additionalReferences) { string templateSrc = @" #<conf><compiler base-class-name=""{0}"" namespace=""{1}"" abstract=""true"" summary=""Test master page""/> #</conf>".Args(baseClassFullName, classNamespace); TemplateStringContentSource src = new TemplateStringContentSource(templateSrc); TextCSTemplateCompiler compiler = new TextCSTemplateCompiler(src) { CompileCode = true }; additionalReferences.ForEach(a => compiler.ReferenceAssembly(a)); compiler.Compile(); return(compiler); }
public void MethodNames() { const string RENDER_HEADER = "renderHeader"; const string RENDER_FOOTER = "renderFooter"; const string RENDER_BODY = "renderBody"; const string TITLE = "Title"; string templateSrc = @" #<conf> <compiler base-class-name=""NFX.NUnit.Templatization.TeztTemplate"" namespace=""NFX.NUnit.Templatization"" abstract=""true"" summary=""Test master page"" /> #</conf> #[class] public string " + TITLE + @" { get {return ""aaaaa""; } } protected abstract void " + RENDER_HEADER + @"(); protected abstract void " + RENDER_BODY + @"(bool showDetails); protected abstract void " + RENDER_FOOTER + @"(); #[render] <html> <head> <title>?[Title]</title> </head> <body> <h1>This is Header</h1> @[renderHeader();] <h1>This is Body</h1> @[renderBody(true);] <p>This is in master page</p> <h1>This is Footer</h1> @[renderFooter();] </body> </html> "; TemplateStringContentSource src = new TemplateStringContentSource(templateSrc); TextCSTemplateCompiler compiler = new TextCSTemplateCompiler(src) { CompileCode = true }; compiler.ReferenceAssembly(NFX_NUNIT_DLL); compiler.Compile(); CompileUnit cu = compiler.First(); Type compiledType = cu.CompiledTemplateType; Assert.IsNotNull(compiledType.GetMethod(RENDER_HEADER, BindingFlags.NonPublic | BindingFlags.Instance)); Assert.IsNotNull(compiledType.GetMethod(RENDER_FOOTER, BindingFlags.NonPublic | BindingFlags.Instance)); MethodInfo methodBody = compiledType.GetMethod(RENDER_BODY, BindingFlags.NonPublic | BindingFlags.Instance, Type.DefaultBinder, new[] { typeof(bool) }, null); Assert.IsNotNull(compiledType.GetProperty(TITLE, BindingFlags.Public | BindingFlags.Instance)); }