/// <summary> /// Get the execution record based on the combination of test case, test plan, test environment(configuration) /// Note that, typically, the combination of case/plan/config/timeline dertimine one execution record, here we ignored the timeline. /// </summary> /// <param name="projectAlias"></param> /// <param name="caseWebId">test case WebId</param> /// <param name="planWebId">test plan WebId</param> /// <param name="environmentGeneratedId">environment Generated Id</param> /// <returns>list of execution records</returns> private List<Resources.executionworkitem> GetExistingExecutionRecordsInRQMByTestCaseTestPlanAndEnvironment(string projectAlias, string caseWebId, string planWebId, string environmentGeneratedId) { Resources.testcase testCase = new Resources.testcase(); string testCaseURL = GetResourceURLForGettingAndPuttingUsingWebId(projectAlias,testCase, caseWebId); Resources.testplan testPlan = new Resources.testplan(); string testPlanURL = GetResourceURLForGettingAndPuttingUsingWebId(projectAlias, testPlan, planWebId); Resources.configuration config = new Resources.configuration(); string configURL = GetResourceURLForGettingAndPuttingUsingGeneratedId(projectAlias, config, environmentGeneratedId); Resources.executionworkitem item = new Resources.executionworkitem(); string requestURL = GetResourcesURLForPosting(projectAlias, item); requestURL = string.Format("{0}?fields=feed/entry/content/{1}/(*|testcase[@href='{2}']|testplan[@href='{3}']|configuration[@href='{4}'])",requestURL,item.GetType().Name, testCaseURL, testPlanURL, configURL ); List<object> executionRecords = GetResourcesByURL(requestURL, item); if (executionRecords != null) { return executionRecords.Select(e => e as Resources.executionworkitem).ToList(); } else { return null; } }
/// <summary> /// Get or Create test case execution record /// 1. If execution record with the same case id, plan id and configuration id, return its web id /// 2. else, create a new execution record and return the web id /// </summary> /// <param name="projectAlias">the project the execution record will be created on</param> /// <param name="title">record title</param> /// <param name="description">record description</param> /// <param name="testCaseWebId">test case web id related</param> /// <param name="testPlanWebId">test plan web id related</param> /// <returns>web id of the created execution record</returns> public string GetOrCreateTestCaseExecutionRecord(string projectAlias, string title, string description, string testCaseWebId, string testPlanWebId, string testEnvironmentGeneratedId) { List<Resources.executionworkitem> existingExecutionRecords = GetExistingExecutionRecordsInRQMByTestCaseTestPlanAndEnvironment(projectAlias, testCaseWebId, testPlanWebId, testEnvironmentGeneratedId); if (existingExecutionRecords != null && existingExecutionRecords.Count > 0) { return existingExecutionRecords.FirstOrDefault().webId.ToString(); } else { Resources.executionworkitem executionRecord = new Resources.executionworkitem(); executionRecord.title = title; executionRecord.testcase = new Resources.executionworkitemTestcase(); executionRecord.testcase.href = GetResourceURLForGettingAndPuttingUsingWebId(projectAlias, new Resources.testcase(), testCaseWebId); executionRecord.testplan = new Resources.executionworkitemTestplan(); executionRecord.testplan.href = GetResourceURLForGettingAndPuttingUsingWebId(projectAlias, new Resources.testplan(), testPlanWebId); executionRecord.description = description; executionRecord.weight = 100; executionRecord.configuration = new Resources.executionworkitemConfiguration[1]; executionRecord.configuration[0] = new Resources.executionworkitemConfiguration(); executionRecord.configuration[0].href = GetResourceURLForGettingAndPuttingUsingGeneratedId(projectAlias, new Resources.configuration(), testEnvironmentGeneratedId); return CreateResourceByPost(projectAlias, executionRecord); } }