コード例 #1
0
        /// <summary>
        /// 获取框架步骤
        /// </summary>
        /// <param name="FID"></param>
        /// <returns></returns>
        public static string getFrameControl(int?FID)
        {
            QCTESTEntities QC_DB = new QCTESTEntities();

            List <caseFramework> ss = new List <caseFramework>();

            if (FID == null)//没有指定框架就是全框架
            {
                ss = (from t in QC_DB.caseFramework
                      where t.userID == 1
                      select t).ToList();
            }
            else
            {
                ss = (from t in QC_DB.caseFramework
                      where t.ID == FID
                      select t).ToList();
            }


            List <treeViewModel> Fdata = new List <treeViewModel>();

            foreach (var s in ss)
            {
                var treeNode = s.getControlJson4Tree();
                Fdata.Add(treeNode);
            }

            JsonSerializerSettings jSetting = new JsonSerializerSettings();

            jSetting.NullValueHandling = NullValueHandling.Ignore;

            return(JsonConvert.SerializeObject(Fdata, jSetting));
        }
コード例 #2
0
        /// <summary>
        /// 获取项目步骤
        /// </summary>
        /// <param name="PID"></param>
        /// <param name="FID"></param>
        /// <returns></returns>
        public static string getProjectControl(int PID, int FID)
        {
            QCTESTEntities QC_DB = new QCTESTEntities();

            var fps = (from t in QC_DB.Framework4Project
                       where t.PID == PID && t.FID == FID
                       select t).ToList();

            List <scriptStepTreeModel> lss = new List <scriptStepTreeModel>();

            scriptStepTreeModel rootnode = new scriptStepTreeModel();

            var p = QC_DB.project.First(t => t.ID == PID);

            rootnode.text  = p.Pname;
            rootnode.PID   = p.ID;
            rootnode.state = "open";

            rootnode.children = new List <treeViewModel>();
            foreach (var fp in fps)
            {
                rootnode.children.Add(fp.getControlJson4Tree());
            }
            if (rootnode.children.Count > 0)
            {
                lss.Add(rootnode);
            }

            JsonSerializerSettings jSetting = new JsonSerializerSettings();

            jSetting.NullValueHandling = NullValueHandling.Ignore;

            return(JsonConvert.SerializeObject(lss, jSetting));
        }
コード例 #3
0
ファイル: treeHelper.cs プロジェクト: afzheng/openCaseMaster
        public static string getUserControl()
        {
            int userID = userHelper.getUserID();

            int[] Permission = userHelper.getUserPermission();


            using (QCTESTEntities QC_DB = new QCTESTEntities())
            {
                //我的组件
                var myControls = (from t in QC_DB.M_testCaseSteps
                                  where t.userID == userID
                                  select t).ToList();
                var frames = (from t in QC_DB.caseFramework
                              where t.userID == 1
                              select t).ToList();

                var pjs = (from t in QC_DB.project
                           where Permission.Contains(t.ID)
                           select t).ToList();


                return(getUserControl(myControls, frames, pjs));
            }
        }
コード例 #4
0
        /// <summary>
        /// 获取projectStep的参数列表
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static XElement getProjectStepParam(string name)
        {
            int stepID = Convert.ToInt32(name.Substring(8));
            //这里是用户控件初始化
            QCTESTEntities    QC_DB = new QCTESTEntities();
            Framework4Project mtcs  = QC_DB.Framework4Project.Where(t => t.ID == stepID).First();
            var xe = XElement.Parse(mtcs.controlXML);

            xe.SetAttributeValue("name", "prostep_" + mtcs.ID);



            XElement PB = new XElement("ParamBinding");

            PB.SetAttributeValue("name", "是否启用");
            PB.SetAttributeValue("value", "true");
            PB.SetAttributeValue("list", "启用:true,不启用:false");


            xe.Add(PB);



            //mtcs.paramXML.SetAttributeValue("name", name);
            return(xe);
        }
