public async void PostUserTestRun(TblUserTestRun tblUserTestRun) { using (IDbConnection dbConnection = _connectionFactory.GetConnection()) { dbConnection.Open(); var urls = await dbConnection.ExecuteAsync("Insert into tblUserTestRun(TestGroupId, TestRunId, Username, PackId, RunDate, RunAt) values('" + tblUserTestRun.testgroupid + "', '" + tblUserTestRun.testrunid + "','" + tblUserTestRun.username + "','" + tblUserTestRun.packid + "', now(), '" + tblUserTestRun.runat + "')"); } }
public async Task <string> RunSuite([FromBody] List <RunSuiteViewModel> runsuites) { try { string IPAddress = GetIP(); IPAddress = GetLocalIPAddress(); string IPAddress1 = GetIPAddress(); string ipAddressforRunSuite = runsuites.FirstOrDefault().IpAddress; //_accessor.HttpContext.Connection.RemoteIpAddress.ToString(); List <CommonViewModel> environments = _runsuiteRepository.GetEnvironemnts().Result.Select(x => x.ToViewModel()).ToList(); foreach (var item in runsuites) { TblPacks tblPacks = await _runsuiteRepository.GetPackByPackId(item.PackId); string selectedEnvironmentId = environments.Where(x => x.Name == item.DefaultEnvironment).FirstOrDefault().Id; List <string> subscenariosIds = new List <string>(); string packName = string.Empty; string projectName = _runsuiteRepository.GetProjectNameByProjectId(item.ProjectId).Result; string scenarios = string.Empty; if (string.IsNullOrEmpty(tblPacks.scenario_subscenario)) { CleanTestSteps(item.ProjectId); List <String> subScenariosResults = _runsuiteRepository.GetSubScenariosByPackId(item.PackId).Result.ToList(); string subScenariosIds = String.Join(',', subScenariosResults); string subScenarios = string.Join(",", subScenariosIds.Split(',').Select(x => string.Format("'{0}'", x)).ToList()); var scenarioResults = _runsuiteRepository.GetScenariosByPackId(item.PackId).Result; string scenarioIds = string.Join(',', scenarioResults); scenarios = string.Join(",", scenarioIds.Split(',').Select(x => string.Format("'{0}'", x)).ToList()); packName = _runsuiteRepository.GetPackNameByPackId(item.PackId).Result; subscenariosIds = _runsuiteRepository.GetSubScenIdBySubScenarioIdAndProjectId(subScenarios, item.ProjectId).Result.ToList(); } else { packName = tblPacks.packname; List <RunSuiteScenarioViewModel> scenario_subscenario = JsonConvert.DeserializeObject <List <RunSuiteScenarioViewModel> >(tblPacks.scenario_subscenario); List <String> lstscnIds = scenario_subscenario.Select(x => x.Id).ToList(); List <RunSuiteSubScenarioViewModel> lstsubsceneIds = scenario_subscenario.SelectMany(x => x.SubScenerio).ToList(); subscenariosIds = lstsubsceneIds.Select(x => x.Id).ToList(); String scnIds = string.Join(",", lstscnIds); scenarios = string.Join(",", scnIds.Split(',').Select(x => string.Format("'{0}'", x)).ToList()); } if (item.ParallelExecution) { List <String>[] lst = Partition(subscenariosIds, 4); string grpTestRunId = "Grp" + DateTime.Now.ToString("yyyyMMddHHmmssfff", CultureInfo.InvariantCulture); for (int z = 0; z < 4; z++) { foreach (var nodes in item.RunAt) { string testRunId = DateTime.Now.ToString("yyyyMMddHHmmssfff", CultureInfo.InvariantCulture); TblNode tblNodeData = _runsuiteRepository.GetNodesData(nodes.Name).Result; TblUserTestRun tblUserTestRun = new TblUserTestRun { testgroupid = grpTestRunId, testrunid = testRunId, username = getUser.UserName.Replace(" ", String.Empty), packid = item.PackId, runat = nodes.Name }; _runsuiteRepository.PostUserTestRun(tblUserTestRun); List <TblTestSteps> testSteps = new List <TblTestSteps>(); string subsceneswithParallelExecution = string.Join(",", lst[z]); List <TblTestRunTemp> tblTestRunTmp = new List <TblTestRunTemp>(); testSteps = new List <TblTestSteps>(); List <TblTestSteps> tblTestSteps = new List <TblTestSteps>(); foreach (var subscneIds in lst[z]) { var tblSteps = _runsuiteRepository.GetTestStepsBySceneIdAndSubSceneId(scenarios, subscneIds, tblNodeData.nodeIp, tblNodeData.nodePortNo).Result.ToList(); foreach (var zt in tblSteps) { tblTestSteps.Add(zt); } } foreach (var i in tblTestSteps) { var count = testSteps.Where(x => x.teststepid == i.teststepid).Count(); if (count == 0) { i.testdata = string.IsNullOrEmpty(i.testdata) ? string.Empty : i.testdata.Replace("'", "''"); i.objectvalue = string.IsNullOrEmpty(i.objectvalue) ? string.Empty : i.objectvalue.Replace("'", "''"); i.description = string.IsNullOrEmpty(i.description) ? string.Empty : i.description.Replace("'", "''"); } string stpId = string.Empty; if (int.TryParse(i.teststepid, out int n)) { //"CDE_SCEN_02_SUB_09_STEP_08" if (int.TryParse(i.mainscenarioid, out int c)) { stpId += i.projectcode + "_" + "SCEN" + "_" + i.mainscenarioid; } if (int.TryParse(i.subscenarioid, out int d)) { if (!int.TryParse(i.mainscenarioid, out int f)) { stpId += i.mainscenarioid; } stpId = stpId + "_" + "SUB" + "_" + i.subscenarioid; } else { stpId = i.subscenarioid; } stpId = stpId + "_" + "STEP" + "_" + i.teststepid; i.teststepid = stpId; } testSteps.Add(i); } if (nodes.Name == "Local Node") { int count = 1; foreach (var rows in testSteps) { TblTestRunTemp tblTestRunTemp = new TblTestRunTemp { packid = item.PackId, packname = packName, projectid = item.ProjectId, projectname = projectName, environment = selectedEnvironmentId, stepno = count.ToString(), teststepid = rows.teststepid, keyword = rows.actionname, objectname = rows.objectname, testdata = rows.testdata, objectvalue = rows.objectvalue, decription = rows.description, runmode = rows.runmode, status = rows.status, runat = ipAddressforRunSuite, portno = "5555", browser = item.DefaultBrowser, testrunid = testRunId, scan_id = rows.scen_id, sub_scan_id = rows.sub_scen_id, testgroupid = grpTestRunId }; tblTestRunTmp.Add(tblTestRunTemp); count = count + 1; } } else { int count = 1; foreach (var rows in testSteps) { TblTestRunTemp tblTestRunTemp = new TblTestRunTemp { packid = item.PackId, packname = packName, projectid = item.ProjectId, projectname = projectName, environment = selectedEnvironmentId, stepno = count.ToString(), teststepid = rows.teststepid, keyword = rows.actionname, objectname = rows.objectname, testdata = rows.testdata, objectvalue = rows.objectvalue, decription = rows.description, runmode = rows.runmode, status = rows.status, runat = tblNodeData.hostIp, portno = tblNodeData.hostPortNo, browser = item.DefaultBrowser, testrunid = testRunId, scan_id = rows.scen_id, sub_scan_id = rows.sub_scen_id, testgroupid = grpTestRunId }; tblTestRunTmp.Add(tblTestRunTemp); count = count + 1; } } var returndata = await _runsuiteRepository.PostTestRunTemp(tblTestRunTmp); NameValueCollection nvc = new NameValueCollection(); nvc.Add("userId", getUser.UserName.Replace(" ", String.Empty)); nvc.Add("packId", item.PackId); nvc.Add("testRunId", testRunId); nvc.Add("testGroupId", grpTestRunId); string url = _iconfiguration.GetValue <string>("AppSettings:RunSuite");//"http://10.70.10.147:8080/SKUAWeb/TestEngine/FrameWork/RunPackWithIds"; url += ToQueryString(nvc); GetMethodCall(url); } } } else { foreach (var nodes in item.RunAt) { string grpTestRunId = "Grp" + DateTime.Now.ToString("yyyyMMddHHmmssfff", CultureInfo.InvariantCulture); string testRunId = DateTime.Now.ToString("yyyyMMddHHmmssfff", CultureInfo.InvariantCulture); TblNode tblNodeData = _runsuiteRepository.GetNodesData(nodes.Name).Result; TblUserTestRun tblUserTestRun = new TblUserTestRun { testgroupid = grpTestRunId, testrunid = testRunId, username = getUser.UserName.Replace(" ", String.Empty), packid = item.PackId, runat = nodes.Name }; _runsuiteRepository.PostUserTestRun(tblUserTestRun); List <TblTestSteps> testSteps = new List <TblTestSteps>(); List <TblTestRunTemp> tblTestRunTmp = new List <TblTestRunTemp>(); testSteps = new List <TblTestSteps>(); foreach (var subscneIds in subscenariosIds) { List <TblTestSteps> tblTestSteps = _runsuiteRepository.GetTestStepsBySceneIdAndSubSceneId(scenarios, subscneIds, tblNodeData.nodeIp, tblNodeData.nodePortNo).Result.ToList(); foreach (var i in tblTestSteps) { var count = testSteps.Where(x => x.teststepid == i.teststepid).Count(); if (count == 0) { i.testdata = string.IsNullOrEmpty(i.testdata)?string.Empty: i.testdata.Replace("'", "''"); i.objectvalue = string.IsNullOrEmpty(i.objectvalue)?string.Empty: i.objectvalue.Replace("'", "''"); i.description = string.IsNullOrEmpty(i.description)?string.Empty: i.description.Replace("'", "''"); } string stpId = string.Empty; if (int.TryParse(i.teststepid, out int n)) { //"CDE_SCEN_02_SUB_09_STEP_08" if (int.TryParse(i.mainscenarioid, out int c)) { stpId += i.projectcode + "_" + "SCEN" + "_" + i.mainscenarioid; } if (int.TryParse(i.subscenarioid, out int d)) { if (!int.TryParse(i.mainscenarioid, out int f)) { stpId += i.mainscenarioid; } stpId = stpId + "_" + "SUB" + "_" + i.subscenarioid; } else { stpId = i.subscenarioid; } stpId = stpId + "_" + "STEP" + "_" + i.teststepid; i.teststepid = stpId; } testSteps.Add(i); } } if (nodes.Name == "Local Node") { int count = 1; foreach (var rows in testSteps) { TblTestRunTemp tblTestRunTemp = new TblTestRunTemp { packid = item.PackId, packname = packName, projectid = item.ProjectId, projectname = projectName, environment = selectedEnvironmentId, stepno = count.ToString(), teststepid = rows.teststepid, keyword = rows.actionname, objectname = rows.objectname, testdata = rows.testdata, objectvalue = rows.objectvalue, decription = rows.description, runmode = rows.runmode, status = rows.status, runat = ipAddressforRunSuite, portno = "5555", browser = item.DefaultBrowser, testrunid = testRunId, scan_id = rows.scen_id, sub_scan_id = rows.sub_scen_id, testgroupid = grpTestRunId }; tblTestRunTmp.Add(tblTestRunTemp); count = count + 1; } } else { int count = 1; foreach (var rows in testSteps) { TblTestRunTemp tblTestRunTemp = new TblTestRunTemp { packid = item.PackId, packname = packName, projectid = item.ProjectId, projectname = projectName, environment = selectedEnvironmentId, stepno = count.ToString(), teststepid = rows.teststepid, keyword = rows.actionname, objectname = rows.objectname, testdata = rows.testdata, objectvalue = rows.objectvalue, decription = rows.description, runmode = rows.runmode, status = rows.status, runat = tblNodeData.hostIp, portno = tblNodeData.hostPortNo, browser = item.DefaultBrowser, testrunid = testRunId, scan_id = rows.scen_id, sub_scan_id = rows.sub_scen_id, testgroupid = grpTestRunId }; tblTestRunTmp.Add(tblTestRunTemp); count = count + 1; } } var returndata = await _runsuiteRepository.PostTestRunTemp(tblTestRunTmp); NameValueCollection nvc = new NameValueCollection(); nvc.Add("userId", getUser.UserName.Replace(" ", String.Empty)); nvc.Add("packId", item.PackId); nvc.Add("testRunId", testRunId); nvc.Add("testGroupId", grpTestRunId); string url = _iconfiguration.GetValue <string>("AppSettings:RunSuite");// System.Configuration.ConfigurationManager.AppSettings["APIQAURL"];// "http://10.70.10.147:8080/SKUAWeb/TestEngine/FrameWork/RunPackWithIds"; url += ToQueryString(nvc); GetMethodCall(url); } } } return("success"); } catch (Exception Ex) { throw Ex; } }