コード例 #1
0
        private async Task UploadTestResultsAttachmentAsync(int testRunId,
                                                            TestCaseResultData testCaseResultData,
                                                            TestCaseResult testCaseResult,
                                                            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (testCaseResult == null || testCaseResultData == null)
            {
                return;
            }

            if (testCaseResultData.AttachmentData != null)
            {
                // Remove duplicate entries
                string[]         attachments   = testCaseResultData.AttachmentData.AttachmentsFilePathList?.ToArray();
                HashSet <string> attachedFiles = GetUniqueTestRunFiles(attachments);

                if (attachedFiles != null && attachedFiles.Any())
                {
                    var createAttachmentsTasks = attachedFiles.Select(async attachment =>
                    {
                        TestAttachmentRequestModel reqModel = GetAttachmentRequestModel(attachment);
                        if (reqModel != null)
                        {
                            await _testResultsServer.CreateTestResultAttachmentAsync(reqModel, _projectName, testRunId, testCaseResult.Id, cancellationToken);
                        }
                    });
                    await Task.WhenAll(createAttachmentsTasks);
                }

                // Upload console log as attachment
                string consoleLog = testCaseResultData?.AttachmentData.ConsoleLog;
                TestAttachmentRequestModel attachmentRequestModel = GetConsoleLogAttachmentRequestModel(consoleLog);
                if (attachmentRequestModel != null)
                {
                    await _testResultsServer.CreateTestResultAttachmentAsync(attachmentRequestModel, _projectName, testRunId, testCaseResult.Id, cancellationToken);
                }

                // Upload standard error as attachment
                string standardError = testCaseResultData.AttachmentData.StandardError;
                TestAttachmentRequestModel stdErrAttachmentRequestModel = GetStandardErrorAttachmentRequestModel(standardError);
                if (stdErrAttachmentRequestModel != null)
                {
                    await _testResultsServer.CreateTestResultAttachmentAsync(stdErrAttachmentRequestModel, _projectName, testRunId, testCaseResult.Id, cancellationToken);
                }
            }

            if (testCaseResult.SubResults != null && testCaseResult.SubResults.Any() && testCaseResultData.TestCaseSubResultData != null)
            {
                for (int i = 0; i < testCaseResultData.TestCaseSubResultData.Count; i++)
                {
                    await UploadTestSubResultsAttachmentAsync(testRunId, testCaseResult.Id, testCaseResultData.TestCaseSubResultData[i], testCaseResult.SubResults[i], 1, cancellationToken);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Publishes the given results to the test run.
        /// </summary>
        /// <param name="testResults">Results to be published.</param>
        public async Task AddResultsAsync(TestRun testRun, TestCaseResultData[] testResults, CancellationToken cancellationToken)
        {
            Trace.Entering();
            int noOfResultsToBePublished = BATCH_SIZE;

            _executionContext.Output(StringUtil.Loc("PublishingTestResults", testRun.Id));

            for (int i = 0; i < testResults.Length; i += BATCH_SIZE)
            {
                cancellationToken.ThrowIfCancellationRequested();
                if (i + BATCH_SIZE >= testResults.Length)
                {
                    noOfResultsToBePublished = testResults.Length - i;
                }
                _executionContext.Output(StringUtil.Loc("TestResultsRemaining", (testResults.Length - i), testRun.Id));

                var currentBatch = new TestCaseResultData[noOfResultsToBePublished];
                Array.Copy(testResults, i, currentBatch, 0, noOfResultsToBePublished);

                List <TestCaseResult> testresults = await _testResultsServer.AddTestResultsToTestRunAsync(currentBatch, _projectName, testRun.Id, cancellationToken);

                for (int j = 0; j < noOfResultsToBePublished; j++)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    // Do not upload duplicate entries
                    string[] attachments = testResults[i + j].Attachments;
                    if (attachments != null)
                    {
                        Hashtable attachedFiles          = new Hashtable(StringComparer.CurrentCultureIgnoreCase);
                        var       createAttachmentsTasks = attachments.Select(async attachment =>
                        {
                            if (!attachedFiles.ContainsKey(attachment))
                            {
                                TestAttachmentRequestModel reqModel = GetAttachmentRequestModel(attachment);
                                if (reqModel != null)
                                {
                                    await _testResultsServer.CreateTestResultAttachmentAsync(reqModel, _projectName, testRun.Id, testresults[j].Id, cancellationToken);
                                }
                                attachedFiles.Add(attachment, null);
                            }
                        });
                        await Task.WhenAll(createAttachmentsTasks);
                    }

                    // Upload console log as attachment
                    string consoleLog = testResults[i + j].ConsoleLog;
                    TestAttachmentRequestModel attachmentRequestModel = GetConsoleLogAttachmentRequestModel(consoleLog);
                    if (attachmentRequestModel != null)
                    {
                        await _testResultsServer.CreateTestResultAttachmentAsync(attachmentRequestModel, _projectName, testRun.Id, testresults[j].Id, cancellationToken);
                    }
                }
            }

            Trace.Leaving();
        }
コード例 #3
0
        /// <summary>
        /// Publishes the given results to the test run.
        /// </summary>
        /// <param name="testResults">Results to be published.</param>
        public async Task AddResultsAsync(TestRun testRun, TestCaseResultData[] testResults, CancellationToken cancellationToken)
        {
            Trace.Entering();
            int noOfResultsToBePublished = BATCH_SIZE;

            _executionContext.Output(StringUtil.Loc("PublishingTestResults", testRun.Id));

            for (int i = 0; i < testResults.Length; i += BATCH_SIZE)
            {
                cancellationToken.ThrowIfCancellationRequested();
                if (i + BATCH_SIZE >= testResults.Length)
                {
                    noOfResultsToBePublished = testResults.Length - i;
                }
                _executionContext.Output(StringUtil.Loc("TestResultsRemaining", (testResults.Length - i), testRun.Id));

                var currentBatch     = new TestCaseResultData[noOfResultsToBePublished];
                var testResultsBatch = new TestCaseResult[noOfResultsToBePublished];
                Array.Copy(testResults, i, currentBatch, 0, noOfResultsToBePublished);

                for (int testResultsIndex = 0; testResultsIndex < noOfResultsToBePublished; testResultsIndex++)
                {
                    testResultsBatch[testResultsIndex] = new TestCaseResult();
                    TestCaseResultDataConverter.Convert(currentBatch[testResultsIndex], testResultsBatch[testResultsIndex]);
                }

                List <TestCaseResult> testresults = await _testResultsServer.AddTestResultsToTestRunAsync(testResultsBatch, _projectName, testRun.Id, cancellationToken);

                for (int j = 0; j < noOfResultsToBePublished; j++)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    // Remove duplicate entries
                    string[]         attachments   = testResults[i + j]?.AttachmentData?.AttachmentsFilePathList?.ToArray();
                    HashSet <string> attachedFiles = GetUniqueTestRunFiles(attachments);

                    if (attachedFiles != null)
                    {
                        var createAttachmentsTasks = attachedFiles.Select(async attachment =>
                        {
                            TestAttachmentRequestModel reqModel = GetAttachmentRequestModel(attachment);
                            if (reqModel != null)
                            {
                                await _testResultsServer.CreateTestResultAttachmentAsync(reqModel, _projectName, testRun.Id, testresults[j].Id, cancellationToken);
                            }
                        });
                        await Task.WhenAll(createAttachmentsTasks);
                    }

                    // Upload console log as attachment
                    string consoleLog = testResults[i + j]?.AttachmentData?.ConsoleLog;
                    TestAttachmentRequestModel attachmentRequestModel = GetConsoleLogAttachmentRequestModel(consoleLog);
                    if (attachmentRequestModel != null)
                    {
                        await _testResultsServer.CreateTestResultAttachmentAsync(attachmentRequestModel, _projectName, testRun.Id, testresults[j].Id, cancellationToken);
                    }

                    // Upload standard error as attachment
                    string standardError = testResults[i + j]?.AttachmentData?.StandardError;
                    TestAttachmentRequestModel stdErrAttachmentRequestModel = GetStandardErrorAttachmentRequestModel(standardError);
                    if (stdErrAttachmentRequestModel != null)
                    {
                        await _testResultsServer.CreateTestResultAttachmentAsync(stdErrAttachmentRequestModel, _projectName, testRun.Id, testresults[j].Id, cancellationToken);
                    }
                }
            }

            Trace.Leaving();
        }