Example #1
0
        private void analyzeCaseData()
        {
            MyRunCaseData <ICaseExecutionContent> yourCaseRunData = ((CaseCell)myTargetNode.Tag).CaseRunData;

            if (yourCaseRunData.errorMessages == null)
            {
                llb_errorInfo.Visible = false;
            }
            else
            {
                llb_errorInfo.Text = yourCaseRunData.errorMessages.MyToString(";");
                return;
            }
            lb_caseId.Text     = "ID:" + yourCaseRunData.id;
            lb_caseTarget.Text = "->" + yourCaseRunData.testContent.MyExecutionTarget;
            lb_protocol.Text   = "Protocol:" + yourCaseRunData.contentProtocol.ToString();
            lb_delay.Text      = "Delay:" + yourCaseRunData.caseAttribute.attributeDelay + "ms";
            lb_level.Text      = "CaseLevel:" + yourCaseRunData.caseAttribute.attributeLevel;
            if (yourCaseRunData.caseAttribute.myParameterSaves != null)
            {
                foreach (ParameterSave tempValue in yourCaseRunData.caseAttribute.myParameterSaves)
                {
                    listView_parameterSave.Items.Add(new ListViewItem(new string[] { tempValue.parameterName, tempValue.parameterFindVaule }));
                }
            }

            lb_expectType.Text = "AssertType:" + yourCaseRunData.caseExpectInfo.myExpectType.ToString();
            if (yourCaseRunData.caseExpectInfo.myExpectContent.IsFilled())
            {
                tb_expectContent.Text = yourCaseRunData.caseExpectInfo.myExpectContent.contentData;
            }
            if (yourCaseRunData.actions != null)
            {
                foreach (KeyValuePair <CaseResult, CaseActionDescription> tempAction in yourCaseRunData.actions)
                {
                    listView_action.Items.Add(new ListViewItem(new string[] { tempAction.Key.ToString(), tempAction.Value.caseAction.ToString() + tempAction.Value.addInfo.MyValue() }));
                }
            }
            if (yourCaseRunData.testContent != null)
            {
                MyControlHelper.myAddRtbStr(ref rtb_Content, "【Actuator】:" + yourCaseRunData.testContent.MyCaseActuator, Color.DarkOrchid, true);
                MyControlHelper.myAddRtbStr(ref rtb_Content, yourCaseRunData.testContent.MyExecutionContent, Color.Maroon, true);
                //rtb_Content.AppendText((((CaseCell)myTargetNode.Tag).CaseXmlNode)["Content"].InnerXml);
                string xmlContent;
                if (MyCommonTool.FormatXmlString((((CaseCell)myTargetNode.Tag).CaseXmlNode)["Content"].OuterXml, out xmlContent))
                {
                    MyControlHelper.myAddRtbStr(ref rtb_Content, xmlContent, Color.Black, true);
                }
                else
                {
                    MyControlHelper.myAddRtbStr(ref rtb_Content, xmlContent, Color.Red, true);
                }
                rtb_Content.Select(0, 0);
                rtb_Content.ScrollToCaret();
            }
            else
            {
                rtb_Content.Text = "NULL";
            }
        }
Example #2
0
        /// <summary>
        /// i will get the csae info that you need to show in your Tree(使用MyRunCaseData的重载版本针对不同执行协议对content的内容有优化)
        /// </summary>
        /// <param name="runCaseData">MyRunCaseData</param>
        /// <returns>the info with myCaseLaodInfo</returns>
        public static myCaseLaodInfo GetCaseLoadInfo(MyRunCaseData <ICaseExecutionContent> runCaseData)
        {
            myCaseLaodInfo myInfo = new myCaseLaodInfo("NULL");

            myInfo.id       = runCaseData.id;
            myInfo.remark   = runCaseData.name;
            myInfo.caseType = CaseType.Case;
            myInfo.content  = runCaseData.testContent.MyExecutionContent == null?string.Format("> {0}", runCaseData.testContent.MyExecutionTarget) : string.Format("> {0}{1}{2}", runCaseData.testContent.MyExecutionTarget, MyConfiguration.CaseShowTargetAndContent, runCaseData.testContent.MyExecutionContent);

            myInfo.caseProtocol = runCaseData.testContent.MyCaseProtocol;
            if (runCaseData.actions != null)
            {
                foreach (var tempAction in runCaseData.actions)
                {
                    myInfo.actions.Add(tempAction.Key, tempAction.Value.caseAction);
                }
            }
            return(myInfo);
        }