コード例 #5
0
        /// <summary>
        /// 通过stepName获得StepXml(非属性节点,而是真实的)
        /// </summary>
        /// <param name="stepName"></param>
        /// <returns></returns>
        public static XElement getUserStepRealXml(string stepName)
        {
            int stepID = Convert.ToInt32(stepName.Substring(9));
            //这里是用户控件初始化
            QCTESTEntities  QC_DB = new QCTESTEntities();
            M_testCaseSteps mtcs  = QC_DB.M_testCaseSteps.Where(t => t.ID == stepID).First();

            return(XElement.Parse(mtcs.stepXML));
        }
コード例 #6
0
        /// <summary>
        /// 创建场景
        /// </summary>
        public static void creatScene(Stream MS, int DemandID, string name)
        {
            QCTESTEntities QC_DB = new QCTESTEntities();

            M_runScene mrs = new M_runScene();

            mrs.DemandID  = DemandID;
            mrs.name      = name;
            mrs.creatDate = DateTime.Now;
            QC_DB.M_runScene.Add(mrs);



            HSSFWorkbook hssfworkbook = new HSSFWorkbook(MS);


            HSSFFormulaEvaluator eva = new HSSFFormulaEvaluator(hssfworkbook);

            //eva.EvaluateInCell(cell);//取结果不取公式
            eva.EvaluateAll();//取结果不取公式

            ISheet sheet = hssfworkbook.GetSheetAt(0);

            System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
            rows.MoveNext();



            while (rows.MoveNext())
            {
                IRow   row       = (IRow)rows.Current;
                string sheetName = row.GetCell(1).ToString();
                if (sheetName == null || sheetName.Trim() == "")
                {
                    break;
                }

                ISheet caseSheet = hssfworkbook.GetSheet(sheetName);

                //找不到相关案例的话直接下一条
                int        ID  = Convert.ToInt32(caseSheet.SheetName);
                M_testCase mtc = QC_DB.M_testCase.Where(t => t.ID == ID).FirstOrDefault();
                if (mtc == null)
                {
                    continue;
                }

                var rts = getRunScript <M_runTestCase>(mtc, caseSheet, mrs.ID);
                QC_DB.M_runTestCase.AddRange(rts);
            }

            QC_DB.SaveChanges();
        }
コード例 #7
0
        /// <summary>
        /// 获取projectStep的参数列表
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static XElement getProjectStepParam(string name)
        {
            int stepID = Convert.ToInt32(name.Substring(8));
            //这里是用户控件初始化
            QCTESTEntities    QC_DB = new QCTESTEntities();
            Framework4Project mtcs  = QC_DB.Framework4Project.Where(t => t.ID == stepID).First();
            var xe = XElement.Parse(mtcs.controlXML);

            xe.SetAttributeValue("name", "prostep_" + mtcs.ID);


            //mtcs.paramXML.SetAttributeValue("name", name);
            return(xe);
        }
コード例 #8
0
        public static List <tmp_TaskScript> tmpTaskScript(Stream MS)
        {
            List <tmp_TaskScript> result = new List <tmp_TaskScript>();

            HSSFWorkbook hssfworkbook = new HSSFWorkbook(MS);


            HSSFFormulaEvaluator eva = new HSSFFormulaEvaluator(hssfworkbook);

            //eva.EvaluateInCell(cell);//取结果不取公式
            eva.EvaluateAll();//取结果不取公式

            ISheet sheet = hssfworkbook.GetSheetAt(0);

            System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
            rows.MoveNext();



            QCTESTEntities QC_DB = new QCTESTEntities();

            while (rows.MoveNext())
            {
                IRow   row       = (IRow)rows.Current;
                string sheetName = row.GetCell(1).ToString();
                if (sheetName == null || sheetName.Trim() == "")
                {
                    break;
                }

                ISheet caseSheet = hssfworkbook.GetSheet(sheetName);

                //找不到相关案例的话直接下一条
                int        ID  = Convert.ToInt32(caseSheet.SheetName);
                M_testCase mtc = QC_DB.M_testCase.Where(t => t.ID == ID).FirstOrDefault();
                if (mtc == null)
                {
                    continue;
                }

                var rts = getRunScript <tmp_TaskScript>(mtc, caseSheet);
                QC_DB.tmp_TaskScript.AddRange(rts);
                result.AddRange(rts);
            }

            QC_DB.SaveChanges();

            return(result);
        }
