/// <summary>
        /// Initializes a new instance of the <see cref="ReportGenerator"/> class.
        /// </summary>
        /// <param name="testRun">Completed test results.</param>
        /// <param name="parameters">Test parameters.</param>
        /// <param name="libraryParameters">User parameters.</param>
        internal ReportGenerator(TestRun testRun, IReadOnlyDictionary <string, string> parameters, IDictionary <string, object> libraryParameters)
        {
            var library = new LibraryDrop(libraryParameters);
            var run     = new TestRunDrop(testRun);

            _context = Hash.FromAnonymousObject(new { run, parameters, library });
        }
Exemple #2
0
        internal TestRunDrop Process()
        {
            var testRunDrop = new TestRunDrop
            {
                ResultSets        = new TestResultSetDropCollection(),
                TestRunStatistics = new TestRunStatisticsDrop(),
            };

            foreach (var input in _inputs)
            {
                switch (input.Format)
                {
                case InputFormatType.Trx:
                {
                    var results = TrxLoader.FromFile(input.File.FullName);
                    TrxMapper.Map(results, testRunDrop, input);
                    break;
                }

                default:
                    throw new NotImplementedException();
                }
            }

            return(testRunDrop);
        }
        /// <summary>
        /// Maps result types from TRX into instance of drop models with configuration
        /// </summary>
        /// <param name="source">Instance of test results from deserialised TRX input</param>
        /// <param name="destination">Instance to map and merge results into</param>
        /// <param name="inputConfiguration">User configured input for current source</param>
        public static void Map(TestRunType source, TestRunDrop destination, ReportInput inputConfiguration = null)
        {
            var times    = source.Times.FirstOrDefault();
            var started  = DateTimeOffset.Parse(times.Start);
            var finished = DateTimeOffset.Parse(times.Finish);

            if (destination.Started is null || destination.Started > started)
            {
                destination.Started = started;
            }
            if (destination.Finished is null || destination.Finished < finished)
            {
                destination.Finished = finished;
            }

            var definitions          = source.TestDefinitions.SelectMany(x => x.UnitTest).ToDictionary(k => k.Id, v => v);
            var unitTestResultsGroup = source.Results
                                       .SelectMany(r => r.UnitTestResult)
                                       .Select(r => (result: r, definition: definitions[r.TestId]))
                                       .GroupBy(t => inputConfiguration?.GroupTitle ?? StringFilters.PathSplit(t.definition.TestMethod.CodeBase).Last()) // Group by codebase if no title is provided
                                       .ToList();

            foreach (var resultGroup in unitTestResultsGroup)
            {
                TestResultSetDrop drop;

                if (destination.ResultSets.TryGetValue(resultGroup.Key, out var existingDrop))
                {
                    drop = existingDrop;
                }
                else
                {
                    drop = new TestResultSetDrop
                    {
                        Source  = resultGroup.Key,
                        Results = new List <TestResultDrop>(),
                    };
                    destination.ResultSets.Add(drop);
                }

                foreach (var(result, definition) in resultGroup)
                {
                    foreach (var unitTestResults in ExtractTestResults(result))
                    {
                        var testCase = new TestCaseDrop
                        {
                            Source             = definition.TestMethod.CodeBase,
                            DisplayName        = string.IsNullOrEmpty(inputConfiguration?.TestSuffix) ? unitTestResults.TestName : $"{unitTestResults.TestName}{inputConfiguration.TestSuffix}",
                            FullyQualifiedName = $"{definition.TestMethod.ClassName}.{definition.TestMethod.Name}",
                            Id          = Guid.Parse(definition.Id),
                            ExecutorUri = definition.TestMethod.AdapterTypeName,
                        };
                        var startTime  = DateTimeOffset.Parse(unitTestResults.StartTime);
                        var endTime    = DateTimeOffset.Parse(unitTestResults.EndTime);
                        var duration   = (endTime - startTime);
                        var outcome    = MapOutcome(unitTestResults.Outcome, drop, destination.TestRunStatistics);
                        var resultDrop = new TestResultDrop
                        {
                            StartTime      = startTime,
                            EndTime        = endTime,
                            Duration       = duration,
                            Outcome        = outcome,
                            TestCase       = testCase,
                            ComputerName   = unitTestResults.ComputerName,
                            AttachmentSets = new List <AttachmentSetDrop>(unitTestResults.CollectorDataEntries.Select(rf => new AttachmentSetDrop
                            {
                                Attachments = new List <AttachmentDrop>(rf.Collector.Select(c => new AttachmentDrop
                                {
                                    Description = c.CollectorDisplayName,
                                    Uri         = c.Uri
                                }))
                            })),
                            DisplayName = definition.TestMethod.Name
                        };
                        MapOutputToResult(unitTestResults.Output, resultDrop);
                        destination.TestRunStatistics.ExecutedTestsCount++;
                        destination.ElapsedTimeInRunningTests += duration;
                        drop.Duration += duration;
                        drop.ExecutedTestsCount++;
                        drop.Results.Add(resultDrop);
                    }
                }
            }
        }
        /// <summary>
        /// Maps result types from JUnit into instance of drop models with configuration
        /// </summary>
        /// <param name="source">Instance of test results from deserialised JUnit input</param>
        /// <param name="destination">Instance to map and merge results into</param>
        /// <param name="inputConfiguration">User configured input for current source</param>
        public static void Map(Testsuites source, TestRunDrop destination, ReportInput inputConfiguration = null)
        {
            foreach (var testsuite in source.Testsuite)
            {
                var started  = DateTimeOffset.Parse(testsuite.Timestamp);
                var finished = started + TimeSpan.FromMilliseconds(double.Parse(testsuite.Time));

                if (destination.Started is null || destination.Started > started)
                {
                    destination.Started = started;
                }
                if (destination.Finished is null || destination.Finished < finished)
                {
                    destination.Finished = finished;
                }

                var key = inputConfiguration?.GroupTitle ?? testsuite.Package;

                foreach (var testCase in testsuite.Testcase)
                {
                    TestResultSetDrop drop;

                    if (destination.ResultSets.TryGetValue(key, out var existingDrop))
                    {
                        drop = existingDrop;
                    }
                    else
                    {
                        drop = new TestResultSetDrop
                        {
                            Source  = key,
                            Results = new List <TestResultDrop>(),
                        };
                        destination.ResultSets.Add(drop);
                    }


                    var testCaseDrop = new TestCaseDrop
                    {
                        Source             = testsuite.Package,
                        DisplayName        = string.IsNullOrEmpty(inputConfiguration?.TestSuffix) ? testCase.Name : $"{testCase.Name}{inputConfiguration.TestSuffix}",
                        FullyQualifiedName = $"{testCase.Classname}.{testCase.Classname}",
                        Id          = null,
                        ExecutorUri = null,
                    };
                    var duration   = TimeSpan.FromMilliseconds(double.Parse(testCase.Time));
                    var outcome    = MapOutcome(testCase, drop, destination.TestRunStatistics);
                    var resultDrop = new TestResultDrop
                    {
                        StartTime      = null,
                        EndTime        = null,
                        Duration       = duration,
                        Outcome        = outcome,
                        TestCase       = testCaseDrop,
                        ComputerName   = testsuite.Hostname,
                        AttachmentSets = null,
                        DisplayName    = testCase.Name
                    };
                    MapOutputToResult(testCase, resultDrop);
                    destination.TestRunStatistics.ExecutedTestsCount++;
                    destination.ElapsedTimeInRunningTests += duration;
                    drop.Duration += duration;
                    drop.ExecutedTestsCount++;
                    drop.Results.Add(resultDrop);
                }
            }
        }