Exemplo n.º 1
0
        public async Task ShouldNotReleaseScopeAsynchronously()
        {
            var parser = new FluidParser();

            parser.RegisterEmptyBlock("sleep", async(statements, writer, encoder, context) =>
            {
                context.EnterChildScope();
                context.IncrementSteps();
                context.SetValue("id", "0");
                await Task.Delay(100);
                await statements.RenderStatementsAsync(writer, encoder, context);
                context.ReleaseScope();
                return(Completion.Normal);
            });

            var context = new TemplateContext {
            };

            context.SetValue("id", "1");
            var template = parser.Parse(@"{{id}}{%sleep%}{{id}}{%endsleep%}{{id}}");

            var output = await template.RenderAsync(context);

            Assert.Equal("101", output);
        }