Beispiel #1
0
        private void RunTests(string source, IEnumerable <TestCase> tests, KarmaTestResults.Karma karma, IFrameworkHandle frameworkHandle, IKarmaLogger logger)
        {
            var vsConfig = CreateVsConfig(tests, karma);
            var runKarma = Run(source, vsConfig, logger);

            if (runKarma == null)
            {
                logger.Error("No karma");
                return;
            }

            var consolidatedResults = runKarma.ConsolidateResults(logger);
            var testNames           = tests.Select(t => t.DisplayName).Union(consolidatedResults.Select(r => r.Test.DisplayName));

            var results = from displayName in testNames
                          join test in tests
                          on displayName equals test.DisplayName
                          into test_
                          from test in test_.DefaultIfEmpty()
                          join result in consolidatedResults
                          on displayName equals result.Test.DisplayName
                          into result_
                          from result in result_.DefaultIfEmpty()
                          select new TestCaseResult(test, result, source);

            foreach (var result in results)
            {
                frameworkHandle.RecordStart(result.Test);
                foreach (var res in result.Result.Results)
                {
                    frameworkHandle.RecordResult(new TestResult(result.Test)
                    {
                        ComputerName = Environment.MachineName,
                        DisplayName  = res.Browser.Name,
                        Outcome      = res.Outcome,
                        Duration     = res.Time,
                        ErrorMessage = res.Message
                    });
                }
                frameworkHandle.RecordEnd(result.Test, result.Result.Outcome);
            }
        }
Beispiel #2
0
        private VsConfig.Config CreateVsConfig(IEnumerable <TestCase> tests, KarmaTestResults.Karma karma)
        {
            var includedWithTests = tests.Select(t => t.CodeFilePath).Distinct();

            return(new VsConfig.Config
            {
                files = karma.Files
                        .Where(f => !f.AllTests.Any() || includedWithTests.Any(fi => f.HasFile(fi)))
                        .Select(f => new VsConfig.File
                {
                    path = f.Path,
                    served = f.Served,
                    included = f.Included,
                    tests = f.AllTests
                            .Where(t => tests.Any(tc => tc.FullyQualifiedName == t.FullyQualifiedName))
                            .Select(t => new VsConfig.Test
                    {
                        name = t.Name,
                        index = t.Index
                    })
                })
            });
        }