public void ViewEngine_Dynamic_SingleSubstitutions() { //strings and simple types MakeSure.That(ViewEngine.Instance.Render("Hello @Model", "World")).Is("Hello World"); MakeSure.That(ViewEngine.Instance.Render("Hello @Model", 1)).Is("Hello 1"); MakeSure.That(ViewEngine.Instance.Render("Hello @Model", DateTime.Now.ToShortTimeString())).Is("Hello {0}".With(DateTime.Now.ToShortTimeString())); dynamic basic = new ExpandoObject(); basic.Name = "World"; dynamic extended = new ExpandoObject(); extended.Data = new ExpandoObject(); extended.Data = "World"; var real = new SampleModel { Age = 38, Title = "Model", Type = ModelType.Example }; //object MakeSure.That(ViewEngine.Instance.Render("Hello @Model.Data", extended)).Is("Hello World"); MakeSure.That(ViewEngine.Instance.Render("Hello @Model.Age", real)).Is("Hello 38"); MakeSure.That(ViewEngine.Instance.Render("Hello @Model.Type", real)).Is("Hello Example"); //extensions var renderable = new RenderableModel { Title = "Cool" }; MakeSure.That(renderable.Render("Hello @Model.Title")).Is("Hello Cool"); MakeSure.That("Hello @Model.Title".RenderWith(renderable)).Is("Hello Cool"); }
public void ViewEngine_Dynamic_Conditionals() { var m1 = new RenderableModel { HasUsers = true, HasAdmins = false, Title = "Cool" }; MakeSure.That(m1.Render("@If.HasUsers @Model.Title @EndIf @IfNot.HasAdmins no admins! @EndIf")).Is("Cool no admins!"); }