public void SetUpTest() { runDetails = new RunnerDetails(new Dictionary<string, string>()); runner = new Runner(true, runDetails); doc = new System.Xml.XmlDocument(); errParser = new ErrorParser(); parser = new ResultParser(doc, errParser, true); }
public bool RunTest(System.Xml.XmlNode seeflawNode, XmlElement bodyElement, RunnerDetails runDetails) { XmlDocument doc = bodyElement.OwnerDocument; ResultParser parser = new ResultParser(doc, errParser, onlyTest); Runner defaultRunner = new Runner(onlyTest, runDetails); for (int i = 0; i < seeflawNode.ChildNodes.Count; i++) { XmlNode childNode = seeflawNode.ChildNodes[i]; switch (childNode.LocalName) { case ActionType.TEXT: // Gather all text nodes that follows each other List<XmlNode> textNodes = GetSelectedNodes(seeflawNode.ChildNodes, ActionType.TEXT, i); XmlElement textElement = bodyElement.OwnerDocument.CreateElement("text"); bodyElement.AppendChild(textElement); foreach (XmlNode rowNode in textNodes) { XmlElement rowElement = bodyElement.OwnerDocument.CreateElement("row"); rowElement.InnerText = rowNode.InnerText; textElement.AppendChild(rowElement); } i += textNodes.Count - 1; break; case ActionType.PARAM: // Gather all param nodes that follows each other List<XmlNode> paramNodes = GetParamNodes(seeflawNode.ChildNodes, i); if (paramNodes.Count > 0) { ResultHolder paramData = defaultRunner.RunFixtureParam(paramNodes); AppendResultTable(bodyElement, paramData, parser); i += paramNodes.Count - 1; } else { // This is a fixture param node Runner paramRunner = new Runner(childNode, runDetails); Thread paramRunnerThread = new Thread(new ThreadStart(paramRunner.ThreadRun)); paramRunnerThread.Start(); ResultHolder paramAbortData = HandleRunnerThread(paramRunnerThread, paramRunner); ResultHolder paramCallData = paramRunner.GetThreadRunResult(); AppendResultTable(bodyElement, paramCallData, parser); AppendResultTable(bodyElement, paramAbortData, parser); } break; case ActionType.INIT: // Gather all init nodes that follows each other List<XmlNode> initNodes = GetSelectedNodes(seeflawNode.ChildNodes, ActionType.INIT, i); ResultHolder initData = defaultRunner.RunFixtureInit(initNodes); AppendResultTable(bodyElement, initData, parser); i += initNodes.Count - 1; break; case ActionType.CALL: Runner runner = new Runner(childNode, runDetails); Thread runnerThread = new Thread(new ThreadStart(runner.ThreadRun)); runnerThread.Start(); ResultHolder abortData = HandleRunnerThread(runnerThread, runner); ResultHolder callData = runner.GetThreadRunResult(); AppendResultTable(bodyElement, callData, parser); AppendResultTable(bodyElement, abortData, parser); break; case ActionType.SAVE: XmlNode saveInputNode = childNode.OwnerDocument.ImportNode(testResultSaveInput, true); XmlElement htmlResultNode = TransformToHtml(testResultSaveInput, childNode.OwnerDocument); bool inputNodesExist = false; if (childNode.ChildNodes.Count > 0) { foreach (XmlNode inputChildNode in childNode.ChildNodes) { if (inputChildNode.LocalName == "input") { if (inputChildNode.ChildNodes.Count > 0) { inputChildNode.InsertBefore(htmlResultNode.Clone(), inputChildNode.FirstChild); inputChildNode.InsertBefore(saveInputNode.Clone(), inputChildNode.FirstChild); } else { inputChildNode.AppendChild(saveInputNode.Clone()); inputChildNode.AppendChild(htmlResultNode.Clone()); } inputNodesExist = true; } } } if (!inputNodesExist) { XmlNode inputNode = childNode.OwnerDocument.CreateElement("input"); inputNode.AppendChild(saveInputNode); inputNode.AppendChild(htmlResultNode); childNode.AppendChild(inputNode); } goto case ActionType.CALL; case ActionType.LOAD: XmlAttribute fileLoadAttr = GetAttributeByName(childNode, "file"); XmlNode loadTestNode = null; if(loadDic.TryGetValue(fileLoadAttr.Value, out loadTestNode)) { XmlElement loadBodyNode = doc.CreateElement("load"); loadBodyNode.SetAttribute("file", fileLoadAttr.Value); RunnerDetails loadRunDetails = runDetails.LoadCopy(fileLoadAttr.Value); RunTest(loadTestNode, loadBodyNode, loadRunDetails); bodyElement.AppendChild(loadBodyNode); } break; case ActionType.ASYNC: List<ThreadRunnerInfo> asyncPairList = new List<ThreadRunnerInfo>(); foreach (XmlNode fixtureNode in childNode.ChildNodes) { if (fixtureNode.LocalName == "fixture") { XmlAttribute fixId = GetAttributeByName(fixtureNode, "id"); Object asyncFixture = runDetails.GetInitiatedFixture(fixId.Value); if (asyncFixture != null) { Runner asyncRunner = new Runner(fixtureNode, asyncFixture, runDetails); Thread asyncThread = new Thread(new ThreadStart(asyncRunner.ThreadAsyncRun)); asyncThread.Start(); asyncPairList.Add(new ThreadRunnerInfo(asyncThread, asyncRunner, fixId.Value)); } } } XmlElement asyncNode = doc.CreateElement("async"); foreach (ThreadRunnerInfo asyncInfo in asyncPairList) { XmlElement asyncFixtureNode = doc.CreateElement("fixture"); asyncFixtureNode.SetAttribute("id", asyncInfo.fixtureId); ResultHolder abortAsyncData = HandleRunnerThread(asyncInfo.thread, asyncInfo.runner); foreach (ResultHolder asyncData in asyncInfo.runner.GetThreadAsyncRunResult()) { AppendResultTable(asyncFixtureNode, asyncData, parser); } AppendResultTable(asyncFixtureNode, abortAsyncData, parser); asyncNode.AppendChild(asyncFixtureNode); } bodyElement.AppendChild(asyncNode); break; default: // TODO error message break; } if (bgRunner != null && bgRunner.KillPending) { break; } } return runSuccessful; }
public void SetUpTest() { XmlDocument doc = new XmlDocument(); parser = new ResultParser(doc, null, true); holder = new ResultHolder("test", null, true); outputDic = new Dictionary<string, string>(); resultDic = new Dictionary<string, object>(); dic1 = new Dictionary<string, string>(); dic2 = new Dictionary<string, string>(); dic3 = new Dictionary<string, string>(); dic4 = new Dictionary<string, string>(); dic5 = new Dictionary<string, string>(); dic5b = new Dictionary<string, object>(); dic6 = new Dictionary<string, object>(); dic7 = new Dictionary<string, object>(); dic8 = new Dictionary<string, object>(); dic9 = new Dictionary<string, object>(); dic1.Add("first", "A"); dic1.Add("second", "B"); dic1.Add("third", "C"); dic1.Add("fourth", "D"); dic2.Add("first", "A"); dic2.Add("second", "B"); dic2.Add("third", "B"); dic2.Add("fourth", "B"); dic3.Add("first", "A"); dic3.Add("second", "C"); dic3.Add("third", "C"); dic3.Add("fourth", "C"); dic4.Add("first", "C"); dic4.Add("second", "B"); dic4.Add("third", "C"); dic4.Add("fourth", "D"); dic5.Add("first", "C"); dic5.Add("second", "B"); dic5.Add("third", "D"); dic5.Add("fourth", "D"); dic5b.Add("first", "C"); dic5b.Add("second", "B"); dic5b.Add("third", "D"); dic5b.Add("fourth", "D"); dic6.Add("first", "A"); dic6.Add("second", "C"); dic6.Add("third", "C"); dic6.Add("fourth", "C"); dic7.Add("first", "C"); dic7.Add("second", "B"); dic7.Add("third", "D"); dic7.Add("fourth", "C"); dic8.Add("first", "A"); dic8.Add("second", "B"); dic8.Add("third", "B"); dic8.Add("fourth", "C"); dic9.Add("first", "A"); dic9.Add("second", "B"); dic9.Add("third", "D"); dic9.Add("fourth", "C"); holder.LoadOutputKeys(dic1); }
public void AppendResultTable(XmlElement bodyElement, ResultHolder dataHolder, ResultParser parser) { XmlNode table = parser.GetResultAsXml(dataHolder); if (table == null) { return; } bodyElement.AppendChild(table); //bodyElement.AppendChild(bodyElement.OwnerDocument.CreateElement("br")); CheckResultStatus(dataHolder); }