protected string ExecuteTemplate <T>(SyntaxTreeNode syntaxTree, T model) { var template = new VeilTemplateCompiler <T>(GetTemplateByName).Compile(syntaxTree); using (var writer = new StringWriter()) { template(writer, model); return(writer.ToString()); } }
public void Should_flush_textwriter() { var template = SyntaxTree.Block( SyntaxTree.WriteString("Start"), SyntaxTree.Flush(), SyntaxTree.WriteString("End") ); var compiledTemplate = new VeilTemplateCompiler <object>(this.GetTemplateByName).Compile(template); var writer = A.Fake <TextWriter>(); compiledTemplate(writer, new object()); A.CallTo(() => writer.Write("Start")).MustHaveHappened() .Then(A.CallTo(() => writer.Flush()).MustHaveHappened()) .Then(A.CallTo(() => writer.Write("End")).MustHaveHappened()); }
public void Should_flush_textwriter() { var template = SyntaxTree.Block( SyntaxTree.WriteString("Start"), SyntaxTree.Flush(), SyntaxTree.WriteString("End") ); var compiledTemplate = new VeilTemplateCompiler<object>(this.GetTemplateByName).Compile(template); using (var scope = Fake.CreateScope()) { var writer = A.Fake<TextWriter>(); compiledTemplate(writer, new object()); using (scope.OrderedAssertions()) { A.CallTo(() => writer.Write("Start")).MustHaveHappened(); A.CallTo(() => writer.Flush()).MustHaveHappened(); A.CallTo(() => writer.Write("End")).MustHaveHappened(); } } }
public void Should_flush_textwriter() { var template = SyntaxTree.Block( SyntaxTree.WriteString("Start"), SyntaxTree.Flush(), SyntaxTree.WriteString("End") ); var compiledTemplate = new VeilTemplateCompiler <object>(this.GetTemplateByName).Compile(template); using (var scope = Fake.CreateScope()) { var writer = A.Fake <TextWriter>(); compiledTemplate(writer, new object()); using (scope.OrderedAssertions()) { A.CallTo(() => writer.Write("Start")).MustHaveHappened(); A.CallTo(() => writer.Flush()).MustHaveHappened(); A.CallTo(() => writer.Write("End")).MustHaveHappened(); } } }