コード例 #1
0
        /// <summary>
        /// Update Test Results.
        /// </summary>
        /// <param name="filePath">TRX file path.</param>
        /// <param name="account">Account.</param>
        /// <param name="project">Project.</param>
        /// <param name="token">PAT.</param>
        /// <param name="testSuiteIds">Test Suite Ids.</param>
        /// <param name="consideration">Consideration of specified Test Suite Ids.</param>
        /// <returns>Integer.</returns>
        public static int UpdateTestResults(string filePath, string account, string project, string token, IEnumerable <string> testSuiteIds, bool consideration)
        {
            TestSuiteIds  = testSuiteIds;
            Consideration = consideration;
            AzureDevOpsUtility.UpdateAccountDetails(account, project, token);
            try
            {
                ParseTestRun(filePath);
                GetAutomatedTestNames();
                GetTestCasesByPlanAsync().GetAwaiter().GetResult();
                GetTestPointIdsAsync().GetAwaiter().GetResult();
                CreateNewTestRunsAsync().GetAwaiter().GetResult();
                UpdateTestResultsAsync().GetAwaiter().GetResult();
                UploadTrxFileAsTestRunAttachment(filePath).GetAwaiter().GetResult();
                UpdateTestRunsAsync().GetAwaiter().GetResult();
            }
            catch (Exception e)
            {
                CommonUtility.DeleteTestRunsAsync(NewTestRunIds).GetAwaiter().GetResult();
                throw e;
            }

            return(0);
        }
コード例 #2
0
        /// <summary>
        /// Update Test Results.
        /// </summary>
        /// <param name="filePath">file path.</param>
        /// <param name="isJson">Is input file type Json?</param>
        /// <param name="account">Account.</param>
        /// <param name="project">Project.</param>
        /// <param name="token">Token.</param>
        /// <returns>Integer.</returns>
        public static int UpdateTestResults(string filePath, bool isJson, string account, string project, string token)
        {
            AzureDevOpsUtility.UpdateAccountDetails(account, project, token);
            if (isJson)
            {
                var json = File.ReadAllText(filePath);
                TestResults = JsonConvert.DeserializeObject <TestResults>(json);
            }
            else
            {
                var excel = new ExcelMapper(filePath);
                excel.AddMapping <TestCaseOutcome>("TestCaseId", t => t.TestCaseId);
                excel.AddMapping <TestCaseOutcome>("TestSuiteId", t => t.TestSuiteId);
                excel.AddMapping <TestCaseOutcome>("Outcome", t => t.Outcome)
                .SetPropertyUsing(v =>
                {
                    if ((v as string).Equals(Constants.NotExecuted))
                    {
                        return(OutcomeType.NotExecuted);
                    }
                    if ((v as string).Equals(Constants.Failed))
                    {
                        return(OutcomeType.Failed);
                    }
                    else
                    {
                        return(OutcomeType.Passed);
                    }
                });

                var testCases = excel.Fetch <TestCaseOutcome>().ToList();
                TestResults = new TestResults()
                {
                    SuiteId   = 0,
                    TestCases = testCases
                };
            }

            try
            {
                GetTestCasesByPlanAsync().GetAwaiter().GetResult();
                GetTestPointIdsAsync().GetAwaiter().GetResult();
                CreateNewTestRunsAsync().GetAwaiter().GetResult();
                UpdateTestRunsAsync().GetAwaiter().GetResult();
            }
            catch (FlurlHttpException e)
            {
                var statusCode = e.Call.Response.StatusCode.ToString();
                if (statusCode.Equals(Constants.NonAuthoritativeInformation) || statusCode.Equals(Constants.Unauthorized))
                {
                    Log.Error("Authentication Error!!! Please provide valid Account Details...\n");
                }
            }
            catch (Exception e)
            {
                CommonUtility.DeleteTestRunsAsync(NewTestRunIds).GetAwaiter().GetResult();
                throw e;
            }

            return(0);
        }