public void InMemoryString() { factory.TemporaryFile = null; ITemplate it = factory.Create("This is a test"); Context c = new Context(); Assert.AreEqual("This is a test", it.ToString(c)); }
public void OneArgVariable() { factory.TemporaryFile = new FileInfo("OneArgVariable.cs"); ITemplate t = factory.Create("This is a <%= Var1 %> test"); Context c = new Context(); c["var1"] = "valid"; Assert.AreEqual("This is a valid test", t.ToString(c)); }
public void NewlineString() { factory.TemporaryFile = new FileInfo("NewlineString.cs"); ITemplate it = factory.Create("This is\na test"); Context c = new Context(); Assert.AreEqual("This is" + Environment.NewLine + "a test", it.ToString(c)); }
/// <summary> /// Applies the template using the context, then returns the /// results as a string. /// </summary> public string ToString(Context context) { // Change the context StringWriter sw = new StringWriter(); Write(context, sw); sw.Close(); // Trim off the final \n (artifact of the process) string buffer = sw.ToString(); return buffer.Substring(0, buffer.Length -1); }
public void ReuseTest() { factory.TemporaryFile = new FileInfo("ReuseTest.cs"); ITemplate t = factory.Create("I am <%=Var1%>."); Context c1 = new Context(); c1["var1"] = "okay"; Assert.AreEqual("I am okay.", t.ToString(c1), "First context."); Context c2 = new Context(); c2["var1"] = "good"; Assert.AreEqual("I am good.", t.ToString(c2), "Second context."); }
public void TestVariable() { factory.TemporaryFile = new FileInfo("TestVariable.cs"); ITemplate t = factory.Create( "<%@ Variable Name=\"Var2\" Type=\"System.String\" %>" + "<%=Var2%>"); Context c1 = new Context(); c1["Var2"] = "yes"; Assert.AreEqual("yes", t.ToString(c1)); }
public void TestNamespace() { factory.TemporaryFile = new FileInfo("TestNamespace.cs"); ITemplate t = factory.Create( "<%@ Template Namespace=\"System.Collections\"%>" + "<%=typeof(ArrayList)%>"); Context c1 = new Context(); Assert.AreEqual("System.Collections.ArrayList", t.ToString(c1)); }
public void TestExternal60() { factory.TemporaryFile = new FileInfo("External.cs"); ITemplate t = factory.Create( "<%# private string Foo()\n" + " {\n" + " return \"bar\";\n" + " }\n" + "%>" + "<%=Foo()%>"); Context c1 = new Context(); Assert.AreEqual("bar", t.ToString(c1)); }
public void TestBug61b() { factory.TemporaryFile = new FileInfo("TestBug61b.cs"); ITemplate t = factory.Create ("<%= Foo() %><%#\n//Comment\n" + "string Foo() { return \"template\"; } %>"); Context c1 = new Context(); Assert.AreEqual("template", t.ToString(c1)); }
public void TestBug61a() { factory.TemporaryFile = new FileInfo("TestBug61a.cs"); ITemplate t = factory.Create ("<%\n//Comment\nVar1 = \"bob\";\n" + "// Comment\nVar1 = \"template\"; %><%=Var1%>"); Context c1 = new Context(); Assert.AreEqual("template", t.ToString(c1)); }
public void TestBug61() { factory.TemporaryFile = new FileInfo("TestBug61.cs"); ITemplate t = factory.Create("<%=\n//Comment\nVar1\n%>"); Context c1 = new Context(); c1["var1"] = "template"; Assert.AreEqual("template", t.ToString(c1)); }
public void TestBug60a() { factory.TemporaryFile = new FileInfo("TestBug60a.cs"); ITemplate t = factory.Create("<%\nVar1\n =\n \"inner\";\n%>" + "<%= Var1 %>"); Context c1 = new Context(); Assert.AreEqual("inner", t.ToString(c1)); }
public void StraightString() { factory.TemporaryFile = new FileInfo("StraightString.cs"); ITemplate it = factory.Create("This is a test"); Context c = new Context(); Assert.AreEqual("This is a test", it.ToString(c)); }
public void SimpleLoop() { factory.TemporaryFile = new FileInfo("SimpleLoop.cs"); ITemplate t = factory.Create("<% for (int i = 1; i < 6; i++) { %>" + "<%=i%> " + "<% }%>"); Context c = new Context(); Assert.AreEqual("1 2 3 4 5 ", t.ToString(c)); }
public void SimpleInclude2() { factory.TemporaryFile = new FileInfo("SimpleInclude.cs"); ITemplate t = factory.Create("<%= Include(\"inner\") %>" + "<% Var1 = \"second\"; %>" + "<%= Include(\"inner\") %>"); Context c1 = new Context(); c1["var1"] = "template"; Assert.AreEqual("inner(template)inner(second)", t.ToString(c1)); }
/// <summary> /// Writes out the template to a given stream. /// </summary> public void Write(Context context, TextWriter writer) { this.context = context; Write(writer); }