static void Main(string[] args) { "Testing THMessage Class".title('='); Console.WriteLine(); /////////////////////////////////////////////////////////////// // Serialize and Deserialize TestRequest data structure "Testing Serialization of TestRequest data structure".title(); TestElement te1 = new TestElement(); te1.testName = "test1"; te1.addDriver("td1.dll"); te1.addCode("tc1.dll"); te1.addCode("tc2.dll"); TestElement te2 = new TestElement(); te2.testName = "test2"; te2.addDriver("td2.dll"); te2.addCode("tc3.dll"); te2.addCode("tc4.dll"); TestRequest tr = new TestRequest(); tr.author = "Jim Fawcett"; tr.tests.Add(te1); tr.tests.Add(te2); string trXml = tr.ToXml(); Console.Write("\n Serialized TestRequest data structure:\n\n {0}\n", trXml); "Testing Deserialization of TestRequest from XML".title(); TestRequest newRequest = trXml.FromXml <TestRequest>(); string typeName = newRequest.GetType().Name; Console.Write("\n deserializing xml string results in type: {0}\n", typeName); Console.Write(newRequest); Console.WriteLine(); }
static void Main(string[] args) { "Testing THMessage Class".title('='); Console.WriteLine(); /////////////////////////////////////////////////////////////// // Serialize and Deserialize TestRequest data structure "Testing Serialization of TestRequest data structure".title(); TestElement te1 = new TestElement(); te1.testName = "test1"; te1.addDriver("td1.dll"); te1.addCode("tc1.dll"); te1.addCode("tc2.dll"); TestElement te2 = new TestElement(); te2.testName = "test2"; te2.addDriver("td2.dll"); te2.addCode("tc3.dll"); te2.addCode("tc4.dll"); TestRequest tr = new TestRequest(); tr.author = "Jim Fawcett"; tr.tests.Add(te1); tr.tests.Add(te2); string trXml = tr.ToXml(); Console.Write("\n Serialized TestRequest data structure:\n\n {0}\n", trXml); "Testing Deserialization of TestRequest from XML".title(); TestRequest newRequest = trXml.FromXml <TestRequest>(); string typeName = newRequest.GetType().Name; Console.Write("\n deserializing xml string results in type: {0}\n", typeName); Console.Write(newRequest); Console.WriteLine(); /////////////////////////////////////////////////////////////// // Create and Parse TestRequest message "Testing Creation and Parsing of TestRequest Message".title(); Message msg = new Message(); msg.to = "TH"; msg.from = "CL"; msg.type = "basic"; msg.author = "Fawcett"; Console.Write("\n base message:\n {0}", msg.ToString()); msg.show(); Console.Write("\n Creating Message using TestRequest data structure\n"); Message rqstMsg = new Message(); rqstMsg.author = "Fawcett"; rqstMsg.to = "localhost:8080"; rqstMsg.from = "localhost:8091"; rqstMsg.type = "TestRequest"; rqstMsg.time = DateTime.Now; rqstMsg.body = tr.ToXml(); rqstMsg.show(); Console.Write("\n retrieving testRequest object:"); TestRequest newTrq = rqstMsg.body.FromXml <TestRequest>(); Console.Write("\n{0}\n", newTrq); /////////////////////////////////////////////////////////////// // Serialize and Deserialize TestResults data structure "Testing Serialization of TestResults data structure".title(); TestResult tr1 = new TestResult(); tr1.testName = "test1"; tr1.passed = true; tr1.log = "test always passes"; TestResult tr2 = new TestResult("test2", false); tr2.addLog("test always fails"); tr2.addLog(" every time"); TestResults rslts = new TestResults("Fawcett", DateTime.Now); rslts.add(tr1).add(tr2); // using extension method syntax string xml = rslts.ToXml(); Console.Write("\n Serialized TestResults data structure:\n\n {0}\n", xml); "Testing Deserialization of TestResults from XML".title(); TestResults newResults = xml.FromXml <TestResults>(); typeName = newResults.GetType().Name; Console.Write("\n deserializing xml string results in type: {0}\n", typeName); Console.Write(newResults); Console.WriteLine(); /////////////////////////////////////////////////////////////// // Create and Parse TestResults message "Testing Creation and Parsing of TestResults Message".title(); Console.Write("\n Creating Message using TestResults data structure\n"); Message rltsMsg = new Message(); rltsMsg.to = "localhost:8091"; rltsMsg.from = "localhost:8080"; rltsMsg.type = "TestResults"; rltsMsg.author = "TestHarness"; rltsMsg.time = DateTime.Now; rltsMsg.body = rslts.ToXml(); rltsMsg.show(); Console.Write("\n retrieving testResults object:"); TestResults newTr = rltsMsg.body.FromXml <TestResults>(); Console.Write("\n{0}", newTr); Console.Write("\n\n"); }