예제 #1
0
        /// <summary>
        /// 检查输入文件地址是否符合要求
        /// </summary>
        /// <param name="filePath">文件地址</param>
        /// <returns>isChecked</returns>
        private bool FileChecked(string filePath)
        {
            if (filePathTb.Text == string.Empty)
            {
                this._logger.Info(message: new Exception(message: "请输入文件地址."));
                OutputDisplay.ShowMessage(msg: "请输入文件地址.", color: Color.Red);
                return(true);
            }

            if (!(filePathTb.Text.EndsWith(value: ".xml") || filePathTb.Text.EndsWith(value: ".xls") || filePathTb.Text.EndsWith(value: ".xlsx")))
            {
                this._logger.Info(message: new Exception(message: "输入文件要求为xml,xls或xlsx格式."));
                OutputDisplay.ShowMessage(msg: "输入文件要求为xml,xls或xlsx格式.", color: Color.Red);
                return(true);
            }

            if (!File.Exists(path: filePathTb.Text))
            {
                this._logger.Info(message: new Exception(message: string.Format(format: "{0} 已不存在,请重新输入文件地址.", arg0: filePathTb.Text)));
                MessageBox.Show(text: string.Format(format: "{0} 已不存在,请重新输入文件地址.", arg0: filePathTb.Text), caption: "Warning");
                return(true);
            }

            return(false);
        }
예제 #2
0
        private void WriteInWorkSheet(Excel.Workbook workBook)
        {
            var workSheet = (Excel.Worksheet)workBook.Worksheets.Item[1];

            int iFlag = 2;

            foreach (TestCase node in this._sourceTestCases)
            {
                OutputDisplay.ShowMessage(node.Name, Color.Chartreuse);
                workSheet.Cells[iFlag, 1] = node.ExternalId;
                workSheet.Cells[iFlag, 2] = node.Name;
                workSheet.Cells[iFlag, 3] = node.Importance.ToString();
                workSheet.Cells[iFlag, 4] = node.ExecutionType.ToString();
                workSheet.Cells[iFlag, 5] = node.Summary;
                workSheet.Cells[iFlag, 6] = node.Preconditions;
                int iMerge = 0;
                foreach (TestStep step in node.TestSteps)
                {
                    workSheet.Cells[iFlag, 7] = CommonHelper.DelTags(step.Actions);
                    workSheet.Cells[iFlag, 8] = CommonHelper.DelTags(step.ExpectedResults);
                    iFlag++;
                    iMerge++;
                }

                this.MergeCells(workSheet, iMerge, iFlag - iMerge);
                Thread.Sleep(1000);
            }
            workSheet.Cells[iFlag++, 1] = "END";
        }
예제 #3
0
        /// <summary>
        /// 检查输入文件地址是否符合要求
        /// </summary>
        /// <param name="filePath">文件地址</param>
        /// <returns>isChecked</returns>
        private bool FileChecked(string filePath)
        {
            if (filePathTb.Text == string.Empty)
            {
                this._logger.Info(new Exception("请输入文件地址."));
                OutputDisplay.ShowMessage("请输入文件地址.", Color.Red);
                return(true);
            }

            if (!(filePathTb.Text.EndsWith(".xml") || filePathTb.Text.EndsWith(".xls") || filePathTb.Text.EndsWith(".xlsx")))
            {
                this._logger.Info(new Exception("输入文件要求为xml,xls或xlsx格式."));
                OutputDisplay.ShowMessage("输入文件要求为xml,xls或xlsx格式.", Color.Red);
                return(true);
            }

            if (!File.Exists(filePathTb.Text))
            {
                this._logger.Info(new Exception($"{filePathTb.Text} 已不存在,请重新输入文件地址."));
                MessageBox.Show($"{filePathTb.Text} 已不存在,请重新输入文件地址.", "Warning");
                return(true);
            }

            return(false);
        }
예제 #4
0
        private void SaveFileByDialog(object fileObj)
        {
            if (fileObj is string fileDir && fileDir.EndsWith("xml"))
            {
                if (_tcDic.First().Value == null)
                {
                    return;
                }

                SaveFileDialog sfd = new SaveFileDialog {
                    RestoreDirectory = true, Filter = "Excel 2007(*.xlsx)|*.xlsx|Excel 2003(*.xls)|*.xls"
                };

                ExcelHandler eh = new ExcelHandler(_tcDic.First().Value);
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        eh.WriteExcel(sfd.FileName);
                    }
                    catch (Exception ex)
                    {
                        OutputDisplay.ShowMessage(ex.ToString(), Color.Red);
                        this._logger.Error(ex);
                        return;
                    }
                }
            }
