/// <summary> /// To Retrive TestCase with the testcase id /// </summary> /// <param name="testCaseId"></param> /// <returns></returns> public WorkItemsClass TestCaseRetrive(string testCaseId) { WorkItemsClass Result = new WorkItemsClass(); try { string api = string.Format("https://dev.azure.com/{0}/{1}/_apis/wit/workitems/{2}?api-version=5.0", Org.OrganizationName, Org.ProjectName, testCaseId); ClientRequest c1 = new ClientRequest(); var response = c1.GetResponseMethod(api); if (response.IsSuccessStatusCode) { var obj = response.Content.ReadAsStringAsync().Result; var Message = response.Content.ReadAsStringAsync(); Result = JsonConvert.DeserializeObject <WorkItemsClass>(obj); return(Result); } return(Result); } catch { return(Result); } }
public JsonResult DestCopyTest(List <jsonResp> testcase, string testPlan, string testSuit) { CreateTest t1 = new CreateTest(); foreach (var item in testcase) { WorkItemsClass testcaseItem = logic.TestCaseRetrive(item.id); //getting the details of the testcase with the ID //after we get the details from of the id,we should create a new testcase TestCaseResponseModel testResponse = t1.TestCaseCreate(testcaseItem); if (testResponse != null) { t1.AddtoTestCaseToTestSuit(testPlan, testSuit, testResponse.id.ToString()); } } bool result = false; if (CheckValid.AddTestcase == true) { result = true; } else { result = false; } return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult TestRunFromTestCase(string testCaseId) { List <TestRunPartial> testrunStoreList = new List <TestRunPartial>(); TestRunById testrun = new TestRunById(); List <TestRunById> testrunList = new List <TestRunById>(); List <TestRunById> runStore; List <TestRunById> RunList = new List <TestRunById>(); //List<TestRunById> RundetailsList = new List<TestRunById>(); TestRunProject testProData = logic.GetRunByProject(); foreach (var test in testProData.value) { TestRunById runData = new TestRunById(); runData = logic.GetRunByRunId(test.id.ToString()); RunList.Add(runData); ListClass.RunList.Add(runData); } //project level run TestSuit dataretrive = new TestSuit(); runStore = new List <TestRunById>(); //TestCasesFromSuits testresult = logic.TestCaseFromSuit(plan.id.ToString(), inf.id.ToString); WorkItemsClass testresult = logic.testCaseMethod(testCaseId); //foreach (var test in testresult.fields) //{ foreach (var run in RunList) { foreach (var run1 in run.value) { if (run1.testCase.id.ToString() == testCaseId) //testresult.id.ToString()) { testrun = new TestRunById(); testrun = run; testrunList.Add(testrun); //int runid = Convert.ToInt32(run1.testRun.id); } } // } } foreach (var test in testrunList) { foreach (var test1 in test.value) { TestRunPartial store = testStoreMethod(test1.id, test1.testCaseTitle, test1.outcome); testrunStoreList.Add(store); } } return(Json(testrunStoreList, JsonRequestBehavior.AllowGet)); }
public TestCaseResponseModel TestCaseCreate(WorkItemsClass testcases) { TestCaseResponseModel Result = new TestCaseResponseModel(); try { string testName = testcases.fields.Title; string jsonString = System.IO.File.ReadAllText(System.Web.HttpContext.Current.Server.MapPath("~") + @"\Jsons\TestCaseJson.json"); jsonString = jsonString.Replace("$name$", testName); string api = string.Format("https://dev.azure.com/{0}/{1}/_apis/wit/workitems/${2}?api-version=5.1", Org.OrganizationName, Org.ProjectName, "Test Case"); using (var client = new HttpClient()) { var jsonContent = new StringContent(jsonString, Encoding.UTF8, "application/json-patch+json");//"application/json"); var method = new HttpMethod("POST"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Org.pat); var request = new HttpRequestMessage(method, api) { Content = jsonContent }; var response = client.SendAsync(request).Result; if (response.IsSuccessStatusCode) { var obj = response.Content.ReadAsStringAsync().Result; var Message = response.Content.ReadAsStringAsync(); Result = JsonConvert.DeserializeObject <TestCaseResponseModel>(obj); return(Result); } else { var errorMessage = response.Content.ReadAsStringAsync(); return(Result); } } return(Result); } catch { return(Result); } }
public WorkItemsClass testCaseMethod(string testcaseid) { WorkItemsClass workitemTestCase = new WorkItemsClass(); string api = string.Format("https://dev.azure.com/{0}{1}/_apis/wit/workitems/151?api-version=5.1", Org.OrganizationName, Org.ProjectName, testcaseid); 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);//);accessToken1 HttpResponseMessage response = client.GetAsync(api).Result; if (response.IsSuccessStatusCode) { var obj = response.Content.ReadAsStringAsync().Result; workitemTestCase = JsonConvert.DeserializeObject <WorkItemsClass>(obj); } return(workitemTestCase); } }