Example #1
0
        /// <summary>
        /// Execute the tests in the assembly, passing in
        /// a list of arguments.
        /// </summary>
        /// <param name="args">Execution options</param>
        public int Execute(string[] args)
        {
            var options         = new ConsoleOptions(args);
            var callingAssembly = Assembly.GetCallingAssembly();

            var level = (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), options.InternalTraceLevel ?? "Off", true);

#if NETCF  // NETCF: Try to unify
            InitializeInternalTrace(callingAssembly.GetName().CodeBase, level);
#else
            InitializeInternalTrace(callingAssembly.Location, level);
#endif

            ExtendedTextWriter outWriter = null;
            if (options.OutFile != null)
            {
                outWriter = new ExtendedTextWrapper(new StreamWriter(Path.Combine(options.WorkDirectory, options.OutFile)));
                Console.SetOut(outWriter);
            }

            TextWriter errWriter = null;
            if (options.ErrFile != null)
            {
                errWriter = new StreamWriter(Path.Combine(options.WorkDirectory, options.ErrFile));
                Console.SetError(errWriter);
            }

            var _textUI = new TextUI(outWriter, options);

            if (!options.NoHeader)
            {
                _textUI.DisplayHeader();
            }

            if (options.ShowHelp)
            {
                _textUI.DisplayHelp();
                return(TextRunner.OK);
            }

            if (options.ErrorMessages.Count > 0)
            {
                _textUI.DisplayErrors(options.ErrorMessages);
                _textUI.DisplayHelp();

                return(TextRunner.INVALID_ARG);
            }

#if !PORTABLE
            if (options.InputFiles.Count > 0)
            {
                _textUI.DisplayError("Input assemblies may not be specified when using the NUnitLite AutoRunner");
                return(TextRunner.INVALID_ARG);
            }
#endif

            _textUI.DisplayTestFiles(new string[] { callingAssembly.GetName().Name });
            _textUI.DisplayRuntimeEnvironment();
            _textUI.DisplayRequestedOptions();

            if (options.WaitBeforeExit && options.OutFile != null)
            {
                _textUI.DisplayWarning("Ignoring /wait option - only valid for Console");
            }

            try
            {
                return(new TextRunner(_textUI, options).Execute(callingAssembly));
            }
            finally
            {
                if (options.WaitBeforeExit)
                {
                    _textUI.WaitForUser("Press Enter key to continue . . .");
                }

                if (outWriter != null)
                {
                    outWriter.Close();
                }

                if (errWriter != null)
                {
                    errWriter.Close();
                }
            }
        }
Example #2
0
        /// <summary>
        /// Execute the tests in the assembly, passing in
        /// a list of arguments.
        /// </summary>
        /// <param name="args">Execution options</param>
        public int Execute(string[] args)
        {
            var options = new ConsoleOptions(args);
            var callingAssembly = Assembly.GetCallingAssembly();

            var level = (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), options.InternalTraceLevel ?? "Off", true);
#if NETCF  // NETCF: Try to unify
            InitializeInternalTrace(callingAssembly.GetName().CodeBase, level);
#else
            InitializeInternalTrace(callingAssembly.Location, level);
#endif

            ExtendedTextWriter outWriter = null;
            if (options.OutFile != null)
            {
                outWriter = new ExtendedTextWrapper(new StreamWriter(Path.Combine(options.WorkDirectory, options.OutFile)));
                Console.SetOut(outWriter);
            }

            TextWriter errWriter = null;
            if (options.ErrFile != null)
            {
                errWriter = new StreamWriter(Path.Combine(options.WorkDirectory, options.ErrFile));
                Console.SetError(errWriter);
            }

            var _textUI = new TextUI(outWriter, options);

            if (!options.NoHeader)
                _textUI.DisplayHeader();

            if (options.ShowHelp)
            {
                _textUI.DisplayHelp();
                return TextRunner.OK;
            }

            if (options.ErrorMessages.Count > 0)
            {
                _textUI.DisplayErrors(options.ErrorMessages);
                _textUI.DisplayHelp();

                return TextRunner.INVALID_ARG;
            }

#if !PORTABLE
            if (options.InputFiles.Count > 0)
            {
                _textUI.DisplayError("Input assemblies may not be specified when using the NUnitLite AutoRunner");
                return TextRunner.INVALID_ARG;
            }
#endif

            _textUI.DisplayTestFiles(new string[] { callingAssembly.GetName().Name });
            _textUI.DisplayRuntimeEnvironment();
            _textUI.DisplayRequestedOptions();

            if (options.WaitBeforeExit && options.OutFile != null)
                _textUI.DisplayWarning("Ignoring /wait option - only valid for Console");

            try
            {
                return new TextRunner(_textUI, options).Execute(callingAssembly);
            }
            finally
            {
                if (options.WaitBeforeExit)
                    _textUI.WaitForUser("Press Enter key to continue . . .");

                if (outWriter != null)
                    outWriter.Close();

                if (errWriter != null)
                    errWriter.Close();
            }
        }