Exemplo n.º 1
0
        /// <summary>
        /// 创建执行案例
        /// </summary>
        /// <param name="sheet">sheet页</param>
        /// <param name="sceneID">场景ID</param>
        private static void insertRunCase(QCTESTEntities QC_DB, ISheet sheet, int sceneID)
        {
            int ID = Convert.ToInt32(sheet.SheetName);

            M_testCase mtc = QC_DB.M_testCase.Where(t => t.ID == ID).FirstOrDefault();

            if (mtc == null)
            {
                return;
            }



            System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
            //读取下一行
            rows.MoveNext();//如果没有要处理下
            IRow headRow = (IRow)rows.Current;



            Dictionary <string, string> data = new Dictionary <string, string>();
            List <string> keys = new List <string>();

            //首先获得参数列表
            for (int i = 1; i < headRow.LastCellNum; i++)
            {
                ICell cell = headRow.GetCell(i);
                if (cell == null || cell.ToString() == "")
                {
                    break;                                       //有空数据直接退出
                }
                string key = cell.ToString();
                data.Add(key, "");
                keys.Add(key);
            }

            //逐行转化案例
            while (rows.MoveNext())
            {
                IRow row = (IRow)rows.Current;
                if (row.GetCell(0) == null || row.GetCell(0).StringCellValue.Trim() == "")
                {
                    break;                                                                       //案例名字没有退出
                }
                string caseName = row.GetCell(0).StringCellValue;
                if (caseName.Length > 50)
                {
                    caseName = caseName.Substring(0, 50);
                }
                XElement cloneXML = XElement.Parse(mtc.testXML);
                cloneXML.SetAttributeValue("name", caseName);//name

                for (int i = 1; i < keys.Count; i++)
                {
                    ICell  cell  = row.GetCell(i);
                    string value = "";
                    if (cell != null)
                    {
                        //cell = eva.EvaluateInCell(cell);
                        cell.SetCellType(CellType.String);
                        value = cell.StringCellValue;
                    }
                    data[keys[i]] = value;
                }



                //获得最终案例
                cloneXML.getRunScript(data);

                //放入数据库

                M_runTestCase mrtc = new M_runTestCase();
                mrtc.sceneID = sceneID;
                mrtc.testXML = cloneXML.ToString();
                mrtc.name    = caseName;
                QC_DB.M_runTestCase.Add(mrtc);
            }
        }
Exemplo n.º 2
0
        private static List <T> getRunScript <T>(M_testCase mtc, ISheet sheet, int sceneID = 0)
            where T : class
        {
            List <T> result = new List <T>();


            int ID = Convert.ToInt32(sheet.SheetName);


            System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
            //读取下一行
            rows.MoveNext();//如果没有要处理下
            IRow headRow = (IRow)rows.Current;



            Dictionary <string, string> data = new Dictionary <string, string>();
            List <string> keys = new List <string>();

            //首先获得参数列表
            for (int i = 1; i < headRow.LastCellNum; i++)
            {
                ICell cell = headRow.GetCell(i);
                if (cell == null || cell.ToString() == "")
                {
                    break;                                       //有空数据直接退出
                }
                string key = cell.ToString();
                data.Add(key, "");
                keys.Add(key);
            }

            //逐行转化案例
            while (rows.MoveNext())
            {
                IRow row = (IRow)rows.Current;
                if (row.GetCell(0) == null || row.GetCell(0).StringCellValue.Trim() == "")
                {
                    break;                                                                       //案例名字没有退出
                }
                string caseName = row.GetCell(0).StringCellValue;
                if (caseName.Length > 50)
                {
                    caseName = caseName.Substring(0, 50);
                }
                XElement cloneXML = XElement.Parse(mtc.testXML);
                cloneXML.SetAttributeValue("name", caseName);//name

                for (int i = 0; i < keys.Count; i++)
                {
                    ICell  cell  = row.GetCell(i + 1);
                    string value = "";
                    if (cell != null)
                    {
                        //cell = eva.EvaluateInCell(cell);
                        cell.SetCellType(CellType.String);
                        value = cell.StringCellValue;
                    }
                    data[keys[i]] = value;
                }


                //获得最终案例
                cloneXML.getRunScript(data);

                if (typeof(T) == typeof(M_runTestCase))
                {
                    M_runTestCase mrtc = new M_runTestCase();
                    mrtc.sceneID = sceneID;
                    mrtc.testXML = cloneXML.ToString();
                    mrtc.name    = caseName;
                    result.Add(mrtc as T);
                }
                else if (typeof(T) == typeof(tmp_TaskScript))
                {
                    tmp_TaskScript mrtc = new tmp_TaskScript();
                    mrtc.title  = caseName;
                    mrtc.script = cloneXML.ToString();
                    result.Add(mrtc as T);
                }
            }
            return(result);
        }