public bool InvokeTest() { //testing string variable Template tp = new Template("This is my string: $mystring$"); tp.SetParameter("mystring", "Hello world"); if (tp.ToString() != "This is my string: Hello world") { Console.WriteLine("Basic string test failed with results: "+tp.ToString()); return false; } //testing string array tp = new Template("This is my string array: $mystringarray$"); tp.SetParameter("mystringarray", new string[] { "Bob", "Lob", "Law" }); if (tp.ToString() != "This is my string array: BobLobLaw") { Console.WriteLine("Basic string array test failed with results: " + tp.ToString()); return false; } //testing List<string> object tp.ClearParameters(); tp.SetParameter("mystringarray", new List<string>(new string[] { "Bob", "Lob", "Law" })); if (tp.ToString() != "This is my string array: BobLobLaw") { Console.WriteLine("Basic List<string> array test failed with results: " + tp.ToString()); return false; } //testing Hashtable object tp = new Template("This is my hashtable: $myhashtable$"); Hashtable ht = new Hashtable(); ht.Add("FirstName", "Bob"); ht.Add("LastName", "LobLaw"); tp.SetParameter("myhashtable", ht); if (tp.ToString() != "This is my hashtable: LastName-->LobLaw, FirstName-->Bob") { Console.WriteLine("Basic hashtable test failed with results: " + tp.ToString()); return false; } //testing Dictionary object tp = new Template("This is my dictionary: $mydictionary$"); Dictionary<string, string> dc = new Dictionary<string, string>(); dc.Add("FirstName", "Bob"); dc.Add("LastName", "LobLaw"); tp.SetParameter("mydictionary",dc); if (tp.ToString() != "This is my dictionary: FirstName-->Bob, LastName-->LobLaw") { Console.WriteLine("Basic Dictionary test failed with results: " + tp.ToString()); return false; } //testing Complex Dictionary tp = new Template("This is the subelement $mydictionary.name1.FirstName$"); Dictionary<string, Dictionary<string, string>> cdc = new Dictionary<string, Dictionary<string, string>>(); cdc.Add("name1", dc); tp.SetAttribute("mydictionary", cdc); if (tp.ToString() != "This is the subelement Bob") { Console.Write("Complex Dictionary test failed with results: " + tp.ToString()); return false; } //testing Complex Class Dictionary tp = new Template("This is the subelement $myteir.Child.Name$"); tp.SetAttribute("myteir", new teir1(new teir2("Bob"))); if (tp.ToString() != "This is the subelement Bob") { Console.Write("Complex Dictionary test failed with results: " + tp.ToString()); return false; } //testing access to single dictionary object tp = new Template("This is my dictionaries first name value: $mydictionary.FirstName$"); tp.SetParameter("mydictionary", dc); if (tp.ToString() != "This is my dictionaries first name value: Bob") { Console.WriteLine("Basic Dictionary accessing single value test failed with results: " + tp.ToString()); return false; } //testing escape character tp = new Template("This is my escape character test worth \\$$money$"); tp.SetParameter("money", 1000); if (tp.ToString() != "This is my escape character test worth $1000") { Console.WriteLine("Basic escape character test failed with results: " + tp.ToString()); return false; } //testing accessing a class object within a dictionary tp = new Template("This is my last name value: $mydictionary.FirstPerson.Name$"); Dictionary<string, teir2> mydc = new Dictionary<string, teir2>(); mydc.Add("FirstPerson", new teir2("LobLaw")); tp.SetAttribute("mydictionary", mydc); if (tp.ToString() != "This is my last name value: LobLaw") { Console.WriteLine("Complex access to object property from within dictionary failed with results: " + tp.ToString()); return false; } return true; }
public bool InvokeTest() { //test non parametered call Template tp = new Template("$bob:CreateJavascriptElem()$",Program.TestGroup); tp.SetParameter("bob", "Hello World"); if (tp.ToString() != "'Hello World'") { Console.WriteLine("The basic template group code test failed with results: " + tp.ToString()); return false; } //test parametered call by defining variables in full tp = new Template("$GenerateLargeForm(content=con,id=ID,title=TITLE,OnClose=Clos,OnMinimize=Min,scriptID=SCID)$", Program.TestGroup); tp.SetParameter("con", "TEST CONTENT"); tp.SetParameter("TITLE", "TESTING"); tp.SetParameter("SCID", "'test'"); tp.SetParameter("ID", "test"); if (tp.ToString() != "<div id=\"test\" onBlur=\"UnHighlightTaskBar('test');\" class=\"Form transparent\" style=\"max-width:800px;max-height:600px;\"><div class=\"tl\"><div class=\"tr\"><div class=\"ControlButtons\"><img src=\"./FormParts/minimize.png\" alt=\"minimize\" onclick=\"MinimizeForm('test');\"><img src=\"./FormParts/cancel.png\" alt=\"close\" onclick=\"CloseForm('test');\"></div></div><div class=\"top\" id=\"test_top\"><center>TESTING</center></div></div><div class=\"left\"><div class=\"right\"><div style=\"overflow:auto;max-width:794px;max-height:552px;background-color:White;padding:5px;color:Black;\">TEST CONTENT</div></div></div><div class=\"bl\"><div class=\"br\"></div><div class=\"bottom\"><div class=\"status\"><div id=\"test_status\" class=\"statusContainer\"></div></div><div style=\"clear:right;\"></div></div></div></div>") { Console.WriteLine("The basic template group code test failed with results: " + tp.ToString()); return false; } //test parametered call without defining variables in full tp = new Template("$GenerateLargeForm(con,ID,TITLE,Clos,Min,SCID)$", Program.TestGroup); tp.SetParameter("con", "TEST CONTENT"); tp.SetParameter("TITLE", "TESTING"); tp.SetParameter("SCID", "'test'"); tp.SetParameter("ID", "test"); if (tp.ToString() != "<div id=\"test\" onBlur=\"UnHighlightTaskBar('test');\" class=\"Form transparent\" style=\"max-width:800px;max-height:600px;\"><div class=\"tl\"><div class=\"tr\"><div class=\"ControlButtons\"><img src=\"./FormParts/minimize.png\" alt=\"minimize\" onclick=\"MinimizeForm('test');\"><img src=\"./FormParts/cancel.png\" alt=\"close\" onclick=\"CloseForm('test');\"></div></div><div class=\"top\" id=\"test_top\"><center>TESTING</center></div></div><div class=\"left\"><div class=\"right\"><div style=\"overflow:auto;max-width:794px;max-height:552px;background-color:White;padding:5px;color:Black;\">TEST CONTENT</div></div></div><div class=\"bl\"><div class=\"br\"></div><div class=\"bottom\"><div class=\"status\"><div id=\"test_status\" class=\"statusContainer\"></div></div><div style=\"clear:right;\"></div></div></div></div>") { Console.WriteLine("The basic template group code test failed with results: " + tp.ToString()); return false; } //test parametered call without defining variables in full and specifying group prefix tp = new Template("$skin/GenerateLargeForm(con,ID,TITLE,Clos,Min,SCID)$", Program.TestGroup); tp.SetParameter("con", "TEST CONTENT"); tp.SetParameter("TITLE", "TESTING"); tp.SetParameter("SCID", "'test'"); tp.SetParameter("ID", "test"); if (tp.ToString() != "<div id=\"test\" onBlur=\"UnHighlightTaskBar('test');\" class=\"Form transparent\" style=\"max-width:800px;max-height:600px;\"><div class=\"tl\"><div class=\"tr\"><div class=\"ControlButtons\"><img src=\"./FormParts/minimize.png\" alt=\"minimize\" onclick=\"MinimizeForm('test');\"><img src=\"./FormParts/cancel.png\" alt=\"close\" onclick=\"CloseForm('test');\"></div></div><div class=\"top\" id=\"test_top\"><center>TESTING</center></div></div><div class=\"left\"><div class=\"right\"><div style=\"overflow:auto;max-width:794px;max-height:552px;background-color:White;padding:5px;color:Black;\">TEST CONTENT</div></div></div><div class=\"bl\"><div class=\"br\"></div><div class=\"bottom\"><div class=\"status\"><div id=\"test_status\" class=\"statusContainer\"></div></div><div style=\"clear:right;\"></div></div></div></div>") { Console.WriteLine("The basic template group code test failed with results: " + tp.ToString()); return false; } //test parametered call without defining variables in full and specifying group prefix tp = new Template("$skin/GenerateLargeForm(con,ID,TITLE,Clos,Min,SCID):CreateJavascriptElem()$", Program.TestGroup); tp.SetParameter("con", "TEST CONTENT"); tp.SetParameter("TITLE", "TESTING"); tp.SetParameter("SCID", "'test'"); tp.SetParameter("ID", "test"); if (tp.ToString() != "'<div id=\"test\" onBlur=\"UnHighlightTaskBar('test');\" class=\"Form transparent\" style=\"max-width:800px;max-height:600px;\"><div class=\"tl\"><div class=\"tr\"><div class=\"ControlButtons\"><img src=\"./FormParts/minimize.png\" alt=\"minimize\" onclick=\"MinimizeForm('test');\"><img src=\"./FormParts/cancel.png\" alt=\"close\" onclick=\"CloseForm('test');\"></div></div><div class=\"top\" id=\"test_top\"><center>TESTING</center></div></div><div class=\"left\"><div class=\"right\"><div style=\"overflow:auto;max-width:794px;max-height:552px;background-color:White;padding:5px;color:Black;\">TEST CONTENT</div></div></div><div class=\"bl\"><div class=\"br\"></div><div class=\"bottom\"><div class=\"status\"><div id=\"test_status\" class=\"statusContainer\"></div></div><div style=\"clear:right;\"></div></div></div></div>'") { Console.WriteLine("The basic template group code test failed with results: " + tp.ToString()); return false; } //testing recur calling template in string template group tp = new Template("$GenerateMenu(items)$", Program.TestGroup); List<MenuEntry> items = new List<MenuEntry>(); items.Add(new MenuEntry("test1", new MenuEntry[]{ new MenuEntry("test1.1",null), new MenuEntry("test1.2",null) })); items.Add(new MenuEntry("test2", new MenuEntry[]{ new MenuEntry("test2.1",null), new MenuEntry("test2.2",null) })); tp.SetAttribute("items", items); System.Diagnostics.Debug.WriteLine(tp.ToString()); return true; }
public bool InvokeTest() { //basic forloop Template tp = new Template("$entries:{entry |$entry$\n}$"); tp.SetParameter("entries", new string[] { "line1", "line2", "line3" }); if (tp.ToString() != "line1\nline2\nline3\n") { Console.WriteLine("Basic foreach loop test failed with results: " + tp.ToString()); return false; } //basic dictionary forloop tp = new Template("$entries:{entry|$entry.Key$=$entry.Value$\n}$"); Dictionary<string, string> vars = new Dictionary<string, string>(); vars.Add("FirstName", "Bob"); vars.Add("LastName", "LobLaw"); tp.SetParameter("entries", vars); if (tp.ToString() != "FirstName=Bob\nLastName=LobLaw\n") { Console.WriteLine("Basic foreach using dictionary test failed with results: " + tp.ToString()); return false; } //dictionary array test tp = new Template("$entries:{entry |$entry.FirstName$ $entry.LastName$\n}$"); List<Dictionary<string, string>> arVars = new List<Dictionary<string, string>>(); arVars.Add(vars); vars = new Dictionary<string, string>(); vars.Add("FirstName", "Amanda"); vars.Add("LastName", "Hugnkiss"); arVars.Add(vars); tp.SetParameter("entries", arVars); if (tp.ToString() != "Bob LobLaw\nAmanda Hugnkiss\n") { Console.WriteLine("Basic foreach using array of dictionaries failed with results: " + tp.ToString()); return false; } //testing for in for tp = new Template("$entries:{entry |$entry.Names:{name|$name$\n}$}$"); List<Dictionary<string, List<string>>> compVars = new List<Dictionary<string, List<string>>>(); Dictionary<string, List<string>> ent = new Dictionary<string, List<string>>(); ent.Add("Names", new List<string>(new string[] { "test1", "test2" })); compVars.Add(ent); vars = new Dictionary<string, string>(); tp.SetParameter("entries", compVars); if (tp.ToString().Trim() != "test1\ntest2") { Console.WriteLine("Basic foreach For in For failed with results: " + tp.ToString()); return false; } tp = new Template(Program.ReadEmbeddedResource("StringTemplateTester.resources.test.st")); arVars = new List<Dictionary<string, string>>(); Dictionary<string, string> file = new Dictionary<string, string>(); file.Add("Name", "MyFile"); file.Add("JScriptName", "MyFile"); arVars.Add(file); file = new Dictionary<string, string>(); file.Add("Name", "My Name's"); file.Add("JScriptName", "My Name\\'s"); arVars.Add(file); tp.SetAttribute("files", arVars); System.Diagnostics.Debug.WriteLine(tp.ToString()); return true; }
public bool InvokeTest() { Template tp = new Template(TemplateCode); tp.SetParameter("intercom_extension","1003"); tp.SetParameter("extensions",new string[]{"1001","1002"}); tp.SetParameter("intercom_only",true); if (!StringsEqualIgnoreWhitespace(tp.ToString(), TemplateResult)) { Console.WriteLine("Complex dialplan check failed with result: " + tp.ToString()); return false; } tp = new Template(Program.ReadEmbeddedResource("StringTemplateTester.resources.ExtensionConfig.st")); System.Diagnostics.Debug.WriteLine(tp.ToString()); return true; }
public bool InvokeTest() { Template tp = new Template("$if(bob)$Hello Bob$elseif(fred)$Hello Fred$else$GET OUT STRANGER DANGER$endif$"); //testing basic if tp.SetParameter("bob", true); if (tp.ToString() != "Hello Bob") { Console.WriteLine("Basic If statement test failed with result: " + tp.ToString()); return false; } //testing else if tp.RemoveParameter("bob"); tp.SetParameter("bob", false); tp.SetParameter("fred", true); if (tp.ToString() != "Hello Fred") { Console.WriteLine("Basic elseif statement test failed with result: " + tp.ToString()); return false; } //testing else using nulls tp.ClearParameters(); if (tp.ToString() != "GET OUT STRANGER DANGER") { Console.WriteLine("Basic else statement test failed with result: " + tp.ToString()); return false; } //testing using complex parameter tp = new Template("$if(bob.IsHere)$YAY I found bob$else$BOO bob is dead$endif$"); Dictionary<string, object> vars = new Dictionary<string, object>(); vars.Add("IsHere", true); tp.SetParameter("bob", vars); if (tp.ToString() != "YAY I found bob") { Console.WriteLine("Basic if using complex parameter failed with result: " + tp.ToString()); return false; } //testing compare in if statement tp = new Template("$if(equal(bob,fred))$Bob is Fred$else$Bob is not Fred$endif$"); tp.SetParameter("bob", "bob"); tp.SetParameter("fred", "bob"); if (tp.ToString() != "Bob is Fred") { Console.WriteLine("Basic if test using equal function inside failed with result: " + tp.ToString()); return false; } //testing not compare in if statement tp = new Template("$if(notequal(bob,fred))$Bob is Fred$else$Bob is not Fred$endif$"); tp.SetParameter("bob", "bob"); tp.SetParameter("fred", "bob"); if (tp.ToString() != "Bob is not Fred") { Console.WriteLine("Basic if test using notequal function inside failed with result: " + tp.ToString()); return false; } //testing compare alt format in if statement tp = new Template("$if((bob eq fred))$Bob is Fred$else$Bob is not Fred$endif$"); tp.SetParameter("bob", "bob"); tp.SetParameter("fred", "bob"); if (tp.ToString() != "Bob is Fred") { Console.WriteLine("Basic if test using equal function inside failed with result: " + tp.ToString()); return false; } //testing odd function tp = new Template("$if(odd(world))$OddBall$else$NotWeird$endif$"); tp.SetAttribute("world", "1"); Console.WriteLine(tp.ToString()); tp.RemoveParameter("world"); tp.SetAttribute("world", "hello"); Console.WriteLine(tp.ToString()); tp.RemoveParameter("world"); tp.SetAttribute("world", "2"); Console.WriteLine(tp.ToString()); return true; }