public void CanParseSuccess()
        {
            var eventHandler =
                new EventHandler <TestEventArgs>((sender, args) => Assert.That(args.TestOutput, Is.EqualTo("Passed")));

            _listener.TestFinished += eventHandler;

            _listener.OnTestEvent(SUCCESS_TEST_CASE_XML);

            var testResult = _sink.TestResult;

            Assert.That(testResult, Is.Not.Null);
            Assert.That(testResult.ErrorMessage, Is.Null.Or.Empty);
            Assert.That(testResult.ErrorStackTrace, Is.Null.Or.Empty);
            Assert.That(testResult.Outcome, Is.EqualTo(TestOutcome.Passed));
            Assert.That(testResult.StartTime.Hour, Is.EqualTo(23));
            Assert.That(testResult.EndTime.Minute, Is.EqualTo(31));
            Assert.That(testResult.Duration.TotalSeconds, Is.EqualTo(0.000001d).Within(0.001d));

            _listener.TestFinished -= eventHandler;
        }
        int Execute()
        {
            DisplayRuntimeEnvironment();

            DisplayTestFiles();

            IEnumerable <string>         testList = SetupSinks();
            IDictionary <string, object> settings = GetTestSettings();

            // We display the filters at this point so  that any exception message
            // thrown by CreateTestFilter will be understandable.
            DisplayTestFilters();

            // Apply filters and merge with testList
            var filter = CreateTestFilter(testList);

            var summary = new ResultSummary();

            // Load the test framework
            foreach (var assembly in _options.InputFiles)
            {
                // TODO: Load async
                var assemblyPath  = System.IO.Path.GetFullPath(assembly);
                var testAssembly  = LoadAssembly(assemblyPath);
                var frameworkPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(assemblyPath), "nunit.framework.dll");
                var framework     = LoadAssembly(frameworkPath);

                var driver = new NUnitPortableDriver();
                var result = driver.Load(framework, testAssembly, settings);

                // TODO: Run async
                // Explore or Run
                if (_options.List || _options.Explore)
                {
                    ITestListener listener = new TestExploreListener(_testDiscoverySink, _options, assemblyPath);
                    string        xml      = driver.Explore(filter.Text);
                    listener.OnTestEvent(xml);
                    summary.AddResult(xml);
                }
                else
                {
                    var tcListener = new TeamCityEventListener();
                    TestExecutionListener listener = new TestExecutionListener(_testExecutionSink, _options, assemblyPath);
                    SetupLabelOutput(listener);
                    string xml = driver.Run(
                        report =>
                    {
                        listener.OnTestEvent(report);
                        if (_options.TeamCity)
                        {
                            tcListener.OnTestEvent(report);
                        }
                    },
                        filter.Text);
                    summary.AddResult(xml);
                }
            }

            if (_options.List || _options.Explore)
            {
                if (_options.DesignTime)
                {
                    _testDiscoverySink.SendTestCompleted();
                }

                return(ReturnCodes.OK);
            }

            if (_options.DesignTime)
            {
                _testExecutionSink.SendTestCompleted();
                return(ReturnCodes.OK);
            }

            // Summarize and save test results
            var reporter = new ResultReporter(summary, ColorConsole, _options);

            reporter.ReportResults();

            // Save out the TestResult.xml
            SaveTestResults(reporter.TestResults);

            if (summary.UnexpectedError)
            {
                return(ReturnCodes.UNEXPECTED_ERROR);
            }

            if (summary.InvalidAssemblies > 0)
            {
                return(ReturnCodes.INVALID_ASSEMBLY);
            }

            if (summary.InvalidTestFixtures > 0)
            {
                return(ReturnCodes.INVALID_TEST_FIXTURE);
            }

            // Return the number of test failures
            return(summary.FailedCount);
        }