Пример #1
0
        public async Task <IActionResult> UpdateTestLastState(int testCaseId, TestLastStateUpdateRequest request)
        {
            var error = await _service.UpdateTestLastStateAsync(testCaseId, request);

            return(error.ToActionResult());
        }
Пример #2
0
 public async Task UpdateTestLastStateAsync(int testCaseId, TestLastStateUpdateRequest request)
 {
     await SendAsync <IReadOnlyCollection <TestLastStateResponse> >(HttpMethod.Post, "impact/lastState/" + testCaseId, request);
 }
        public async Task <TestRunResponse> RecordTestRunEndAsync(TestCaseInfo testCase, TestRunOutcome outcome,
                                                                  string errorMessage, IEnumerable <string> impactFiles, IEnumerable <string> impactMethods)
        {
            var patch = new JsonPatchDocument <TestRunRequest>();

            patch.Add(r => r.State, TestRunState.Finished);
            patch.Add(r => r.Outcome, outcome);
            patch.Add(r => r.FinishTime, DateTime.Now);
            patch.Add(r => r.ErrorMessage, errorMessage);
            var runResponse = await _client.PatchTestRunAsync(_session.Id, testCase.TestRunId, patch);

            _logger.Info("Test run finished: " + ObjToString(runResponse));

            List <CodeSignature> codeSignatures = new List <CodeSignature>();

            if (impactFiles != null)
            {
                codeSignatures.AddRange(
                    impactFiles.Select(f => new CodeSignature(f, CodeSignatureUtils.CalculateSignature(f), CodeSignatureType.File)));
            }
            if (impactMethods != null)
            {
                codeSignatures.AddRange(
                    impactMethods.Select(f => new CodeSignature(f, CodeSignatureUtils.CalculateSignature(f), CodeSignatureType.Method)));
            }

            var impactRequest = new TestCaseImpactUpdateRequest()
            {
                ProductLine    = _productLine,
                CodeSignatures = codeSignatures
            };

            var impactDataCount = codeSignatures.Count;

            LogDebug("Updating test impact information. Number of files/methods (code signatures): " + impactDataCount);
            if (impactDataCount == 0)
            {
                LogDebug("(No impact data is available)");
            }

            Exception impactUpdateException = null;

            try
            {
                await _client.UpdateTestImpactAsync(testCase.Id, impactRequest);
            }
            catch (Exception ex)
            {
                impactUpdateException = ex;
                _logger.Error("Updating test case impact data failed:\r\n" + ex.ToString());
            }

            var lastStateRequest = new TestLastStateUpdateRequest()
            {
                ProductLine      = _productLine,
                TestRunSessionId = _session.Id,
                Outcome          = outcome
            };

            if (impactUpdateException != null)
            {
                lastStateRequest.DictatedRunReason = RunReason.ImpactUpdateFailed;
                _logger.Warn("Test case will be run again next time.");
            }

            LogDebug($"Updating test last state. Azure Test Case Id: {testCase.AzureTestCaseId}, Outcome: {outcome}");

            await _client.UpdateTestLastStateAsync(testCase.Id, lastStateRequest);

            return(runResponse);
        }