// Mark result in MTM private void MarkResultMethod() { TfsTeamProjectCollection teamCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("https://mseng.visualstudio.com:443/defaultcollection")); ITestManagementTeamProject project = teamCollection.GetService <ITestManagementService>().GetTeamProject("VSOnline"); var service = teamCollection.GetService <ITestManagementService>(); ITestPlan plan = project.TestPlans.Find(Convert.ToInt32(txtProjectID.Text)); // Create a new test run ITestRun testRun = plan.CreateTestRun(true); // Add the certain a test to the run string query = string.Format("SELECT * from TestPoint where SuiteID='{0}'", txtSuitID.Text); ITestPointCollection testPoints = plan.QueryTestPoints(query); List <string> failedCaceMTM = new List <string>(); foreach (ITestPoint testPoint in testPoints) { // for caseId please type: testPoint.TestCaseId testRun.AddTestPoint(testPoint, null); //string caseName = testPoint.TestCaseWorkItem.Implementation.DisplayText; //string cname = caseName.Substring(caseName.LastIndexOf(".") + 1); //if (GetFailedCaseNamesListFromTrxFile.Contains(cname)) //{ // failedCaceMTM.Add(cname); //} } var blockCase = GetFailedCaseNamesListFromTrxFile.Except(failedCaceMTM).ToList(); testRun.Save(); //Update the outcome of the test ITestCaseResultCollection results = testRun.QueryResults(); ; foreach (ITestCaseResult result in results) { // Get case name in MTM. string caseName = result.Implementation.DisplayText; string name = caseName.Substring(caseName.LastIndexOf(".") + 1); result.Outcome = GetFailedCaseNamesListFromTrxFile.Contains(name) ? TestOutcome.Passed : TestOutcome.Failed; result.State = TestResultState.Completed; result.Save(); } testRun.Save(); testRun.Refresh(); File.Delete(xmlPath); }
private void ModifyTxt() { string txt; List <string> caseList = new List <string>(); using (StreamReader reader = new StreamReader(@".\PassCaseMTM.txt")) { while ((txt = reader.ReadLine()) != null) { txt = txt.Substring(txt.LastIndexOf(".") + 1); caseList.Add(txt); } } var testst = GetFailedCaseNamesListFromTrxFile.Intersect(caseList).ToList(); File.WriteAllLines(@".\PassCaseMTM.txt", caseList); }