예제 #1
0
        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());
            }
        }
예제 #2
0
        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());
        }
예제 #3
0
        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();
                }
            }
        }
예제 #4
0
        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();
                }
            }
        }