Esempio n. 1
0
        internal static async Task <ITestResultReport[]> GenerateTestResultReports(ITestOperationResultStorage storage, ILogger logger)
        {
            logger.LogInformation($"Starting report generation for {Settings.Current.ReportMetadataList.Count} reports");

            try
            {
                var testReportGeneratorFactory = new TestReportGeneratorFactory(storage);
                var testResultReportList       = new List <Task <ITestResultReport> >();
                foreach (IReportMetadata reportMetadata in Settings.Current.ReportMetadataList)
                {
                    ITestResultReportGenerator testResultReportGenerator = testReportGeneratorFactory.Create(Settings.Current.TrackingId, reportMetadata);
                    testResultReportList.Add(testResultReportGenerator.CreateReportAsync());
                }

                ITestResultReport[] testResultReports = await Task.WhenAll(testResultReportList);

                logger.LogInformation("Successfully generated all reports");

                return(testResultReports);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "TestResultCoordinator failed during report generation");
                return(new ITestResultReport[] { });
            }
        }
Esempio n. 2
0
        internal static async Task <ITestResultReport[]> GenerateTestResultReportsAsync(
            string trackingId,
            List <ITestReportMetadata> reportMetadatalist,
            ITestReportGeneratorFactory testReportGeneratorFactory,
            ILogger logger)
        {
            Preconditions.CheckNonWhiteSpace(trackingId, nameof(trackingId));
            Preconditions.CheckNotNull(reportMetadatalist, nameof(reportMetadatalist));

            logger.LogInformation($"Starting report generation for {reportMetadatalist.Count} reports");

            var testResultReportTasks = new List <Task <ITestResultReport> >();

            try
            {
                foreach (ITestReportMetadata reportMetadata in reportMetadatalist)
                {
                    ITestResultReportGenerator testResultReportGenerator = await testReportGeneratorFactory.CreateAsync(trackingId, reportMetadata);

                    testResultReportTasks.Add(testResultReportGenerator.CreateReportAsync());
                }

                ITestResultReport[] testResultReports = await Task.WhenAll(testResultReportTasks);

                logger.LogInformation("Successfully generated all reports");

                return(testResultReports);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "At least 1 report generation is failed.");
                var reports = new List <ITestResultReport>();

                foreach (Task <ITestResultReport> reportTask in testResultReportTasks)
                {
                    if (reportTask.IsFaulted)
                    {
                        logger.LogError(reportTask.Exception, "Error in report generation task");
                    }
                    else
                    {
                        reports.Add(reportTask.Result);
                    }
                }

                return(reports.ToArray());
            }
        }