コード例 #9
0
        /// <summary>
        /// 获取UserStep的参数列表
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static XElement getUserStepParam(string name)
        {
            //if (!isUserStep(name)) return;//是否有必要?

            int stepID = Convert.ToInt32(name.Substring(9));
            //这里是用户控件初始化
            QCTESTEntities  QC_DB = new QCTESTEntities();
            M_testCaseSteps mtcs  = QC_DB.M_testCaseSteps.Where(t => t.ID == stepID).First();
            var             xe    = XElement.Parse(mtcs.paramXML);

            xe.SetAttributeValue("name", "userstep_" + mtcs.ID);
            xe.SetAttributeValue("desc", mtcs.name);

            //mtcs.paramXML.SetAttributeValue("name", name);
            return(xe);
        }
コード例 #10
0
        /// <summary>
        /// 执行前转换项目组件(后期使用catch)
        /// </summary>
        /// <param name="name"></param>
        private static void changeProjectStep2Run(XElement step)
        {
            int id = Convert.ToInt32(step.Attribute("name").Value.Substring(8));


            QCTESTEntities    QC_DB = new QCTESTEntities();
            Framework4Project mtcs  = QC_DB.Framework4Project.FirstOrDefault(t => t.ID == id);

            if (mtcs == null)
            {
                return;
            }

            var xe = XElement.Parse(mtcs.controlXML);

            step.SetAttributeValue("name", xe.Attribute("name").Value);
        }
コード例 #11
0
        /// <summary>
        /// 获取基础框架,包括自动义
        /// </summary>
        /// <returns></returns>
        public static List <caseFramework> getBaseFrameworks()
        {
            int userID = getUserID();
            List <caseFramework> cfs = frameworkHelp.getAutoFramework();


            QCTESTEntities QC_DB = new QCTESTEntities();

            caseFramework cf = QC_DB.caseFramework.FirstOrDefault(t => t.userID == userID);

            if (cf != null)
            {
                cfs.Add(cf);
            }

            return(cfs);
        }
コード例 #12
0
        /// <summary>
        /// 获得场景Excel
        /// </summary>
        /// <param name="_tnc"></param>
        /// <returns></returns>
        public static MemoryStream getSceneExcelMS(List <int> ids)
        {
            HSSFWorkbook hssfworkbook = ExcelHelper.InitializeWorkbook();

            ISheet config = hssfworkbook.CreateSheet("配置表");

            IRow  row   = config.CreateRow(0);
            ICell cell0 = row.CreateCell(0);

            cell0.SetCellValue("案例名");

            ICell cell1 = row.CreateCell(1);

            cell1.SetCellValue("案例ID");

            ICell cell2 = row.CreateCell(2);

            cell2.SetCellValue("参数数量");

            config.SetColumnWidth(0, 30 * 256);

            QCTESTEntities QC_DB = new QCTESTEntities();

            foreach (int id in ids)
            {
                M_testCase mtc = (from t in QC_DB.M_testCase
                                  where t.ID == id
                                  select t).FirstOrDefault();
                if (mtc == null)
                {
                    continue;
                }
                var pdl = XElement.Parse(mtc.testXML).ParamDictionary();
                ExcelHelper.creatCaseSheet(hssfworkbook, pdl, mtc.ID.ToString(), mtc.Name);

                //name要做处理?
                ExcelHelper.creatConfigRow(config, mtc.Name, mtc.ID.ToString(), pdl.Count);
            }

            MemoryStream ms = new MemoryStream();

            hssfworkbook.Write(ms);

            return(ms);
        }
コード例 #13
0
        /// <summary>
        /// 获得有权限的项目
        /// </summary>
        public static IQueryable <project> getPermissionsProject()
        {
            int            userID = getUserID();
            QCTESTEntities QC_DB  = new QCTESTEntities();


            var pp = getUserPermission();


            if (HttpContext.Current.User.IsInRole("admin"))
            {
                return(QC_DB.project.Where(t => t.userID == null || t.userID == userID));
            }
            else
            {
                return(QC_DB.project.Where(t => pp.Contains(t.ID) || t.userID == userID));
            }
        }