예제 #5
0
 private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     this.timer.Stop();
     TimeSpan consume = DateTime.Now - this._starTime;
     string showMsg = $"转换用例数: {_tcDic.Sum(keyValuePair => keyValuePair.Value.Count)}. 耗时: {consume.Minutes.ToString("D2")}:{consume.Seconds.ToString("D2")}.\n用例生成目录: {System.Environment.CurrentDirectory.ToString()}";
     MessageBox.Show(showMsg);
     OutputDisplay.ShowMessage(showMsg, Color.Azure);
     this.filePathTb.Text = string.Empty;
     this.progressBar.Value = this.progressBar.Minimum;
 }
예제 #6
0
 /// <summary>
 /// Excel转换为XML
 /// </summary>
 /// <param name="fileDir">文件路径</param>
 private void ExcelToXml(string fileDir)
 {
     _ = GoogleAnalyticsTracker.Tracker("Work", "ExcelToXml");
     try
     {
         ExcelAnalysisByEpplus excelAnalysis = new ExcelAnalysisByEpplus(fileDir);
         _tcDic = excelAnalysis.ReadExcel();
     }
     catch (Exception ex)
     {
         this._logger.Error(ex);
         OutputDisplay.ShowMessage(ex.ToString(), Color.Red);
         return;
     }
 }
예제 #7
0
 /// <summary>
 /// Excel转换为XML
 /// </summary>
 /// <param name="fileDir">文件路径</param>
 private void ExcelToXml(string fileDir)
 {
     try
     {
         ExcelAnalysisByEpplus excelAnalysis = new ExcelAnalysisByEpplus(fileDir);
         _tcDic = excelAnalysis.ReadExcel();
         XmlHandler xh = new XmlHandler(_tcDic);
         xh.WriteXml();
     }
     catch (Exception ex)
     {
         this._logger.Error(ex);
         OutputDisplay.ShowMessage(ex.ToString(), Color.Red);
         return;
     }
 }
예제 #8
0
 private void XmlToExcel(string fileDir)
 {
     _ = GoogleAnalyticsTracker.Tracker("Work", "XmlToExcel");
     try
     {
         XmlAnalysis     xmlAnalysis = new XmlAnalysis(fileDir);
         XmlToModel      xtm         = new XmlToModel(xmlAnalysis.GetAllTestCaseNodes());
         List <TestCase> tcList      = xtm.OutputTestCases();
         this._tcDic = new Dictionary <string, List <TestCase> >();
         _tcDic.Add("TestCase", tcList);
     }
     catch (Exception ex)
     {
         this._logger.Error(ex);
         OutputDisplay.ShowMessage(ex.ToString(), Color.Red);
         return;
     }
 }
예제 #9
0
        /// <summary>
        /// XML转换为Excel
        /// </summary>
        /// <param name="fileDir">文件路径</param>
        private void XmlToExcel(string fileDir)
        {
            try
            {
                XmlAnalysis     xmlAnalysis = new XmlAnalysis(fileDir);
                XmlToModel      xtm         = new XmlToModel(xmlAnalysis.GetAllTestCaseNodes());
                List <TestCase> tcList      = xtm.OutputTestCases();
                this._tcDic = new Dictionary <string, List <TestCase> >();
                _tcDic.Add("TestCase", tcList);

                ExcelHandler eh = new ExcelHandler(tcList);
                eh.WriteExcel();
            }
            catch (Exception ex)
            {
                this._logger.Error(ex);
                OutputDisplay.ShowMessage(ex.ToString(), Color.Red);
                return;
            }
        }
