public static int Main(string[] args) { var options = new CommandLineOptions(args); if (options.ShowHelp) { // TODO: We would need to have a custom message box // in order to use a fixed font and display the options // so that the values all line up. MessageDisplay.Info(options.GetHelpText()); return(0); } if (!options.Validate()) { var NL = Environment.NewLine; var sb = new StringBuilder($"Error(s) in command line:{NL}"); foreach (string msg in options.ErrorMessages) { sb.Append($" {msg}{NL}"); } sb.Append($"{NL}{options.GetHelpText()}"); MessageDisplay.Error(sb.ToString()); return(2); } // Currently the InternalTraceLevel can only be set from the command-line. // We can't use user settings to provide a default because the settings // are an engine service and the engine have the internal trace level // set as part of its initialization. var traceLevel = options.InternalTraceLevel; // This initializes the trace setting for the GUI itself. InternalTrace.Initialize($"InternalTrace.{Process.GetCurrentProcess().Id}.gui.log", traceLevel); log.Info($"Starting TestCentric Runner - InternalTraceLevel = {traceLevel}"); log.Info("Creating TestEngine"); ITestEngine testEngine = TestEngineActivator.CreateInstance(); testEngine.InternalTraceLevel = traceLevel; log.Info("Instantiating TestModel"); ITestModel model = new TestModel(testEngine); log.Info("Constructing Form"); TestCentricMainView view = new TestCentricMainView(); log.Info("Constructing presenters"); new ProgressBarPresenter(view.ProgressBarView, model); new StatusBarPresenter(view.StatusBarView, model); new ErrorsAndFailuresPresenter(view.ErrorsAndFailuresView, model); new TestsNotRunPresenter(view.TestsNotRunView, model); new TextOutputPresenter(view.TextOutputView, model); new TreeViewPresenter(view.TreeView, model); new TestCentricPresenter(view, model, options); try { log.Info("Starting Gui Application"); Application.Run(view); log.Info("Application Exit"); } catch (Exception ex) { log.Error("Gui Application threw an excepion", ex); throw; } finally { log.Info("Exiting TestCentric Runner"); InternalTrace.Close(); testEngine.Dispose(); } return(0); }
/// <summary> /// The main entry point for the application, minus GUI initialization /// logic. This method is intended for wrapper applications that /// already do their own GUI initializations that would conflict with /// those done in <see cref="Main"/>. /// </summary> public static void Run(string[] args) { CommandLineOptions options = new CommandLineOptions(); try { options.Parse(args); } catch (OptionException ex) { string msg = string.Format("{0} {1}", ex.Message, ex.OptionName); MessageBox.Show(msg, "NUnit - OptionException", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!options.Validate()) { var errMessage = new string[options.ErrorMessages.Count]; options.ErrorMessages.CopyTo(errMessage, 0); var msg = "There were the following errors parsing the options:" + Environment.NewLine + string.Join(Environment.NewLine, errMessage) + Environment.NewLine + Environment.NewLine + "Use the option '--help' to show the possible options and their values."; MessageBox.Show(msg, "NUnit - Problem parsing options", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (options.ShowHelp) { MessageDisplay.Info(GetHelpText(options)); return; } var testEngine = TestEngineActivator.CreateInstance(true); var traceLevel = (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), options.InternalTraceLevel ?? "Off"); testEngine.InternalTraceLevel = traceLevel; var model = new TestModel(testEngine, "Experimental."); model.PackageOverrides.Add(EnginePackageSettings.InternalTraceLevel, traceLevel.ToString()); if (options.ProcessModel != null) { model.PackageOverrides.Add(EnginePackageSettings.ProcessModel, options.ProcessModel); } if (options.DomainUsage != null) { model.PackageOverrides.Add(EnginePackageSettings.DomainUsage, options.DomainUsage); } if (options.MaxAgents >= 0) { model.PackageOverrides.Add(EnginePackageSettings.MaxAgents, options.MaxAgents); } if (options.RunAsX86) { model.PackageOverrides.Add(EnginePackageSettings.RunAsX86, true); } var form = new MainForm(); new ProgressBarPresenter(form.ProgressBarView, model); new StatusBarPresenter(form.StatusBarView, model); new TestPropertiesPresenter(form.PropertiesView, model); new XmlPresenter(form.XmlView, model); new TextOutputPresenter(form.TextOutputView, model); new TreeViewPresenter(form.TestTreeView, model); new MainPresenter(form, model, options); //new RecentFiles(settingsServiceServiceService._settings); //new RecentFilesPresenter(form, settingsServiceServiceService); try { Application.Run(form); } finally { testEngine.Dispose(); } }
public static int Main(string[] args) { var options = new CommandLineOptions(args); if (options.ShowHelp) { // TODO: We would need to have a custom message box // in order to use a fixed font and display the options // so that the values all line up. MessageDisplay.Info(GetHelpText(options)); return(0); } if (!options.Validate()) { var NL = Environment.NewLine; var sb = new StringBuilder($"Error(s) in command line:{NL}"); foreach (string msg in options.ErrorMessages) { sb.Append($" {msg}{NL}"); } sb.Append($"{NL}{GetHelpText(options)}"); MessageDisplay.Error(sb.ToString()); return(2); } log.Info("Instantiating TestModel"); ITestModel model = TestModel.CreateTestModel(options); log.Info("Constructing Form"); TestCentricMainView view = new TestCentricMainView(); log.Info("Constructing presenters"); new ProgressBarPresenter(view.ProgressBarView, model); new StatusBarPresenter(view.StatusBarView, model); new TestPropertiesPresenter(view.TestPropertiesView, model); new ErrorsAndFailuresPresenter(view.ErrorsAndFailuresView, model); new TextOutputPresenter(view.TextOutputView, model); new TreeViewPresenter(view.TreeView, model); new TestCentricPresenter(view, model, options); try { log.Info("Starting Gui Application"); Application.Run(view); log.Info("Application Exit"); } catch (Exception ex) { log.Error("Gui Application threw an exception", ex); throw; } finally { log.Info("Exiting TestCentric Runner"); InternalTrace.Close(); model.Dispose(); } return(0); }