Inheritance: System.Configuration.ConfigurationSection
 public WebSiteTestSuiteGenerator(LinkCheckerConfigSection Config)
 {
     this.Config = Config;
 }
        public int Execute()
        {
            if (Args.Length == 0)
            {
                Console.WriteLine(HELP_MESSAGE);
                return(1);
            }
            else if (Args.Length != 1)
            {
                Console.WriteLine(HELP_MESSAGE);
                return(1);
            }
            else
            {
                string arg        = Args[0];
                string configFile = null;
                foreach (var argPrefix in CONFIG_ARG_PREFIXES)
                {
                    if (arg.StartsWith(argPrefix))
                    {
                        configFile = arg.Substring(argPrefix.Length);
                        break;
                    }
                }

                if (String.IsNullOrEmpty(configFile))
                {
                    Console.WriteLine(HELP_MESSAGE);
                    return(1);
                }
                else
                {
                    if (!File.Exists(configFile))
                    {
                        Console.WriteLine(MISSING_CONFIG_FILE_MESSAGE, configFile);
                        return(1);
                    }

                    Configuration config = null;
                    try
                    {
                        ExeConfigurationFileMap map = new ExeConfigurationFileMap();
                        map.ExeConfigFilename = configFile;
                        config = ConfigurationManager.OpenMappedExeConfiguration(
                            map
                            , ConfigurationUserLevel.None
                            );
                    }
                    catch (ConfigurationErrorsException)
                    {
                        Console.WriteLine(CONFIG_FILE_ERROR_MESSAGE);
                        return(1);
                    }
                    if (config == null)
                    {
                        Console.WriteLine(CONFIG_FILE_ERROR_MESSAGE);
                        return(1);
                    }
                    ConfigurationSectionCollection sections = config.Sections;
                    if (sections == null)
                    {
                        Console.WriteLine(CONFIG_FILE_ERROR_MESSAGE);
                        return(1);
                    }
                    LinkCheckerConfigSection section = null;
                    try
                    {
                        section = (LinkCheckerConfigSection)sections.Get("linkCheckerConfig");
                    }
                    catch (InvalidCastException)
                    {
                        Console.WriteLine(MISSING_CONFIG_SECTIONS_MESSAGE);
                        return(1);
                    }
                    catch (ConfigurationErrorsException)
                    {
                        Console.WriteLine(CONFIG_FILE_ERROR_MESSAGE);
                        return(1);
                    }
                    if (section == null)
                    {
                        Console.WriteLine(CONFIG_FILE_ERROR_MESSAGE);
                        return(1);
                    }

                    WebSiteTestSuiteGenerator generator = new WebSiteTestSuiteGenerator(section);
                    generator.GenerateTests();
                }
            }

            return(0);
        }
Esempio n. 3
0
 public WebSiteTestSuiteGenerator(LinkCheckerConfigSection Config)
 {
     this.Config = Config;
 }