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 void It_Can_Retrieve_Values_From_Dynamic_As_Interface() { dynamic input = new InterfaceOnlyDynamicTestFixture(); input.Foo = "Bar"; input.Number = 1; input.Blah = new { String = "Test" }; var context = new Context(input, new RendererSettingsBuilder().BuildSettings(), RenderSettings.GetDefaultRenderSettings()); var output = context.Lookup("Foo"); var output2 = context.Lookup("Number"); var output3 = context.Lookup("Blah.String"); var output4 = context.Lookup("NonexistantProperty"); Assert.Equal("Bar", output); Assert.Equal(1, output2); Assert.Equal("Test", output3); Assert.Null(output4); }
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); }