grumpydev / SuperSimpleViewEngine

Super simple regex based view engine used in Nancy diagnostics and (soon to be) TinyTemplates.
36 stars 9 forks source link

Context Conditional not working in Nancy #4

Open thecopy opened 11 years ago

thecopy commented 11 years ago

This SSVE markup:

@Context.ViewBag.HaveMessage;<br />
@If.Context.ViewBag.HaveMessage;
    Yay Message!
@EndIf;

Produces in Nancy:

True

Produces in SSVE test:

True
Yay Message!
[Fact]
public void Should_evaluate_context_conditional()
{
    const string input = @"@Context.ViewBag.HaveMessage;! @If.Context.ViewBag.HaveMessage;Yay message!@EndIf;";
    var context = new { ViewBag = (dynamic)new ExpandoObject() };
    context.ViewBag.HaveMessage = true;

    ((FakeViewEngineHost)this.fakeHost).Context = context;

    var output = viewEngine.Render(input, null, this.fakeHost);

    Assert.Equal(@"True! Yay message!", output);
}
thecopy commented 11 years ago

By referencing Nancy and in the test using

var context = new { ViewBag = (dynamic) new DynamicDictionary() };

Makes it behave like Nancy