Пример #1
0
        /// <summary>
        /// Creates a utility command context.
        /// </summary>
        /// <param name="arguments">The parsed command line arguments.</param>
        /// <param name="console">The console.</param>
        /// <param name="logger">The logger.</param>
        /// <param name="progressMonitorProvider">The progress monitor provider.</param>
        /// <param name="verbosity">The verbosity.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="arguments"/>,
        /// <paramref name="console"/>, <paramref name="logger"/> or <paramref name="progressMonitorProvider"/> is null.</exception>
        public UtilityCommandContext(object arguments, IRichConsole console, ILogger logger, IProgressMonitorProvider progressMonitorProvider, Verbosity verbosity)
        {
            if (arguments == null)
            {
                throw new ArgumentNullException("arguments");
            }
            if (console == null)
            {
                throw new ArgumentNullException("console");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }
            if (progressMonitorProvider == null)
            {
                throw new ArgumentNullException("progressMonitorProvider");
            }

            this.arguments = arguments;
            this.console   = console;
            this.logger    = logger;
            this.progressMonitorProvider = progressMonitorProvider;
            this.verbosity = verbosity;
        }
Пример #2
0
 /// <summary>
 /// Creates a launcher with default options and no test assemblies specified.
 /// </summary>
 public TestLauncher()
 {
     filePatterns            = new List <string>();
     testProject             = new TestProject();
     testRunnerOptions       = new TestRunnerOptions();
     testExplorationOptions  = new TestExplorationOptions();
     testExecutionOptions    = new TestExecutionOptions();
     reportFormats           = new List <string>();
     reportFormatterOptions  = new ReportFormatterOptions();
     progressMonitorProvider = NullProgressMonitorProvider.Instance;
     logger = NullLogger.Instance;
 }
        /// <summary>
        /// Creates a utility command context.
        /// </summary>
        /// <param name="arguments">The parsed command line arguments.</param>
        /// <param name="console">The console.</param>
        /// <param name="logger">The logger.</param>
        /// <param name="progressMonitorProvider">The progress monitor provider.</param>
        /// <param name="verbosity">The verbosity.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="arguments"/>,
        /// <paramref name="console"/>, <paramref name="logger"/> or <paramref name="progressMonitorProvider"/> is null.</exception>
        public UtilityCommandContext(object arguments, IRichConsole console, ILogger logger, IProgressMonitorProvider progressMonitorProvider, Verbosity verbosity)
        {
            if (arguments == null)
                throw new ArgumentNullException("arguments");
            if (console == null)
                throw new ArgumentNullException("console");
            if (logger == null)
                throw new ArgumentNullException("logger");
            if (progressMonitorProvider == null)
                throw new ArgumentNullException("progressMonitorProvider");

            this.arguments = arguments;
            this.console = console;
            this.logger = logger;
            this.progressMonitorProvider = progressMonitorProvider;
            this.verbosity = verbosity;
        }
Пример #4
0
        /// <inheritdoc />
        protected override int RunImpl(string[] args)
        {
            ShowBanner();
            InstallCancelHandler();

            if (!ParseArguments(args) || Arguments.CommandAndArguments.Length == 0)
            {
                ShowHelp();
                return(Arguments.Help ? 0 : 1);
            }

            ILogger logger = CreateLogger();
            IProgressMonitorProvider progressMonitorProvider = Arguments.NoProgress
                ? (IProgressMonitorProvider)NullProgressMonitorProvider.Instance
                : new RichConsoleProgressMonitorProvider(Console);

            string commandName = Arguments.CommandAndArguments[0];

            string[] commandRawArguments = new string[Arguments.CommandAndArguments.Length - 1];
            Array.Copy(Arguments.CommandAndArguments, 1, commandRawArguments, 0, commandRawArguments.Length);
            IUtilityCommand command          = GetSpecialCommand(commandName);
            bool            isSpecialCommand = command != null;
            var             runtimeSetup     = new RuntimeSetup();

            GenericCollectionUtils.ForEach(Arguments.PluginDirectories, x => runtimeSetup.AddPluginDirectory(x));

            using (isSpecialCommand ? null : RuntimeBootstrap.Initialize(runtimeSetup, logger))
            {
                if (command == null)
                {
                    var commandManager = RuntimeAccessor.ServiceLocator.Resolve <IUtilityCommandManager>();
                    command = commandManager.GetCommand(commandName);

                    if (command == null)
                    {
                        ShowErrorMessage(string.Format("Unrecognized utility command name: '{0}'.", commandName));
                        ShowHelp();
                        return(1);
                    }
                }

                Type commandArgumentsClass = command.GetArgumentClass();
                var  commandArgumentParser = new CommandLineArgumentParser(commandArgumentsClass, null);

                if (Arguments.Help)
                {
                    ShowHelpForParticularCommand(commandName, commandArgumentParser);
                    return(0);
                }

                object commandArguments = Activator.CreateInstance(commandArgumentsClass);

                if (!commandArgumentParser.Parse(commandRawArguments, commandArguments, ShowErrorMessage) || !command.ValidateArguments(commandArguments, ShowErrorMessage))
                {
                    ShowHelpForParticularCommand(commandName, commandArgumentParser);
                    return(1);
                }

                var commandContext = new UtilityCommandContext(commandArguments, Console, logger, progressMonitorProvider, Arguments.Verbosity);
                return(command.Execute(commandContext));
            }
        }