public void It_Should_Loop_Dictionary_When_Allowed() { var stubble = new StubbleCompilationBuilder() .Configure(conf => { conf.SetSectionBlacklistTypes(new HashSet <Type> { typeof(string) }); }) .Build(); var obj = new { Dict = new Dictionary <string, string> { { "key1", "value1" }, { "key2", "value2" }, { "key3", "value3" }, } }; var func = stubble.Compile("{{#Dict}}{{Key}}|{{Value}}.{{/Dict}}", obj); Assert.Equal("key1|value1.key2|value2.key3|value3.", func(obj)); }
public void It_Can_Override_Encoding_Function() { Expression <Func <string, string> > encodingFunc = (str) => str; var stubbleBuilder = new StubbleCompilationBuilder() .Configure(settings => settings.SetEncodingFunction(encodingFunc)) .Build(); }
public void You_Should_Be_Able_To_Build_Using_Builder() { var builder = new StubbleCompilationBuilder(); builder.Configure(b => b.SetIgnoreCaseOnKeyLookup(true)); var stubble = builder.Build(); var input = new { Foo = "Bar" }; var func = stubble.Compile("{{Foo}}", input); Assert.Equal("Bar", func(input)); }
public void It_Should_Throw_When_Ambiguous_Match() { var stubble = new StubbleCompilationBuilder() .Configure(settings => { settings.SetIgnoreCaseOnKeyLookup(true); }) .Build(); var ex = Assert.Throws <StubbleAmbigousMatchException>(() => stubble.Compile("{{name}}", new { Name = "foo", name = "bar" })); Assert.Equal("Ambiguous match found when looking up key: 'name'", ex.Message); }
public async Task It_Should_Skip_Html_Encoding_With_Setting_Async() { var stubble = new StubbleCompilationBuilder() .Build(); var obj = new { Html = "<b>Html</b>" }; var func = await stubble.CompileAsync("{{Html}}\n{{{Html}}}", obj, new CompilationSettings { SkipHtmlEncoding = true }); Assert.Equal("<b>Html</b>\n<b>Html</b>", func(obj)); }
public void It_Can_Retrieve_Values_From_Dynamic_As_Interface(string template, string result) { dynamic input = new InterfaceOnlyDynamicTestFixture(); input.Foo = "Bar"; input.Number = 1; input.Blah = new { String = "Test" }; var stubble = new StubbleCompilationBuilder() .Build(); Func <InterfaceOnlyDynamicTestFixture, string> func = stubble.Compile(template, input); var renderResult = func(input); Assert.Equal(result, renderResult); }
public async Task Unknown_Exceptions_Are_Thrown() { var partials = new Dictionary <string, string> { { "Partial", "{{Foo}}" } }; var stubble = new StubbleCompilationBuilder() .Configure(configure => { configure.SetTemplateLoader(new DictionaryLoader(partials)); }) .Build(); var input = new ExampleClass { Foo = "Bar" }; Assert.Throws <UnknownTemplateException>(() => stubble.Compile("MissingPartial", input)); await Assert.ThrowsAsync <UnknownTemplateException>(async() => await stubble.CompileAsync("MissingPartial", input)); }
public void It_Should_Throw_Exception_On_Dynamic_IgnoreCase() { dynamic input = new InterfaceOnlyDynamicTestFixture(); input.Foo = "Bar"; input.Number = 1; input.Blah = new { String = "Test" }; var stubble = new StubbleCompilationBuilder() .Configure(settings => { settings.SetIgnoreCaseOnKeyLookup(true); }) .Build(); var ex = Assert.Throws <StubbleException>(() => stubble.Compile("{{Foo}}", input)); Assert.Equal("Dynamic value lookup cannot ignore case", ex.Message); }