コード例 #14
0
        public static void creatScene(Stream MS, int DemandID, string name)
        {
            QCTESTEntities QC_DB = new QCTESTEntities();

            M_runScene mrs = new M_runScene();

            mrs.DemandID  = DemandID;
            mrs.name      = name;
            mrs.creatDate = DateTime.Now;
            QC_DB.M_runScene.Add(mrs);



            HSSFWorkbook hssfworkbook = new HSSFWorkbook(MS);


            HSSFFormulaEvaluator eva = new HSSFFormulaEvaluator(hssfworkbook);

            //eva.EvaluateInCell(cell);//取结果不取公式
            eva.EvaluateAll();//取结果不取公式

            ISheet sheet = hssfworkbook.GetSheetAt(0);

            System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
            rows.MoveNext();



            while (rows.MoveNext())
            {
                IRow   row       = (IRow)rows.Current;
                string sheetName = row.GetCell(1).ToString();
                if (sheetName == null || sheetName.Trim() == "")
                {
                    break;
                }

                ISheet caseSheet = hssfworkbook.GetSheet(sheetName);

                insertRunCase(QC_DB, caseSheet, mrs.ID);
            }

            QC_DB.SaveChanges();
        }
コード例 #15
0
        /// <summary>
        /// 获取默认框架
        /// </summary>
        /// <returns></returns>
        public static List <caseFramework> getAutoFramework()
        {
            System.Web.Caching.Cache objCache = HttpRuntime.Cache;

            List <caseFramework> cfs = objCache.Get("Framework") as List <caseFramework>;

            if (cfs == null)
            {
                QCTESTEntities QC_DB = new QCTESTEntities();

                cfs = (from t in QC_DB.caseFramework
                       where t.userID == 1
                       select t).ToList();
                //10不操作分钟过期
                //objCache.Insert("Framework", cfs, null, DateTime.MaxValue, TimeSpan.FromMinutes(10));

                //强制10分钟过期
                objCache.Insert("Framework", cfs, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);
            }

            return(cfs);
        }
コード例 #16
0
        /// <summary>
        /// 获取可编辑的app
        /// </summary>
        /// <returns></returns>
        public static IQueryable <M_application> getApps()
        {
            QCTESTEntities QC_DB = new QCTESTEntities();

            IQueryable <M_application> apps;

            if (userHelper.isAdmin())
            {
                apps = QC_DB.M_application;
            }
            else
            {
                int[] pjs = userHelper.getUserPermission();



                apps = from t in QC_DB.project_app
                       where t.usable && pjs.Contains(t.PID)
                       select t.M_application;
            }

            return(apps);
        }
コード例 #17
0
        public static string getUserControl(int FID, int PID)
        {
            int userID = userHelper.getUserID();


            QCTESTEntities QC_DB = new QCTESTEntities();


            //我的组件
            var myControls = (from t in QC_DB.M_testCaseSteps
                              where t.userID == userID
                              select t).ToList();
            var frames = (from t in QC_DB.caseFramework
                          where t.userID == 1 && t.ID == FID
                          select t).ToList();

            var pjs = (from t in QC_DB.project
                       where t.ID == PID
                       select t).ToList();


            return(getUserControl(myControls, frames, pjs));
        }
コード例 #18
0
        /// <summary>
        /// 获得基础组件xml
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static XElement getFarmeworkStep(string name, int FID)
        {
            QCTESTEntities QC_DB = new QCTESTEntities();

            var      cf = QC_DB.caseFramework.First(t => t.ID == FID);
            XElement xe = XElement.Parse(cf.controlXML);


            var step = xe.Descendants("Step").FirstOrDefault(t => t.Attribute("name").Value == name);

            if (step != null)
            {
                XElement PB = new XElement("ParamBinding");
                PB.SetAttributeValue("name", "是否启用");
                PB.SetAttributeValue("value", "true");
                PB.SetAttributeValue("list", "启用:true,不启用:false");


                step.Add(PB);
                return(step);
            }

            return(null);
        }
コード例 #19
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);
            }
        }
コード例 #20
0
        public static int noRunCaseNum(this M_testDemand td)
        {
            QCTESTEntities QC_DB = new QCTESTEntities();

            return(QC_DB.M_runTestCase.Where(t => t.M_runScene.M_testDemand.ID == td.ID && t.state == null).Count());
        }