예제 #1
0
        public override TimeSpan RunTest(int iterations)
        {
            var stopwatch = Stopwatch.StartNew();
            var stubble = new StubbleRenderer();

            for (var i = 0; i < iterations; i++)
            {
                var testCase = GetRenderTestCase(i);
                stubble.Render(testCase.Key, testCase.Value);
            }
            stopwatch.Stop();

            return stopwatch.Elapsed;
        }
예제 #2
0
        public void It_Can_Pass_Spec_Tests(SpecTest data)
        {
            var stubble = new StubbleRenderer();
            var output = data.Partials != null ? stubble.Render(data.Template, data.Data, data.Partials) : stubble.Render(data.Template, data.Data);

            OutputStream.WriteLine("Expected \"{0}\", Actual \"{1}\"", data.Expected, output);
            var dic = stubble.Writer.Cache as IDictionary;
            Assert.Equal(data.Expected, output);
        }
예제 #3
0
 public void It_Can_Render_With_LambdaSection_Dynamic()
 {
     var stubble = new StubbleRenderer();
     var output = stubble.Render("{{#Foo}}Foo{{/Foo}}", new
     {
         BarValue = "Bar",
         Foo = new Func<dynamic, string, object>((context, str) => str + " " + context.BarValue)
     });
     Assert.Equal("Foo Bar", output);
 }
예제 #4
0
 public void It_Can_Render_With_LambdaSection_NoDynamic()
 {
     var stubble = new StubbleRenderer();
     var output = stubble.Render("{{#Foo}}Foo{{/Foo}}", new { Foo = new Func<string, object>((str) => str + " Bar") });
     Assert.Equal("Foo Bar", output);
 }
예제 #5
0
 public void It_Can_Render_WithoutPartials()
 {
     var stubble = new StubbleRenderer();
     var output = stubble.Render("{{Foo}}", new { Foo = "Bar" });
     Assert.Equal("Bar", output);
 }
예제 #6
0
 public void It_Can_Render_WithPartials()
 {
     var stubble = new StubbleRenderer();
     var output = stubble.Render("{{> inner}}", new { Foo = "Bar" }, new Dictionary<string, string> { { "inner", "{{Foo}}" } });
     Assert.Equal("Bar", output);
 }
예제 #7
0
        public void It_Should_Error_After_N_Recursions()
        {
            const string rowTemplate = @"
            <div class='row'>
                {{#content}}
                    {{#is_column}}
                        {{>column}}
                    {{/is_column}}
                {{/content}}
            </div>";

            const string columnTemplate = @"
            <div class='column'>
                {{#content}}
                    {{#is_text}}
                        {{>text}}
                    {{/is_text}}
                    {{#is_row}}
                        {{>row}}
                    {{/is_row}}
                {{/content}}
            </div>";

            const string textTemplate = @"
            <span class='text'>
                {{text}}
            </span>";

            var treeData = new
            {
                is_row = true,
                content = new
                {
                    is_column = true,
                    content = new[]
                    {
                        new
                        {
                            is_text = true,
                            text = "Hello World!"
                        }
                    }
                }
            };

            var stubble = new StubbleRenderer();
            var ex =
                Assert.Throws<StubbleException>(() => stubble.Render(rowTemplate, treeData, new Dictionary<string, string>
                {
                    {"row", rowTemplate},
                    {"column", columnTemplate},
                    {"text", textTemplate}
                }));

            Assert.Equal("You have reached the maximum recursion limit of 256.", ex.Message);
        }
예제 #8
0
 public void It_Can_Render_WithoutData()
 {
     var stubble = new StubbleRenderer();
     var output = stubble.Render("I Have No Data :(", null);
     Assert.Equal("I Have No Data :(", output);
 }
예제 #9
0
 public void It_Should_Be_Able_To_Take_Partials_And_Render_Settings()
 {
     var stubble = new StubbleRenderer();
     var output = stubble.Render("{{FooValue}} {{#Foo}}{{> FooBar}}{{/Foo}}", new
     {
         FooValue = "Foo",
         Foo = new
         {
             BarValue = "Bar"
         }
     }, new Dictionary<string, string>
     {
         { "FooBar", "{{FooValue}}{{BarValue}}" }
     }, new RenderSettings { SkipRecursiveLookup = true });
     Assert.Equal("Foo Bar", output);
 }
예제 #10
0
 public void It_Should_Be_Able_To_Skip_Recursive_Lookups()
 {
     var stubble = new StubbleRenderer();
     var output = stubble.Render("{{FooValue}} {{#Foo}}{{FooValue}}{{BarValue}}{{/Foo}}", new
     {
         FooValue = "Foo",
         Foo = new {
             BarValue = "Bar"
         }
     }, new RenderSettings { SkipRecursiveLookup = true });
     Assert.Equal("Foo Bar", output);
 }
예제 #11
0
 public void It_Doesnt_Error_When_Partial_Is_Used_But_None_Are_Given()
 {
     var stubble = new StubbleRenderer();
     var output = stubble.Render("{{> inner}}", new { Foo = "Bar" });
     Assert.Equal("", output);
 }
예제 #12
0
 public void It_Can_Render_With_LambdaToken_NoDynamic()
 {
     var stubble = new StubbleRenderer();
     var output = stubble.Render("{{Foo}}", new { Foo = new Func<object>(() => "Bar") });
     Assert.Equal("Bar", output);
 }
예제 #13
0
 public void It_Can_Render_With_LambdaToken_Dynamic()
 {
     var stubble = new StubbleRenderer();
     var output = stubble.Render("{{Foo}}", new { BarValue = "Bar", Foo = new Func<dynamic, object>((context) => context.BarValue) });
     Assert.Equal("Bar", output);
 }