Example #1
0
        public static string GetDescription(TestResultInfo result)
        {
            var splitMethod  = result.Method.Split('(', ')');
            var methodName   = splitMethod[0];
            var testCaseArgs = splitMethod.Length == 1 ? null : splitMethod[1];

            var testFixtureType = ReflectionUtility.GetTestFixtureType(result);

            var matchingMethod = testFixtureType.GetMethods(BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                                 .Where(x => x.Name == methodName)
                                 .FirstOrDefault(x => IsSignatureMatching(x, testCaseArgs));

            if (matchingMethod == null)
            {
                return(null);
            }

            var attributes = matchingMethod.GetCustomAttributes(false).Cast <Attribute>();

            return(GetDescription(attributes));
        }
        private TestSuite CreateFixture(IGrouping <string, TestResultInfo> resultsByType)
        {
            var element = new XElement("test-suite");

            int      total        = 0;
            int      passed       = 0;
            int      failed       = 0;
            int      skipped      = 0;
            int      inconclusive = 0;
            int      error        = 0;
            var      time         = TimeSpan.Zero;
            DateTime?startTime    = null;
            DateTime?endTime      = null;

            var testFixtureType = ReflectionUtility.GetTestFixtureType(resultsByType.FirstOrDefault());
            var properties      = this.CreateFixturePropertiesElement(testFixtureType);

            element.Add(properties);

            var group = resultsByType
                        .GroupBy(x => x.TestResultKey())
                        .OrderBy(x => x.Key);

            foreach (var entry in group)
            {
                if (entry.Count() == 1)
                {
                    var testResult        = entry.First();
                    var propertiesElement = CreatePropertiesElement(testResult);
                    var testCase          = CreateTestCase(testResult);
                    testCase.Element.Add(propertiesElement);

                    failed       += testCase.Failed;
                    passed       += testCase.Passed;
                    skipped      += testCase.Skipped;
                    inconclusive += testCase.Inconclusive;
                    total++;
                    time += testCase.Time;

                    if (!startTime.HasValue || testCase.StartTime < startTime)
                    {
                        startTime = testCase.StartTime;
                    }

                    if (!endTime.HasValue || testCase.EndTime > endTime)
                    {
                        endTime = testCase.EndTime;
                    }

                    element.Add(testCase.Element);
                }
                else
                {
                    var testSuite = AggregateTestCases(entry.Select(CreateTestCase), entry.Key.fullTypeName, entry.Key.methodName);
                    failed       += testSuite.Failed;
                    passed       += testSuite.Passed;
                    skipped      += testSuite.Skipped;
                    inconclusive += testSuite.Inconclusive;
                    total        += testSuite.Total;
                    time         += testSuite.Time;

                    if (!startTime.HasValue || testSuite.StartTime < startTime)
                    {
                        startTime = testSuite.StartTime;
                    }

                    if (!endTime.HasValue || testSuite.EndTime > endTime)
                    {
                        endTime = testSuite.EndTime;
                    }

                    var firstTestResult   = entry.First();
                    var propertiesElement = CreatePropertiesElement(firstTestResult);
                    testSuite.Element.AddFirst(propertiesElement);

                    element.Add(testSuite.Element);
                }
            }

            // Create test-suite element for the TestFixture
            var name = resultsByType.Key.SubstringAfterDot();

            element.SetAttributeValue("type", "TestFixture");
            element.SetAttributeValue("name", name);
            element.SetAttributeValue("fullname", resultsByType.Key);

            element.SetAttributeValue("total", total);
            element.SetAttributeValue("passed", passed);
            element.SetAttributeValue("failed", failed);
            element.SetAttributeValue("inconclusive", inconclusive);
            element.SetAttributeValue("skipped", skipped);

            var resultString = failed > 0 ? ResultStatusFailed : ResultStatusPassed;

            element.SetAttributeValue("result", resultString);

            if (startTime.HasValue)
            {
                element.SetAttributeValue("start-time", startTime.Value.ToString(DateFormat, CultureInfo.InvariantCulture));
            }

            if (endTime.HasValue)
            {
                element.SetAttributeValue("end-time", endTime.Value.ToString(DateFormat, CultureInfo.InvariantCulture));
            }

            element.SetAttributeValue("duration", time.TotalSeconds);

            return(new TestSuite
            {
                Element = element,
                Name = name,
                FullName = resultsByType.Key,
                Total = total,
                Passed = passed,
                Failed = failed,
                Inconclusive = inconclusive,
                Skipped = skipped,
                Error = error,
                StartTime = startTime,
                EndTime = endTime,
                Time = time
            });
        }