示例#1
0
        /// <summary>
        /// Create failed test results for all tests in test suite
        /// </summary>
        /// <param name="TeamProjectName"></param>
        /// <param name="TestPlanId"></param>
        /// <param name="StaticSuitePath"></param>
        private static void CreateTestResultFailed(string TeamProjectName, int TestPlanId, string StaticSuitePath)
        {
            TestPlan testPlan    = TestManagementClient.GetPlanByIdAsync(TeamProjectName, TestPlanId).Result;
            int      testSuiteId = GetSuiteId(TeamProjectName, TestPlanId, StaticSuitePath);

            var testPlanRef = new Microsoft.TeamFoundation.TestManagement.WebApi.ShallowReference(testPlan.Id.ToString(), testPlan.Name, testPlan.Url);

            RunCreateModel runCreate = new RunCreateModel(
                name: "Test run from console - failed",
                plan: testPlanRef,
                startedDate: DateTime.Now.ToString("o"),
                isAutomated: true
                );

            TestRun testRun = TestManagementClient.CreateTestRunAsync(runCreate, TeamProjectName).Result;

            List <TestCaseResult> testResults = new List <TestCaseResult>();

            List <SuiteTestCase> testCases = TestManagementClient.GetTestCasesAsync(TeamProjectName, TestPlanId, testSuiteId).Result; //Get all test cases from suite

            foreach (var testCase in testCases)
            {
                testResults.Add(FailedTest(TeamProjectName, TestPlanId, testSuiteId, testCase.Workitem.Id, testRun.Id));
            }

            testResults = TestManagementClient.AddTestResultsToTestRunAsync(testResults.ToArray(), TeamProjectName, testRun.Id).Result;

            var definedTestResults = TestManagementClient.GetTestResultsAsync(TeamProjectName, testRun.Id).Result; // Get test result

            TestManagementClient.CreateTestResultAttachmentAsync(GetAttachmentModel(@"img\iconfinder_Insect-robot_131435.png"), TeamProjectName, testRun.Id, definedTestResults.ElementAt(0).Id).Wait();


            RunUpdateModel runUpdateModel = new RunUpdateModel(
                errorMessage: "Test failed",
                completedDate: DateTime.Now.ToString("o"),
                state: Enum.GetName(typeof(TestRunState), TestRunState.NeedsInvestigation)
                );

            testRun = TestManagementClient.UpdateTestRunAsync(runUpdateModel, TeamProjectName, testRun.Id).Result;

            TestManagementClient.CreateTestRunAttachmentAsync(GetAttachmentModel(@"img\Screen_Shot_2018-01-16.jpg"), TeamProjectName, testRun.Id).Wait();

            PrintBasicRunInfo(testRun);
        }