当前位置: 首页>>代码示例>>C#>>正文


C# ConsoleOptions.Parse方法代码示例

本文整理汇总了C#中ConsoleOptions.Parse方法的典型用法代码示例。如果您正苦于以下问题:C# ConsoleOptions.Parse方法的具体用法?C# ConsoleOptions.Parse怎么用?C# ConsoleOptions.Parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConsoleOptions的用法示例。


在下文中一共展示了ConsoleOptions.Parse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateReporter

        public void CreateReporter()
        {
            _report = new StringBuilder();

            var writer = new ExtendedTextWrapper(new StringWriter(_report));
            var options = new ConsoleOptions();
            options.Parse(new string[] { "MockTestResult.xml" });

            _reporter = new ResultReporter(_result, writer, options);
        }
开发者ID:rojac07,项目名称:nunit,代码行数:10,代码来源:ResultReporterTests.cs

示例2: Main

        public static int Main(string[] args)
        {
            ConsoleOptions options = new ConsoleOptions();

            try
            {
                options.Parse(args);
            }
            catch (OptionException ex)
            {
                WriteHeader();
                ColorConsole.WriteLine(ColorStyle.Error, string.Format(ex.Message, ex.OptionName));
                return ConsoleRunner.INVALID_ARG;
            }

            ColorConsole.Enabled = !options.NoColor;

            // Create SettingsService early so we know the trace level right at the start
            //SettingsService settingsService = new SettingsService();
            //InternalTraceLevel level = (InternalTraceLevel)settingsService.GetSetting("Options.InternalTraceLevel", InternalTraceLevel.Default);
            //if (options.trace != InternalTraceLevel.Default)
            //    level = options.trace;

            //InternalTrace.Initialize("nunit-console_%p.log", level);
            
            //log.Info("NUnit-console.exe starting");
            try
            {
                if (options.PauseBeforeRun)
                {
                    ColorConsole.WriteLine(ColorStyle.Warning, "Press any key to continue . . .");
                    Console.ReadKey(true);
                }

                if (!options.NoHeader)
                    WriteHeader();

                if (options.ShowHelp)
                {
                    WriteHelpText(options);
                    return ConsoleRunner.OK;
                }

                if (!options.Validate())
                {
                    using (new ColorConsole(ColorStyle.Error))
                    {
                        foreach (string message in options.ErrorMessages)
                            Console.Error.WriteLine(message);
                    }

                    return ConsoleRunner.INVALID_ARG;
                }

                if (options.InputFiles.Count == 0)
                {
                    using (new ColorConsole(ColorStyle.Error))
                        Console.Error.WriteLine("Error: no inputs specified");
                    return ConsoleRunner.OK;
                }

                // TODO: Move this to engine
                foreach (string file in options.InputFiles)
                {
                    //if (!Services.ProjectService.CanLoadProject(file) && !PathUtils.IsAssemblyFileType(file))
                    string ext = Path.GetExtension(file);
                    if (ext != ".dll" && ext != ".exe" && ext != ".nunit")
                    {
                        ColorConsole.WriteLine(ColorStyle.Warning, "File type not known: " + file);
                        return ConsoleRunner.INVALID_ARG;
                    }
                }

                using (ITestEngine engine = TestEngineActivator.CreateInstance())
                {
                    if (options.WorkDirectory != null)
                        engine.WorkDirectory = options.WorkDirectory;

                    if (options.InternalTraceLevel != null)
                        engine.InternalTraceLevel = (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), options.InternalTraceLevel);

                    try
                    {
                        return new ConsoleRunner(engine, options).Execute();
                    }
                    catch (NUnitEngineException ex)
                    {
                        ColorConsole.WriteLine(ColorStyle.Error, ex.Message);
                        return ConsoleRunner.INVALID_ARG;
                    }
                    catch (FileNotFoundException ex)
                    {
                        ColorConsole.WriteLine(ColorStyle.Error, ex.Message);
#if DEBUG
                        ColorConsole.WriteLine(ColorStyle.Error, ex.StackTrace);
#endif
                        return ConsoleRunner.FILE_NOT_FOUND;
                    }
                    catch (DirectoryNotFoundException ex)
                    {
//.........这里部分代码省略.........
开发者ID:balaghanta,项目名称:nunit-framework,代码行数:101,代码来源:Program.cs


注:本文中的ConsoleOptions.Parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。