示例#1
0
        /// <summary>
        /// Populate adapter settings from the context
        /// </summary>
        /// <param name="context">
        /// The discovery context that contains the runsettings.
        /// </param>
        public static void PopulateSettings(IDiscoveryContext context)
        {
            RunConfigurationSettings = RunConfigurationSettings.PopulateSettings(context);

            if (context == null || context.RunSettings == null || string.IsNullOrEmpty(context.RunSettings.SettingsXml))
            {
                // This will contain default adapter settings
                CurrentSettings = new MSTestSettings();
                return;
            }

            var aliasSettings = GetSettings(context.RunSettings.SettingsXml, SettingsNameAlias);

            // If a user specifies MSTestV2 in the runsettings, then prefer that over the v1 settings.
            if (aliasSettings != null)
            {
                CurrentSettings = aliasSettings;
            }
            else
            {
                var settings = GetSettings(context.RunSettings.SettingsXml, SettingsName);

                if (settings != null)
                {
                    CurrentSettings = settings;
                }
                else
                {
                    CurrentSettings = new MSTestSettings();
                }
            }

            SetGlobalSettings(context.RunSettings.SettingsXml, CurrentSettings);
        }
        /// <summary>
        /// Convert the parameter xml to TestSettings
        /// </summary>
        /// <param name="reader">Reader to load the settings from.</param>
        /// <returns>An instance of the <see cref="MSTestSettings"/> class</returns>
        private static RunConfigurationSettings ToSettings(XmlReader reader)
        {
            ValidateArg.NotNull <XmlReader>(reader, "reader");

            // Expected format of the xml is: -
            //
            // <Runsettings>
            // <RunConfiguration>
            // <CollectSourceInformation>true</CollectSourceInformation>
            // </RunConfiguration>
            // </Runsettings>
            RunConfigurationSettings settings = new RunConfigurationSettings();

            // Read the first element in the section
            reader.ReadToNextElement();

            if (!reader.IsEmptyElement)
            {
                reader.Read();

                while (reader.NodeType == XmlNodeType.Element)
                {
                    bool   result;
                    string elementName = reader.Name.ToUpperInvariant();
                    switch (elementName)
                    {
                    case "COLLECTSOURCEINFORMATION":
                    {
                        if (bool.TryParse(reader.ReadInnerXml(), out result))
                        {
                            settings.CollectSourceInformation = result;
                            PlatformServiceProvider.Instance.AdapterTraceLogger.LogInfo(
                                "CollectSourceInformation value Found : {0} ",
                                result);
                        }

                        break;
                    }

                    default:
                    {
                        reader.SkipToNextElement();
                        break;
                    }
                    }
                }
            }

            return(settings);
        }