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() { 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; }