Beispiel #1
0
 public void RunFixtureParamTwoNodes()
 {
     doc.LoadXml("<doc><param name='param1' value='some'/><param name='param2' argument='user'/></doc>");
     Dictionary<string, string> argDic = new Dictionary<string, string>();
     argDic.Add("user", "Arne");
     runDetails = new RunnerDetails(argDic);
     runner = new Runner(true, runDetails);
     ResultHolder dataHolder = runner.RunFixtureParam(doc.FirstChild.SelectNodes("param"));
     XmlNode resultNode = parser.GetResultAsXml(dataHolder);
     System.Console.WriteLine(resultNode.OuterXml);
     XmlNode htmlNode = HtmlTransformer.ConvertToHtml(resultNode.OwnerDocument, resultNode);
     string expected = "<table border=\"0\" cellpadding=\"0\" class=\"step_passed\"><tr><td><table width=\"100%\">";
     expected += "<tr><th align=\"left\" bgcolor=\"lightgreen\" class=\"title\">param</th></tr></table></td></tr>";
     expected += "<tr><td><table border=\"1\" cellpadding=\"3\" cellspacing=\"0\" width=\"100%\">";
     expected += "<tr><td class=\"status_passed\">Type</td><td bgcolor=\"#AAAAFF\" class=\"input_title\">name</td><td bgcolor=\"#AAAAFF\" class=\"input_title\">value</td><td bgcolor=\"#AAAAFF\" class=\"input_title\">argument</td><td bgcolor=\"#EEAAFF\" class=\"output_title\" colspan=\"2\">read_value</td></tr>";
     expected += "<tr><td bgcolor=\"lightgreen\" class=\"statusvalue_passed\">Param</td><td bgcolor=\"#CCCCFF\" class=\"input_value\">param1</td><td bgcolor=\"#CCCCFF\" class=\"input_value\">some</td><td bgcolor=\"#CCCCFF\" class=\"input_value\" /><td bgcolor=\"lightgreen\" class=\"outputvalue_passed\" colspan=\"2\" /></tr>";
     expected += "<tr><td bgcolor=\"lightgreen\" class=\"statusvalue_passed\">Param</td><td bgcolor=\"#CCCCFF\" class=\"input_value\">param2</td><td bgcolor=\"#CCCCFF\" class=\"input_value\" /><td bgcolor=\"#CCCCFF\" class=\"input_value\">user</td><td bgcolor=\"lightgreen\" class=\"outputvalue_passed\" colspan=\"2\">Arne</td></tr>";
     expected += "</table></td></tr></table>";
     System.Console.WriteLine(htmlNode.OuterXml);
     NUnit.Framework.Assert.AreEqual(expected, htmlNode.OuterXml);
 }
Beispiel #2
0
 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);
 }
Beispiel #3
0
 private ResultHolder HandleRunnerThread(Thread runnerThread, Runner runner)
 {
     if (bgRunner != null)
     {
         while (!bgRunner.KillPending && runnerThread.IsAlive)
         {
             runnerThread.Join(20);
         }
         if (runnerThread.IsAlive)
         {
             try
             {
                 runnerThread.Abort();
                 ResultHolder abortData = runner.activeDataHolder;
                 if (abortData != null)
                 {
                     abortData.SetRowError(new Exception("Process killed by user."));
                     return abortData;
                 }
             }
             catch (Exception ex)
             {
                 System.Console.WriteLine(ex.ToString());
             }
         }
     }
     else
     {
         runnerThread.Join();
     }
     return null;
 }
Beispiel #4
0
 public ThreadRunnerInfo(Thread t, Runner r, string id)
 {
     thread = t;
     runner = r;
     fixtureId = id;
 }
Beispiel #5
0
        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;
        }