Пример #1
0
        /// <summary>
        /// Get Test Cases to be updated in Azure DevOps.
        /// </summary>
        /// <param name="workItem">WorkItem object.</param>
        /// <param name="testSuiteIds">Test Suite Ids.</param>
        /// <param name="consideration">Consideration of Test Suite Ids.</param>
        /// <returns>List of Test Cases.</returns>
        public static async Task <List <TestCase> > GetCasesAsync(JToken workItem, IEnumerable <string> testSuiteIds, bool consideration)
        {
            var testCases  = new List <TestCase>();
            var testCaseId = workItem.SelectToken("id").ToString();
            var testSuites = await AzureDevOpsUtility.GetTestSuitesByTestCaseIdAsync(testCaseId).ConfigureAwait(false);

            var testSuitesValues = testSuites.SelectToken("value").ToList();

            foreach (var testSuite in testSuitesValues)
            {
                var testSuiteId = testSuite.SelectToken("id").ToString();
                var testPlanId  = testSuite.SelectToken("plan.id").ToString();
                if (!consideration && (testSuiteIds.Count() > 0))
                {
                    if (testSuiteIds.Contains(testSuiteId))
                    {
                        testCases.Add(new TestCase(testCaseId, testSuiteId, testPlanId));
                    }
                }
                else if (consideration && (testSuiteIds.Count() > 0))
                {
                    if (testSuitesValues.Count > 1)
                    {
                        if (testSuiteIds.Contains(testSuiteId))
                        {
                            testCases.Add(new TestCase(testCaseId, testSuiteId, testPlanId));
                        }
                    }
                    else
                    {
                        testCases.Add(new TestCase(testCaseId, testSuiteId, testPlanId));
                    }
                }
                else
                {
                    testCases.Add(new TestCase(testCaseId, testSuiteId, testPlanId));
                }
            }

            return(testCases);
        }
        /// <summary>
        /// Get TestCases to be updated.
        /// </summary>
        /// <returns>Task.</returns>
        private static async Task GetTestCasesByPlanAsync()
        {
            foreach (var testCase in TestResults.TestCases)
            {
                var     testCaseId = testCase.TestCaseId.ToString();
                var     tsId       = testCase.TestSuiteId.ToString();
                JObject testSuites;
                try
                {
                    testSuites = await AzureDevOpsUtility.GetTestSuitesByTestCaseIdAsync(testCaseId).ConfigureAwait(false);
                }
                catch (FlurlHttpException e)
                {
                    var statusCode = e.Call.Response.StatusCode.ToString();
                    if (statusCode.Equals(Constants.NotFound))
                    {
                        Log.Information($"No Test-case is found with Id - {testCaseId}");
                        continue;
                    }
                    else
                    {
                        throw e;
                    }
                }

                var testSuitesValues = testSuites.SelectToken("value").ToList();
                if (testSuitesValues.Any())
                {
                    if (testCase.TestSuiteId != 0)
                    {
                        var result = testSuitesValues.Any(x => x.SelectToken("id").ToString().Equals(tsId));
                        if (!result)
                        {
                            Log.Information($"Test-Case Id: {testCase.TestCaseId} is not present in Test-Suite: {tsId}");
                            continue;
                        }
                        else
                        {
                            var testPlanId = testSuitesValues.FirstOrDefault(x => x.SelectToken("id").ToString().Equals(tsId)).SelectToken("plan.id").ToString();
                            TestCases.Add(new TestCase(testCaseId, tsId, testPlanId));
                        }
                    }
                    else if (TestResults.SuiteId != 0)
                    {
                        var suiteId = TestResults.SuiteId.ToString();
                        var result  = testSuitesValues.Any(x => x.SelectToken("id").ToString().Equals(suiteId));
                        if (!result)
                        {
                            Log.Information($"Test-Case Id: {testCase.TestCaseId} is not present in Test-Suite: {suiteId}");
                            continue;
                        }
                        else
                        {
                            var testPlanId = testSuitesValues.FirstOrDefault(x => x.SelectToken("id").ToString().Equals(suiteId)).SelectToken("plan.id").ToString();
                            TestCases.Add(new TestCase(testCaseId, suiteId, testPlanId));
                        }
                    }
                    else
                    {
                        foreach (var testSuite in testSuitesValues)
                        {
                            var testSuiteId = testSuite.SelectToken("id").ToString();
                            var testPlanId  = testSuite.SelectToken("plan.id").ToString();
                            TestCases.Add(new TestCase(testCaseId, testSuiteId, testPlanId));
                        }
                    }
                }
            }

            TestCasesByPlanId = TestCases.GroupBy(y => y.TestPlanId).OrderBy(z => z.Key).ToList();
        }