Example #3
0
 /// <summary>
 /// CaseCell构造函数
 /// </summary>
 /// <param name="yourCaseType">CaseType</param>
 /// <param name="yourXmlNode">CaseCell脚本原始信息</param>
 /// <param name="yourCaseRunData">CaseCell脚本解析后的信息</param>
 public CaseCell(CaseType yourCaseType, XmlNode yourXmlNode, MyRunCaseData <ICaseExecutionContent> yourCaseRunData)
 {
     caseType    = yourCaseType;
     caseXmlNode = yourXmlNode;
     caseRunData = yourCaseRunData;
 }
Example #4
0
        /// <summary>
        /// i will get a myRunCaseData that will give caseActionActuator from XmlNode
        /// </summary>
        /// <param name="yourRunNode">your XmlNode</param>
        /// <returns>myRunCaseData you want</returns>
        public static MyRunCaseData <ICaseExecutionContent> GetCaseRunData(XmlNode sourceNode)
        {
            MyRunCaseData <ICaseExecutionContent> myCaseData = new MyRunCaseData <ICaseExecutionContent>();
            CaseProtocol contentProtocol = CaseProtocol.unknownProtocol;

            if (sourceNode == null)
            {
                myCaseData.AddErrorMessage("Error :source data is null");
            }
            else
            {
                if (sourceNode.Name == "Case")
                {
                    #region Basic information
                    if (sourceNode.Attributes["id"] == null)
                    {
                        myCaseData.AddErrorMessage("Error :not find the ID");
                    }
                    else
                    {
                        try
                        {
                            myCaseData.id = int.Parse(sourceNode.Attributes["id"].Value);
                        }
                        catch (Exception)
                        {
                            myCaseData.AddErrorMessage("Error :find the error ID");
                        }
                    }
                    myCaseData.name = CaseTool.GetXmlAttributeVauleEx(sourceNode, "remark", "NULL");
                    #endregion

                    #region Content
                    //XmlNode tempCaseContent = sourceNode.SelectSingleNode("Content"); //sourceNode["Content"] 具有同样的功能
                    XmlNode tempCaseContent = sourceNode["Content"];
                    if (tempCaseContent == null)
                    {
                        myCaseData.AddErrorMessage("Error :can not find Content");
                    }
                    else
                    {
                        if (tempCaseContent.Attributes["protocol"] != null && tempCaseContent.Attributes["actuator"] != null)
                        {
                            try
                            {
                                contentProtocol            = (CaseProtocol)Enum.Parse(typeof(CaseProtocol), tempCaseContent.Attributes["protocol"].Value);
                                myCaseData.contentProtocol = contentProtocol;
                            }
                            catch
                            {
                                myCaseData.AddErrorMessage("Error :error protocol in Content");
                            }
                            switch (contentProtocol)
                            {
                            case CaseProtocol.console:
                                myCaseData.testContent = CaseProtocolExecutionForConsole.GetRunContent(tempCaseContent);
                                break;

                            case CaseProtocol.activeMQ:
                                myCaseData.testContent = CaseProtocolExecutionForActiveMQ.GetRunContent(tempCaseContent);
                                break;

                            case CaseProtocol.mysql:
                                myCaseData.testContent = CaseProtocolExecutionForMysql.GetRunContent(tempCaseContent);
                                break;

                            case CaseProtocol.ssh:
                                myCaseData.testContent = CaseProtocolExecutionForSsh.GetRunContent(tempCaseContent);
                                break;

                            case CaseProtocol.vanelife_http:
                                myCaseData.testContent = CaseProtocolExecutionForVanelife_http.GetRunContent(tempCaseContent);
                                break;

                            case CaseProtocol.http:
                                myCaseData.testContent = CaseProtocolExecutionForHttp.GetRunContent(tempCaseContent);
                                break;

                            case CaseProtocol.tcp:
                                myCaseData.testContent = CaseProtocolExecutionForTcp.GetRunContent(tempCaseContent);
                                break;

                            case CaseProtocol.telnet:
                                myCaseData.testContent = CaseProtocolExecutionForTelnet.GetRunContent(tempCaseContent);
                                break;

                            case CaseProtocol.com:
                                myCaseData.testContent = CaseProtocolExecutionForCom.GetRunContent(tempCaseContent);
                                break;

                            case CaseProtocol.vanelife_comm:
                                myCaseData.AddErrorMessage("Error :this protocol not supported for now");
                                break;

                            case CaseProtocol.vanelife_tcp:
                                myCaseData.AddErrorMessage("Error :this protocol not supported for now");
                                break;

                            case CaseProtocol.vanelife_telnet:
                                myCaseData.AddErrorMessage("Error :this protocol not supported for now");
                                break;

                            case CaseProtocol.defaultProtocol:
                                myCaseData.AddErrorMessage("Error :this protocol not supported for now");
                                break;

                            default:
                                myCaseData.AddErrorMessage("Error :this protocol not supported for now");
                                break;
                            }
                            if (myCaseData.testContent != null)
                            {
                                if (myCaseData.testContent.MyErrorMessage != null)  //将testContent错误移入MyRunCaseData,执行case时会检查MyRunCaseData中的错误
                                {
                                    myCaseData.AddErrorMessage("Error :the Content not analyticaled Because:" + myCaseData.testContent.MyErrorMessage);
                                    //return myCaseData;
                                }
                            }
                        }
                        else
                        {
                            myCaseData.AddErrorMessage("Error :can not find protocol or actuator in Content");
                        }
                    }
                    #endregion

                    #region Expect
                    XmlNode tempCaseExpect = sourceNode["Expect"];
                    if (tempCaseExpect == null)
                    {
                        myCaseData.caseExpectInfo.myExpectType = CaseExpectType.judge_default;
                    }
                    else
                    {
                        if (tempCaseExpect.Attributes["method"] != null)
                        {
                            try
                            {
                                myCaseData.caseExpectInfo.myExpectType = (CaseExpectType)Enum.Parse(typeof(CaseExpectType), "judge_" + tempCaseExpect.Attributes["method"].Value);
                            }
                            catch
                            {
                                myCaseData.AddErrorMessage("Error :find error CaseExpectType in Expect");
                                myCaseData.caseExpectInfo.myExpectType = CaseExpectType.judge_default;
                            }
                        }
                        else
                        {
                            myCaseData.caseExpectInfo.myExpectType = CaseExpectType.judge_is;
                        }
                        myCaseData.caseExpectInfo.myExpectContent = CaseTool.GetXmlParametContent(tempCaseExpect);
                    }
                    #endregion

                    #region Action
                    XmlNode tempCaseAction = sourceNode["Action"];
                    if (tempCaseAction != null)
                    {
                        if (tempCaseAction.HasChildNodes)
                        {
                            foreach (XmlNode tempNode in tempCaseAction.ChildNodes)
                            {
                                CaseResult tempResult = CaseResult.Unknow;
                                CaseAction tempAction = CaseAction.action_unknow;
                                try
                                {
                                    tempResult = (CaseResult)Enum.Parse(typeof(CaseResult), tempNode.Name);
                                }
                                catch
                                {
                                    myCaseData.AddErrorMessage(string.Format("Error :find error CaseAction in Action with [{0}] in [{1}]", tempNode.InnerXml, tempNode.Name));
                                    continue;
                                }
                                try
                                {
                                    tempAction = (CaseAction)Enum.Parse(typeof(CaseAction), "action_" + CaseTool.GetXmlAttributeVauleWithEmpty(tempNode, "action"));
                                }
                                catch
                                {
                                    myCaseData.AddErrorMessage(string.Format("Error :find error CaseAction in Action with [{0}] in [{1}]", tempNode.InnerXml, CaseTool.GetXmlAttributeVauleWithEmpty(tempNode, "action")));
                                    continue;
                                }
                                if (tempNode.InnerText != "")
                                {
                                    myCaseData.AddCaseAction(tempResult, new CaseActionDescription(tempAction, tempNode.InnerText));
                                }
                                else
                                {
                                    myCaseData.AddCaseAction(tempResult, new CaseActionDescription(tempAction, null));
                                }
                            }
                        }
                    }
                    #endregion

                    #region Attribute
                    XmlNode tempCaseAttribute = sourceNode["Attribute"];
                    if (tempCaseAttribute != null)
                    {
                        if (tempCaseAttribute.HasChildNodes)
                        {
                            if (tempCaseAttribute["Delay"] != null)
                            {
                                try
                                {
                                    myCaseData.caseAttribute.attributeDelay = int.Parse(tempCaseAttribute["Delay"].InnerText);
                                }
                                catch
                                {
                                    myCaseData.AddErrorMessage("Error :find error Delay data in Attribute");
                                }
                            }
                            if (tempCaseAttribute["Level"] != null)
                            {
                                try
                                {
                                    myCaseData.caseAttribute.attributeLevel = int.Parse(tempCaseAttribute["Level"].InnerText);
                                }
                                catch
                                {
                                    myCaseData.AddErrorMessage("Error :find error Level data in Attribute");
                                }
                            }
                            if (tempCaseAttribute["ParameterSave"] != null)
                            {
                                if (tempCaseAttribute["ParameterSave"].HasChildNodes)
                                {
                                    foreach (XmlNode tempNode in tempCaseAttribute["ParameterSave"].ChildNodes)
                                    {
                                        if (tempNode.Name == "NewParameter")
                                        {
                                            string          tempParameterName       = CaseTool.GetXmlAttributeVaule(tempNode, "name");
                                            string          tempParameterMode       = CaseTool.GetXmlAttributeVaule(tempNode, "mode");
                                            string          tempParameterAdditional = CaseTool.GetXmlAttributeVaule(tempNode, "additional");
                                            string          tempFindVaule           = tempNode.InnerText;
                                            PickOutFunction tempPickOutFunction     = PickOutFunction.pick_str;
                                            if (tempParameterName == null)
                                            {
                                                myCaseData.AddErrorMessage("Error :can not find name data in NewParameter in Attribute");
                                                continue;
                                            }
                                            if (tempParameterName == "")
                                            {
                                                myCaseData.AddErrorMessage("Error :the name data in NewParameter is empty in Attribute");
                                                continue;
                                            }
                                            if (tempParameterMode == null)
                                            {
                                                myCaseData.AddErrorMessage("Error :can not find mode data in NewParameter in Attribute");
                                                continue;
                                            }
                                            if (tempFindVaule == "")
                                            {
                                                myCaseData.AddErrorMessage("Error :the NewParameter vaule is empty in Attribute");
                                                continue;
                                            }
                                            try
                                            {
                                                tempPickOutFunction = (PickOutFunction)Enum.Parse(typeof(PickOutFunction), "pick_" + tempParameterMode);
                                            }
                                            catch
                                            {
                                                myCaseData.AddErrorMessage("Error :find error ParameterSave mode in Attribute");
                                                continue;
                                            }
                                            myCaseData.caseAttribute.addParameterSave(tempParameterName, tempFindVaule, tempPickOutFunction, tempParameterAdditional);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    myCaseData.AddErrorMessage("Error :source data is error");
                }
            }
            return(myCaseData);
        }