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)));
                            }
                        }
        }
        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));
                }
            }
        }