Пример #1
0
        // UTILITIES
        private void DoUpdateTestResult(RhinoTestCase testCase, bool inline)
        {
            // constants
            const string Aggregated = "aggregated";

            try
            {
                // setup
                var forUploadOutcomes = new[] { "PASS", "FAIL" };
                var onTestCase        = testCase.AggregateSteps();
                onTestCase.Context.AddRange(testCase.Context, exclude: new[] { Aggregated });

                // exit conditions
                var outcome = "TODO";
                if (onTestCase.Context.ContainsKey("outcome"))
                {
                    outcome = $"{testCase.Context["outcome"]}";
                }

                // update
                if (inline)
                {
                    testCase.SetOutcomeBySteps();
                    testCase.SetOutcomeByRun();
                    return;
                }
                testCase.SetOutcomeBySteps();
                onTestCase = testCase.AggregateSteps();

                // attachments
                if (forUploadOutcomes.Contains(outcome.ToUpper()))
                {
                    onTestCase.UploadEvidences();
                }

                // fail message
                if (outcome.Equals("FAIL", Compare) || testCase.Steps.Any(i => i.Exception != default))
                {
                    var comment = testCase.GetFailComment();
                    testCase.UpdateResultComment(comment);
                }

                // put
                testCase.Context[Aggregated] = onTestCase;
            }
            catch (Exception e) when(e != null)
            {
                logger?.Error($"Update-TestResult -Test [{testCase.Key}] -Inline [{inline}] = false", e);
            }
        }
        /// <summary>
        /// Set XRay runtime ids on all steps under this RhinoTestCase.
        /// </summary>
        /// <param name="testCase">RhinoTestCase on which to update runtime ids.</param>
        /// <param name="testExecutionKey">Jira test execution key by which to find runtime ids.</param>
        public static void SetRuntimeKeys(this RhinoTestCase testCase, string testExecutionKey)
        {
            // setup
            var ravenClient = new JiraCommandsExecutor(testCase.GetAuthentication());
            var command     = RavenCommandsRepository.GetTestRunExecutionDetails(testExecutionKey, testCase.Key);

            // send
            var response = ravenClient.SendCommand(command).AsJToken();

            // exit conditions
            if ($"{response["id"]}".Equals("-1"))
            {
                return;
            }

            // setup
            var jsonToken  = response["steps"];
            var stepsToken = JArray.Parse($"{jsonToken}");
            var aggregated = testCase.AggregateSteps();
            var steps      = aggregated.Steps.ToList();

            // apply runtime id to test-step context
            for (int i = 0; i < steps.Count; i++)
            {
                steps[i].Context["runtimeid"] = stepsToken[i]["id"].ToObject <long>();
                steps[i].Context["testStep"]  = JToken.Parse($"{stepsToken[i]}");

                var isKey  = steps[i].Context.ContainsKey(ContextEntry.ChildSteps);
                var isType = isKey && steps[i].Context[ContextEntry.ChildSteps] is IEnumerable <RhinoTestStep>;
                if (isType)
                {
                    foreach (var _step in (IEnumerable <RhinoTestStep>)steps[i].Context[ContextEntry.ChildSteps])
                    {
                        _step.Context["runtimeid"] = steps[i].Context["runtimeid"];
                    }
                }
            }

            // apply test run key
            _ = int.TryParse($"{response["id"]}", out int idOut);
            testCase.Context["runtimeid"]  = idOut;
            testCase.Context["testRunKey"] = testExecutionKey;
            testCase.Context["aggregated"] = aggregated;
            aggregated.Steps = steps;
        }
        /// <summary>
        /// Set XRay test execution results of test case by setting steps outcome.
        /// </summary>
        /// <param name="testCase">RhinoTestCase by which to update XRay results.</param>
        /// <returns>-1 if failed to update, 0 for success.</returns>
        /// <remarks>Must contain runtimeid field in the context.</remarks>
        public static void SetOutcomeBySteps(this RhinoTestCase testCase)
        {
            // get steps
            var onTestCase = testCase.AggregateSteps();

            onTestCase.Context.AddRange(testCase.Context, new[] { "aggregated" });

            // collect steps
            var steps = new List <object>();

            foreach (var testStep in onTestCase.Steps)
            {
                steps.Add(testStep.GetUpdateRequest(outcome: $"{onTestCase.Context["outcome"]}"));
            }

            // setup
            var executor = new JiraCommandsExecutor(onTestCase.GetAuthentication());
            var command  = RavenCommandsRepository.UpdateTestRun(
                testRun: $"{onTestCase.Context["runtimeid"]}",
                data: new { Steps = steps });

            // send
            executor.SendCommand(command);
        }