public int Execute(string[] args) { _options = new CommandLineOptions(); _options.Parse(args); _workDirectory = _options.WorkDirectory ?? Environment.CurrentDirectory; _writer = _options.OutFile != null ? new ExtendedTextWrapper(new StreamWriter(_options.OutFile)) : new ColorConsoleWriter(!_options.NoColor); _textUI = new TextUI(_writer); if (!_options.NoHeader) { _textUI.DisplayHeader(); } if (_options.ShowHelp) { _textUI.DisplayHelp(_options._monoOptions); return(OK); } if (_options.ShowVersion) { return(OK); } if (_options.Error) { _textUI.DisplayErrorMessages(_options.ErrorMessages); _textUI.DisplayHelp(_options._monoOptions); return(INVALID_ARG); } _textUI.DisplayRuntimeEnvironment(); _textUI.DisplayTestFile(AssemblyHelper.GetAssemblyPath(_testAssembly)); if (_options.WaitBeforeExit && _options.OutFile != null) { _writer.WriteLine("Ignoring /wait option - only valid for Console"); } var runSettings = MakeRunSettings(_options); // We display the filters at this point so that any exception message // thrown by CreateTestFilter will be understandable. if (_options.WhereClauseSpecified) { _textUI.DisplayTestFilter(_options.WhereClause); } ITestFilter filter = _options.WhereClauseSpecified ? CreateTestFilter(_options.WhereClause) : TestFilter.Empty; try { Randomizer.InitialSeed = _options.RandomSeed; if (!_runner.Load(_testAssembly, runSettings)) { AssemblyName assemblyName = AssemblyHelper.GetAssemblyName(_testAssembly); Console.WriteLine("No tests found in assembly {0}", assemblyName.Name); return(NO_TESTS_FOUND); } return(_options.Explore ? ExploreTests() : RunTests(filter)); } catch (FileNotFoundException ex) { _writer.WriteLine(ex.Message); return(FILE_NOT_FOUND); } catch (Exception ex) { _writer.WriteLine(ex.ToString()); return(UNEXPECTED_ERROR); } finally { if (_options.OutFile == null) { if (_options.WaitBeforeExit) { Console.WriteLine("Press Enter key to continue . . ."); Console.ReadLine(); } } else { _writer.Close(); } } }