public TestCasesFromSuits TestCaseFromSuit(string testPlanId, string suitId) { TestCasesFromSuits testData = new TestCasesFromSuits(); try { string OrganizationName = Org.OrganizationName; string Pat = Org.pat; string BaseAddress = "https://dev.azure.com/"; string projectName = Org.ProjectName; string api = string.Format("https://dev.azure.com/{0}/{1}/_apis/testplan/Plans/{2}/Suites/{3}/TestCase?api-version=5.1-preview.2", Org.OrganizationName, Org.ProjectName, testPlanId, suitId);//TempCredintials.OrganizationName,TempCredintials.ProjectName,testPlanId, suitId); using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Org.pat);//TempCredintials.pat ); //Org.pat HttpResponseMessage response = client.GetAsync(api).Result; if (response.IsSuccessStatusCode) { var obj = response.Content.ReadAsStringAsync().Result; testData = JsonConvert.DeserializeObject <TestCasesFromSuits>(obj); } } } catch (Exception ex) { } return(testData); }
public JsonResult GetTestCasesFromSuits(string planId, string suitid) { TestCasesFromSuits dataretrive = new TestCasesFromSuits(); dataretrive = logic.TestCaseFromSuit(planId, suitid); return(Json(dataretrive, JsonRequestBehavior.AllowGet)); }
/// <summary> /// To Get the Test Suits From Test Plan /// </summary> /// <param name="planid"></param> /// <returns></returns> public JsonResult GetTestSuits(string planid) { List <TestRunById> runStore; List <TestResult> TestList = new List <TestResult>(); ListClass listRun = new ListClass(); TestResult ResultObjListStore = new TestResult(); try { List <TestRunById> RunList = new List <TestRunById>(); ResultObj.PassCount = 0; ResultObj.FailCount = 0; ResultObj.TestCaseCount = 0; TestRunProject testProData = logic.GetRunByProject(); foreach (var test in testProData.value) { TestRunById runData = logic.GetRunByRunId(test.id.ToString()); RunList.Add(runData); ListClass.RunList.Add(runData); } //project level run TestSuit dataretrive = new TestSuit(); dataretrive = logic.TestSuit(planid); foreach (var inf in dataretrive.value) { runStore = new List <TestRunById>(); TestCasesFromSuits testresult = logic.TestCaseFromSuit(inf.plan.id.ToString(), inf.id.ToString()); foreach (var test in testresult.value) { List <int> maxStore = new List <int>(); // List<string> runStore = new List<string>(); foreach (var run in RunList) { foreach (var run1 in run.value) { if (run1.testCase.id.ToString() == test.workItem.id.ToString()) { // TestResult.TestCaseList.Add(testresult); //TestResult.TestRun.Add(run); int runid = Convert.ToInt32(run1.testRun.id); maxStore.Add(runid); runStore.Add(run); } } } if (maxStore != null && maxStore.Count > 0) { var maxId = maxStore.Max(); //RunList.Find(); // TestRunById dataQuery =new TestRunById(); string outcome1 = string.Empty; foreach (var i in RunList) { // var dataQuery = i.value.Find(x => x.testRun.id == maxId.ToString()); foreach (var k in i.value) { if (k.testRun.id == maxId.ToString()) { outcome1 = k.outcome.ToString(); } } } string outcome = outcome1.ToString(); if (outcome == "Passed") { ResultObj.PassCount = ResultObj.PassCount + 1; } else if (outcome == "Failed") { ResultObj.FailCount = ResultObj.FailCount + 1; } } ResultObj.TestCaseCount = ResultObj.TestCaseCount + 1; } double passPercentageBasedExec; double passPercentageBasedPlanned; double failPercentage; double executedPercentage; double executed = ResultObj.PassCount + ResultObj.FailCount; if (executed != 0) { passPercentageBasedExec = ((ResultObj.PassCount / executed) * 100); } else { passPercentageBasedExec = 0; } if (ResultObj.PassCount != 0 && ResultObj.TestCaseCount != 0) { passPercentageBasedPlanned = ((ResultObj.PassCount / ResultObj.TestCaseCount) * 100); } else { passPercentageBasedPlanned = 0; } if (executed != 0) { failPercentage = ((ResultObj.FailCount / executed) * 100); } else { failPercentage = 0; } if (ResultObj.TestCaseCount != 0) { executedPercentage = ((executed / ResultObj.TestCaseCount) * 100); } else { executedPercentage = 0; } double notExecuted = ResultObj.TestCaseCount - executed; int passPercentageBasedExecConvert = (int)Math.Round(passPercentageBasedExec); //Convert.ToInt32(passPercentageBasedExec); int passPercentageBasedPlannedConvert = (int)Math.Round(passPercentageBasedPlanned); //Convert.ToInt32(passPercentageBasedPlanned); int failPercentageConvert = Convert.ToInt32(failPercentage); int executedPercentageConvert = (int)Math.Round(executedPercentage); //Convert.ToInt32(executedPercentage); // i = (int)Math.Round(x / y); TestResult DataResult = ResultStore(inf.id.ToString(), inf.name, ResultObj.TestCaseCount.ToString(), ResultObj.PassCount, ResultObj.FailCount, executed.ToString(), passPercentageBasedExecConvert, passPercentageBasedPlannedConvert, notExecuted.ToString(), executedPercentageConvert); DataResult.TestRun = runStore; TestList.Add(DataResult); ResultObj.PassCount = 0; ResultObj.FailCount = 0; ResultObj.TestCaseCount = 0; } // ViewBag.datastore = dataretrive; ViewBag.data1234 = dataretrive; Session["responsedata"] = dataretrive; // return View("TestDisplay"); } catch (Exception ex) { } return(Json(TestList, JsonRequestBehavior.AllowGet)); }
public JsonResult TestCasesFromTestSuit(string testPlanId, string testSuitId) { TestCasesFromSuits testresult = logic.TestCaseFromSuit(testPlanId, testSuitId); // TestRunById testrun = new TestRunById(); List <TestRunById> RunList = new List <TestRunById>(); TestRunProject testProData = logic.GetRunByProject(); foreach (var test in testProData.value) { TestRunById runData = logic.GetRunByRunId(test.id.ToString()); RunList.Add(runData); ListClass.RunList.Add(runData); } string outcome1 = string.Empty; foreach (var test in testresult.value) { TestCaseStoreSub dataStore1 = new TestCaseStoreSub(); List <int> maxStore = new List <int>(); // List<string> runStore = new List<string>(); foreach (var run in RunList) { foreach (var run1 in run.value) { if (run1.testCase.id == null || run1.testCase.id == "") { } else { if (run1.testCase.id.ToString() == test.workItem.id.ToString()) { //TestResult.TestCaseList.Add(testresult); //TestResult.TestRun.Add(run); int runid = Convert.ToInt32(run1.testRun.id); maxStore.Add(runid); // runStore.Add(run); } } } } if (maxStore == null || maxStore.Count <= 0) { outcome1 = "Not Yet Runned"; } if (maxStore != null && maxStore.Count > 0) { var maxId = maxStore.Max(); //RunList.Find(); // TestRunById dataQuery =new TestRunById(); foreach (var i in RunList) { // var dataQuery = i.value.Find(x => x.testRun.id == maxId.ToString()); foreach (var k in i.value) { if (k.testRun.id == maxId.ToString()) { if (k.outcome != null) { outcome1 = k.outcome.ToString(); //dataStore1.ID = test.workItem.id.ToString(); //dataStore1.Name = test.workItem.name.ToString(); //dataStore1.Outcome = outcome1; } else { outcome1 = "Not Yet runned"; } } } } } dataStore1 = caseResultStore(test.workItem.id.ToString(), test.workItem.name.ToString(), outcome1); dataStoreList.Add(dataStore1); } // return(Json(dataStoreList, JsonRequestBehavior.AllowGet)); }