using System.IO; using System.Threading.Tasks; using Util.Generators.Contexts; using Util.Helpers; using Util.Templates; using Xunit; namespace Util.Generators.Razor.Tests.Integration { /// /// Razor模板测试 /// public class RazorTemplateTest { /// /// 模板引擎 /// private readonly ITemplateEngine _templateEngine; /// /// 测试初始化 /// public RazorTemplateTest( ITemplateEngine templateEngine ) { _templateEngine = templateEngine; } /// /// 测试渲染模板 /// [Fact] public async Task TestRender() { var path = Common.GetPhysicalPath( "Templates/Test1/Template.cshtml" ); var template = new RazorTemplate( _templateEngine, new FileInfo( path ) ); var generatorContext = new GeneratorContext { TemplateRootPath = Common.GetPhysicalPath( "~/Templates" ), OutputRootPath = Common.GetPhysicalPath( "~/Output" ) }; var projectContext = new ProjectContext( generatorContext ) { Name = "test" }; var entityContext = new EntityContext( projectContext, "Hello" ); var result = await template.RenderAsync( entityContext ); Assert.Equal( "Hello,World", result ); Assert.Equal( "Test1", entityContext.Output.RelativeRootPath ); } } }