コード例 #1
0
        private TestResults RunTests(TestPackage package, TestFilter filter, Messages.OnMessage[] subscribers)
        {
            NUnit.Core.TestResult result;
            ProcessModel processModel = package.Settings.Contains("ProcessModel") ? (ProcessModel)package.Settings["ProcessModel"] : ProcessModel.Default;
            DomainUsage domainUsage = package.Settings.Contains("DomainUsage") ? (DomainUsage)package.Settings[(object)"DomainUsage"] : DomainUsage.Default;
            RuntimeFramework runtimeFramework = package.Settings.Contains("RuntimeFramework") ? (RuntimeFramework)package.Settings["RuntimeFramework"] : RuntimeFramework.CurrentFramework;

            using (new SaveConsoleOutput())
            using (TestRunner testRunner = new DefaultTestRunnerFactory().MakeTestRunner(package))
            using (var ms = new MemoryStream())
            using (var output = CreateOutputWriter(ms))
            {
                try
                {
                    TestEventHandler eventCollector = new TestEventHandler(_options, output, subscribers);
                    testRunner.Load(package);
                    if (testRunner.Test == null)
                    {
                        testRunner.Unload();
                        return new TestResults(TestResults.Code.FixtureNotFound, "Unable to locate fixture");
                    }
                    result = testRunner.Run(eventCollector, filter, false, LoggingThreshold.All);
                    var summary = eventCollector.GetSummary();

                    output.Flush();
                    if (summary.UnexpectedError)
                        return new TestResults(TestResults.Code.UnexpectedError, GetResultText(ms), summary);

                    return new TestResults(summary.InvalidAssemblies > 0
                            ? TestResults.Code.InvalidAssembly
                            : GetCode(summary.FailureCount + summary.ErrorCount + summary.InvalidCount),
                            GetResultText(ms), summary);
                }
                catch (FileNotFoundException ex)
                {
                    output.WriteLine(ex.Message);
                    output.Flush();
                    return new TestResults(TestResults.Code.InvalidAssembly, GetResultText(ms));
                }
                catch (DirectoryNotFoundException ex)
                {
                    output.WriteLine(ex.Message);
                    output.Flush();
                    return new TestResults(TestResults.Code.InvalidAssembly, GetResultText(ms));
                }
                catch (Exception ex)
                {
                    output.WriteLine(ex.ToString());
                    output.Flush();
                    return new TestResults(TestResults.Code.UnexpectedError, GetResultText(ms));
                }
            }
        }
コード例 #2
0
        private TestResults RunTests(TestPackage package, TestFilter filter, Messages.OnMessage[] messageSubscribers)
        {
            XmlNode result;

            using (new SaveConsoleOutput())
            using (ITestRunner runner = _engine.GetRunner(package))
            using (var ms = new MemoryStream())
            using (var output = CreateOutputWriter(ms))
            {
                try
                {
                    var labels = "ON";
                    var eventHandler = new TestEventHandler(output, labels, messageSubscribers);

                    result = runner.Run(eventHandler, filter);
                    var reporter = new ResultReporter(result, output, _options);
                    reporter.ReportResults();

                    output.Flush();
                    if (reporter.Summary.UnexpectedError)
                        return new TestResults(TestResults.Code.UnexpectedError, GetResultText(ms), reporter.Summary);

                    return new TestResults(reporter.Summary.InvalidAssemblies > 0
                            ? TestResults.Code.InvalidAssembly
                            : GetCode( reporter.Summary.FailureCount + reporter.Summary.ErrorCount + reporter.Summary.InvalidCount),
                            GetResultText(ms), reporter.Summary);
                }
                catch (NUnitEngineException ex)
                {
                    output.WriteLine(ex.Message);
                    output.Flush();
                    return new TestResults(TestResults.Code.InvalidArg, GetResultText(ms));
                }
                catch (FileNotFoundException ex)
                {
                    output.WriteLine(ex.Message);
                    output.Flush();
                    return new TestResults(TestResults.Code.InvalidAssembly, GetResultText(ms));
                }
                catch (DirectoryNotFoundException ex)
                {
                    output.WriteLine(ex.Message);
                    output.Flush();
                    return new TestResults(TestResults.Code.InvalidAssembly, GetResultText(ms));
                }
                catch (Exception ex)
                {
                    output.WriteLine(ex.ToString());
                    output.Flush();
                    return new TestResults(TestResults.Code.UnexpectedError, GetResultText(ms));
                }
            }
        }