Exemplo n.º 1
0
        public void CompilationRenderer_ItShouldAllowMultipleTruthyChecks(string fooValue, string result)
        {
            var builder = new CompilerSettingsBuilder();

            builder.AddTruthyCheck <string>(val => !val.Equals("Bar"));
            builder.AddTruthyCheck <string>(val => !val.Equals("Boo"));

            var stubble = new StubbleCompilationRenderer(builder.BuildSettings());

            var obj = new
            {
                Foo = "Bar",
                Bar = "Display Me"
            };

            var func = stubble.Compile("{{#Foo}}{{Bar}}{{/Foo}}", obj);

            var renderResult = func(new
            {
                Foo = fooValue,
                Bar = "Hello World"
            });

            Assert.Equal(result, renderResult);
        }
Exemplo n.º 2
0
        public void CompilationRenderer_ItShouldAllowMultipleTruthyChecks()
        {
            var builder = new CompilerSettingsBuilder();

            builder.AddTruthyCheck <string>(val => !val.Equals("Bar"));
            builder.AddTruthyCheck <string>(val => !val.Equals("Boo"));

            var stubble = new StubbleCompilationRenderer(builder.BuildSettings());

            var obj = new
            {
                Foo = "Bar",
                Bar = "Display Me"
            };

            var func = stubble.Compile("{{#Foo}}{{Bar}}{{/Foo}}", obj);

            Assert.Equal("", func(obj));
            Assert.Equal("", func(new
            {
                Foo = "Boo",
                Bar = "Display Me"
            }));

            Assert.Equal("", func(new
            {
                Foo = "false",
                Bar = "Display Me"
            }));

            Assert.Equal("", func(new
            {
                Foo = (string)null,
                Bar = "Display Me"
            }));
        }
Exemplo n.º 3
0
        public void It_Can_Use_Truthy_Checks(uint fooValue, string expectedResult)
        {
            var builder = new CompilerSettingsBuilder();

            builder.AddTruthyCheck <uint>(val => val > 0);

            var stubble = new StubbleCompilationRenderer(builder.BuildSettings());

            var obj = new
            {
                Foo = fooValue,
                Bar = "Bar"
            };

            var func = stubble.Compile("{{#Foo}}{{Bar}}{{/Foo}}", obj);

            Assert.Equal(expectedResult, func(obj));
        }
Exemplo n.º 4
0
        public void It_Can_Use_Truthy_Checks()
        {
            var builder = new CompilerSettingsBuilder();

            builder.AddTruthyCheck <uint>(val => val > 0);

            var stubble = new StubbleCompilationRenderer(builder.BuildSettings());

            var obj = new
            {
                Foo = (uint)10,
                Bar = "Bar"
            };

            var func = stubble.Compile("{{#Foo}}{{Bar}}{{/Foo}}", obj);

            Assert.Equal("Bar", func(obj));
            Assert.Equal("", func(new
            {
                Foo = (uint)0,
                Bar = "Boo"
            }));
        }