예제 #10
0
        /// <summary>
        /// 测试用例转为Str
        /// </summary>
        /// <returns>List String</returns>
        private Dictionary <string, List <string> > CaseToStr()
        {
            Dictionary <string, List <string> > dicCase = new Dictionary <string, List <string> >();

            foreach (KeyValuePair <string, List <TestCase> > keyValuePair in _tcList)
            {
                OutputDisplay.ShowMessage($"【{keyValuePair.Key}】数据读取......", Color.MediumVioletRed);
                List <string> tcStrList = new List <string>();
                foreach (TestCase testCase in keyValuePair.Value)
                {
                    OutputDisplay.ShowMessage(testCase.Name, Color.Chartreuse);
                    string fieldsStr = $"<node_order><![CDATA[{testCase.NodeOrder}]]></node_order>";
                    fieldsStr += $"<externalid><![CDATA[{testCase.ExternalId}]]></externalid>";
                    fieldsStr += $"<version><![CDATA[{testCase.Version}]]></version>";
                    fieldsStr += $"<summary><![CDATA[{testCase.Summary}]]></summary>";
                    fieldsStr += $"<preconditions><![CDATA[{testCase.Preconditions}]]></preconditions>";
                    fieldsStr += $"<execution_type><![CDATA[{testCase.ExecutionType.ToString()}]]></execution_type>";
                    fieldsStr += $"<importance><![CDATA[{testCase.Importance.ToString()}]]></importance>";
                    fieldsStr += $"<estimated_exec_duration>{testCase.EstimatedExecDuration}</estimated_exec_duration>";
                    fieldsStr += $"<status>{testCase.Status}</status>";
                    string tsStr = "";
                    foreach (TestStep testStep in testCase.TestSteps)
                    {
                        tsStr += "<step>";
                        tsStr += $"<step_number><![CDATA[{testStep.StepNumber}]]></step_number>";
                        tsStr += $"<actions><![CDATA[{testStep.Actions}]]></actions>";
                        tsStr += $"<expectedresults><![CDATA[{testStep.ExpectedResults}]]></expectedresults>";
                        tsStr += $"<execution_type><![CDATA[{testStep.ExecutionType}]]></execution_type>";
                        tsStr += "</step>";
                    }
                    fieldsStr += $"<steps>{tsStr}</steps>";
                    string tcStr = $"<testcase name=\"{testCase.Name}\">{fieldsStr}</testcase>";
                    Thread.Sleep(1000);
                    tcStrList.Add(tcStr);
                }

                dicCase.Add(keyValuePair.Key, tcStrList);
            }

            return(dicCase);
        }
예제 #11
0
        private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            this.timer.Stop();
            TimeSpan consume = DateTime.Now - this._starTime;
            string   showMsg = $"转换用例数: {_tcDic.Sum(keyValuePair => keyValuePair.Value.Count)}. 耗时: {consume.Minutes.ToString("D2")}:{consume.Seconds.ToString("D2")}.\n";
            var      result  = MessageBox.Show(showMsg, "TestLinkConverter", MessageBoxButtons.YesNo);

            if (result == DialogResult.No)
            {
                return;
            }

            Thread thread = new Thread(new ParameterizedThreadStart(SaveFileByDialog))
            {
                ApartmentState = ApartmentState.STA
            };

            thread.Start(this.filePathTb.Text);

            OutputDisplay.ShowMessage(showMsg, Color.Azure);

            this.progressBar.Value = this.progressBar.Minimum;
        }
예제 #12
0
        /// <summary>
        /// Node转为Model
        /// </summary>
        /// <param name="node">XML节点Node</param>
        /// <returns>TestCase Model</returns>
        private TestCase NodeToModel(XmlNode node)
        {
            TestCase tc = new TestCase();

            try
            {
                if (node.Attributes.Count != 1)
                {
                    tc.InternalId = node.Attributes["internalid"].Value;
                }
                tc.Name = node.Attributes["name"].Value;
            }
            catch (NullReferenceException ex)
            {
                this._logger.Error("用例名称为空", ex);
                OutputDisplay.ShowMessage("用例名称为空", Color.Red);
            }


            foreach (XmlNode xmlNode in node)
            {
                switch (xmlNode.Name)
                {
                case "node_order":
                    tc.NodeOrder = xmlNode.InnerText;
                    break;

                case "externalid":
                    tc.ExternalId = xmlNode.InnerText;
                    break;

                case "version":
                    tc.Version = xmlNode.InnerText;
                    break;

                case "summary":
                    tc.Summary = CommonHelper.DelTags(xmlNode.InnerText);
                    break;

                case "preconditions":
                    tc.Preconditions = CommonHelper.DelTags(xmlNode.InnerText);
                    break;

                case "execution_type":

                    tc.ExecutionType = CommonHelper.StrToExecType(xmlNode.InnerText);
                    break;

                case "importance":
                    tc.Importance = CommonHelper.StrToImportanceType(xmlNode.InnerText);
                    break;

                case "estimated_exec_duration":
                    if (xmlNode.InnerText.Equals(""))
                    {
                        tc.EstimatedExecDuration = 0.0;
                        break;
                    }
                    tc.EstimatedExecDuration = double.Parse(xmlNode.InnerText);
                    break;

                case "status":
                    tc.Status = (StatusType)int.Parse(xmlNode.InnerText);
                    break;

                case "steps":
                    tc.TestSteps = this.GetAllSteps(xmlNode);
                    break;

                //TODO KeyWords未解析
                //TODO Requirements未解析
                default:
                    break;
                }
            }
            return(tc);
        }