Пример #1
0
        private TestProperty(string id, string label, string category, string description, Type valueType, ValidateValueCallback validateValueCallback, TestPropertyAttributes attributes)
        {
            ValidateArg.NotNullOrEmpty(id, "id");
            ValidateArg.NotNull(label, "label");
            ValidateArg.NotNull(category, "category");
            ValidateArg.NotNull(description, "description");
            ValidateArg.NotNull(valueType, "valueType");

            // If the type of property is unexpected, then fail as otherwise we will not be to serialize it over the wcf channel and serialize it in db.
            if (valueType == typeof(KeyValuePair<string, string>[]))
            {
                this.ValueType = "System.Collections.Generic.KeyValuePair`2[[System.String],[System.String]][]";
            }
            else if (valueType == typeof(string)
                || valueType == typeof(Uri)
                || valueType == typeof(string[])
                || valueType.AssemblyQualifiedName.Contains("System.Private")
                || valueType.AssemblyQualifiedName.Contains("mscorlib"))
            {
                // This comparison is a check to ensure assembly information is not embedded in data.
                // Use type.FullName instead of type.AssemblyQualifiedName since the internal assemblies
                // are different in desktop and coreclr. Thus AQN in coreclr includes System.Private.CoreLib which
                // is not available on the desktop.
                // Note that this doesn't handle generic types. Such types will fail during serialization.
                this.ValueType = valueType.FullName;
            }
            else if (valueType.GetTypeInfo().IsValueType)
            {
                // In case of custom types, let the assembly qualified name be available to help
                // deserialization on the client.
                this.ValueType = valueType.AssemblyQualifiedName;
            }
            else
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.Resources.UnexpectedTypeOfProperty, valueType, id));
            }

            this.Id = id;
            this.Label = label;
            this.Category = category;
            this.Description = description;
            this.ValidateValueCallback = validateValueCallback;
            this.Attributes = attributes;
            this.valueType = valueType;
        }
Пример #2
0
        /// <summary>
        /// Convert passed in value into the specified type when property is registered.
        /// </summary>
        /// <returns>Converted object</returns>
        private static T ConvertPropertyTo <T>(TestProperty property, CultureInfo culture, object value)
        {
            ValidateArg.NotNull(property, "property");
            ValidateArg.NotNull(culture, "culture");

            var lazyValue = value as LazyPropertyValue <T>;

            if (value == null)
            {
                return(default(T));
            }
            else if (value is T)
            {
                return((T)value);
            }
            else if (lazyValue != null)
            {
                return(lazyValue.Value);
            }

            var valueType = property.GetValueType();

            TypeConverter converter = TypeDescriptor.GetConverter(valueType);

            if (converter == null)
            {
                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Resources.Resources.ConverterNotSupported, valueType.Name));
            }

            try
            {
                return((T)converter.ConvertTo(null, culture, value, typeof(T)));
            }
            catch (FormatException)
            {
                throw;
            }
            catch (Exception e)
            {
                // some type converters throw strange exceptions (e.g.: System.Exception by Int32Converter)
                throw new FormatException(e.Message, e);
            }
        }
Пример #3
0
        /// <summary>
        /// Convert passed in value from TestProperty's specified value type.
        /// </summary>
        /// <returns>Converted object</returns>
        private static object ConvertPropertyFrom <T>(TestProperty property, CultureInfo culture, object value)
        {
            ValidateArg.NotNull(property, "property");
            ValidateArg.NotNull(culture, "culture");

            var valueType = property.GetValueType();

            // Do not try conversion if the object is already of the type we're trying to convert.
            // Note that typeof(T) may be object in case the value is getting deserialized via the StoreKvpList, however
            // the deserializer could have converted it already, hence the runtime type check.
            if (valueType != null && (valueType.GetTypeInfo().IsAssignableFrom(typeof(T).GetTypeInfo()) || valueType.GetTypeInfo().IsAssignableFrom(value?.GetType().GetTypeInfo())))
            {
                return(value);
            }

            TypeConverter converter = TypeDescriptor.GetConverter(valueType);

            if (converter == null)
            {
                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Resources.Resources.ConverterNotSupported, valueType.Name));
            }

            try
            {
                return(converter.ConvertFrom(null, culture, value));
            }
            catch (FormatException)
            {
                throw;
            }
            catch (Exception e)
            {
                // some type converters throw strange exceptions (eg: System.Exception by Int32Converter)
                throw new FormatException(e.Message, e);
            }
        }
Пример #4
0
        internal static DataCollectorSettings FromXml(XmlReader reader)
        {
            DataCollectorSettings settings = new DataCollectorSettings();

            settings.IsEnabled = true;
            bool empty = reader.IsEmptyElement;

            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    switch (reader.Name)
                    {
                    case "uri":
                        ValidateArg.NotNullOrEmpty(reader.Value, "uri");
                        try
                        {
                            settings.Uri = new Uri(reader.Value);
                        }
                        catch (UriFormatException)
                        {
                            throw new SettingsException(String.Format(CultureInfo.CurrentCulture, Resources.Resources.InvalidDataCollectorUriInSettings, reader.Value));
                        }

                        break;

                    case "assemblyQualifiedName":
                        ValidateArg.NotNullOrEmpty(reader.Value, "assemblyQualifiedName");
                        settings.AssemblyQualifiedName = reader.Value;
                        break;

                    case "friendlyName":
                        ValidateArg.NotNullOrEmpty(reader.Value, "FriendlyName");
                        settings.FriendlyName = reader.Value;
                        break;

                    case "enabled":
                        settings.IsEnabled = bool.Parse(reader.Value);
                        break;

                    case "codebase":
                        settings.CodeBase = reader.Value;     // Optional.
                        break;

                    default:
                        throw new SettingsException(
                                  String.Format(
                                      CultureInfo.CurrentCulture,
                                      Resources.Resources.InvalidSettingsXmlAttribute,
                                      Constants.DataCollectionRunSettingsName,
                                      reader.Name));
                    }
                }
            }

            if (string.IsNullOrWhiteSpace(settings.FriendlyName))
            {
                throw new SettingsException(
                          String.Format(CultureInfo.CurrentCulture, Resources.Resources.MissingDataCollectorAttributes, "FriendlyName"));
            }

            reader.Read();
            if (!empty)
            {
                while (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                    case "Configuration":
                        XmlDocument doc     = new XmlDocument();
                        XmlElement  element = doc.CreateElement("Configuration");
                        element.InnerXml       = reader.ReadInnerXml();
                        settings.Configuration = element;
                        break;

                    default:
                        throw new SettingsException(
                                  String.Format(
                                      CultureInfo.CurrentCulture,
                                      Resources.Resources.InvalidSettingsXmlElement,
                                      Constants.DataCollectionRunSettingsName,
                                      reader.Name));
                    }
                }
                reader.ReadEndElement();
            }
            return(settings);
        }
Пример #5
0
        /// <summary>
        /// Loads RunConfiguration from XmlReader.
        /// </summary>
        /// <param name="reader">XmlReader having run configuration node.</param>
        /// <returns></returns>
        public static RunConfiguration FromXml(XmlReader reader)
        {
            ValidateArg.NotNull <XmlReader>(reader, "reader");
            var runConfiguration = new RunConfiguration();
            var empty            = reader.IsEmptyElement;

            XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);

            // Process the fields in Xml elements
            reader.Read();
            if (!empty)
            {
                while (reader.NodeType == XmlNodeType.Element)
                {
                    string elementName = reader.Name;
                    switch (elementName)
                    {
                    case "ResultsDirectory":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
                        runConfiguration.ResultsDirectory = reader.ReadElementContentAsString();
                        break;

                    case "CollectSourceInformation":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
                        string collectSourceInformationStr = reader.ReadElementContentAsString();

                        bool bCollectSourceInformation = true;
                        if (!bool.TryParse(collectSourceInformationStr, out bCollectSourceInformation))
                        {
                            throw new SettingsException(String.Format(CultureInfo.CurrentCulture,
                                                                      Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, bCollectSourceInformation, elementName));
                        }

                        runConfiguration.ShouldCollectSourceInformation = bCollectSourceInformation;
                        break;

                    case "MaxCpuCount":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);

                        string cpuCount = reader.ReadElementContentAsString();
                        int    count;
                        if (!int.TryParse(cpuCount, out count) || count < 0)
                        {
                            throw new SettingsException(
                                      string.Format(
                                          CultureInfo.CurrentCulture,
                                          Resources.Resources.InvalidSettingsIncorrectValue,
                                          Constants.RunConfigurationSettingsName,
                                          cpuCount,
                                          elementName));
                        }

                        runConfiguration.MaxCpuCount = count;
                        break;

                    case "BatchSize":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);

                        string batchSize = reader.ReadElementContentAsString();
                        long   size;
                        if (!long.TryParse(batchSize, out size) || size < 0)
                        {
                            throw new SettingsException(
                                      string.Format(
                                          CultureInfo.CurrentCulture,
                                          Resources.Resources.InvalidSettingsIncorrectValue,
                                          Constants.RunConfigurationSettingsName,
                                          batchSize,
                                          elementName));
                        }

                        runConfiguration.BatchSize = size;
                        break;

                    case "TestSessionTimeout":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);

                        string testSessionTimeout = reader.ReadElementContentAsString();
                        long   sessionTimeout;
                        if (!long.TryParse(testSessionTimeout, out sessionTimeout) || sessionTimeout < 0)
                        {
                            throw new SettingsException(
                                      string.Format(
                                          CultureInfo.CurrentCulture,
                                          Resources.Resources.InvalidSettingsIncorrectValue,
                                          Constants.RunConfigurationSettingsName,
                                          testSessionTimeout,
                                          elementName));
                        }

                        runConfiguration.TestSessionTimeout = sessionTimeout;
                        break;

                    case "DesignMode":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);

                        string designModeValueString = reader.ReadElementContentAsString();
                        bool   designMode;
                        if (!bool.TryParse(designModeValueString, out designMode))
                        {
                            throw new SettingsException(String.Format(CultureInfo.CurrentCulture,
                                                                      Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, designModeValueString, elementName));
                        }
                        runConfiguration.DesignMode = designMode;
                        break;

                    case "InIsolation":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);

                        string inIsolationValueString = reader.ReadElementContentAsString();
                        bool   inIsolation;
                        if (!bool.TryParse(inIsolationValueString, out inIsolation))
                        {
                            throw new SettingsException(String.Format(CultureInfo.CurrentCulture,
                                                                      Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, inIsolationValueString, elementName));
                        }
                        runConfiguration.InIsolation = inIsolation;
                        break;

                    case "DisableAppDomain":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);

                        string disableAppDomainValueString = reader.ReadElementContentAsString();
                        bool   disableAppDomainCheck;
                        if (!bool.TryParse(disableAppDomainValueString, out disableAppDomainCheck))
                        {
                            throw new SettingsException(String.Format(CultureInfo.CurrentCulture,
                                                                      Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, disableAppDomainValueString, elementName));
                        }
                        runConfiguration.DisableAppDomain = disableAppDomainCheck;
                        break;

                    case "DisableParallelization":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);

                        string disableParallelizationValueString = reader.ReadElementContentAsString();
                        bool   disableParallelizationCheck;
                        if (!bool.TryParse(disableParallelizationValueString, out disableParallelizationCheck))
                        {
                            throw new SettingsException(String.Format(CultureInfo.CurrentCulture,
                                                                      Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, disableParallelizationValueString, elementName));
                        }
                        runConfiguration.DisableParallelization = disableParallelizationCheck;
                        break;

                    case "TargetPlatform":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
                        Architecture archType;
                        string       value = reader.ReadElementContentAsString();
                        try
                        {
                            archType = (Architecture)Enum.Parse(typeof(Architecture), value, true);
                            if (archType != Architecture.X64 && archType != Architecture.X86 && archType != Architecture.ARM)
                            {
                                throw new SettingsException(
                                          string.Format(
                                              CultureInfo.CurrentCulture,
                                              Resources.Resources.InvalidSettingsIncorrectValue,
                                              Constants.RunConfigurationSettingsName,
                                              value,
                                              elementName));
                            }
                        }
                        catch (ArgumentException)
                        {
                            throw new SettingsException(string.Format(CultureInfo.CurrentCulture,
                                                                      Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, value, elementName));
                        }

                        runConfiguration.TargetPlatform = archType;
                        break;

                    case "TargetFrameworkVersion":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
                        Framework frameworkType;
                        value = reader.ReadElementContentAsString();
                        try
                        {
                            frameworkType = Framework.FromString(value);

                            if (frameworkType == null)
                            {
                                throw new SettingsException(
                                          string.Format(
                                              CultureInfo.CurrentCulture,
                                              Resources.Resources.InvalidSettingsIncorrectValue,
                                              Constants.RunConfigurationSettingsName,
                                              value,
                                              elementName));
                            }
                        }
                        catch (ArgumentException)
                        {
                            throw new SettingsException(string.Format(CultureInfo.CurrentCulture,
                                                                      Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, value, elementName));
                        }

                        runConfiguration.TargetFramework = frameworkType;
                        break;

                    case "TestAdaptersPaths":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
                        runConfiguration.TestAdaptersPaths = reader.ReadElementContentAsString();
                        break;

                    case "TreatTestAdapterErrorsAsWarnings":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
                        bool treatTestAdapterErrorsAsWarnings = false;

                        value = reader.ReadElementContentAsString();

                        try
                        {
                            treatTestAdapterErrorsAsWarnings = bool.Parse(value);
                        }
                        catch (ArgumentException)
                        {
                            throw new SettingsException(string.Format(CultureInfo.CurrentCulture,
                                                                      Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, value, elementName));
                        }
                        catch (FormatException)
                        {
                            throw new SettingsException(string.Format(CultureInfo.CurrentCulture,
                                                                      Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, value, elementName));
                        }

                        runConfiguration.TreatTestAdapterErrorsAsWarnings = treatTestAdapterErrorsAsWarnings;
                        break;

                    case "SolutionDirectory":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
                        string solutionDirectory = reader.ReadElementContentAsString();
                        solutionDirectory = Environment.ExpandEnvironmentVariables(solutionDirectory);
                        if (string.IsNullOrEmpty(solutionDirectory) || !Directory.Exists(solutionDirectory))
                        {
                            if (EqtTrace.IsErrorEnabled)
                            {
                                EqtTrace.Error(string.Format(CultureInfo.CurrentCulture, Resources.Resources.SolutionDirectoryNotExists, solutionDirectory));
                            }

                            solutionDirectory = null;
                        }

                        runConfiguration.SolutionDirectory = solutionDirectory;

                        break;

                    case "BinariesRoot":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
                        runConfiguration.BinariesRoot = reader.ReadElementContentAsString();
                        break;

                    case "ExecutionThreadApartmentState":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
                        string executionThreadApartmentState = reader.ReadElementContentAsString();
                        PlatformApartmentState apartmentState;
                        if (!Enum.TryParse(executionThreadApartmentState, out apartmentState))
                        {
                            throw new SettingsException(
                                      string.Format(
                                          CultureInfo.CurrentCulture,
                                          Resources.Resources.InvalidSettingsIncorrectValue,
                                          Constants.RunConfigurationSettingsName,
                                          executionThreadApartmentState,
                                          elementName));
                        }

                        runConfiguration.ExecutionThreadApartmentState = apartmentState;
                        break;

                    case "TargetDevice":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
                        runConfiguration.TargetDevice = reader.ReadElementContentAsString();
                        break;

                    default:
                        // Ignore a runsettings element that we don't understand. It could occur in the case
                        // the test runner is of a newer version, but the test host is of an earlier version.
                        if (EqtTrace.IsErrorEnabled)
                        {
                            EqtTrace.Warning(
                                string.Format(
                                    CultureInfo.CurrentCulture,
                                    Resources.Resources.InvalidSettingsXmlElement,
                                    Constants.RunConfigurationSettingsName,
                                    reader.Name));
                        }
                        reader.Skip();
                        break;
                    }
                }

                reader.ReadEndElement();
            }

            return(runConfiguration);
        }
Пример #6
0
        private Type GetType(string typeName)
        {
            ValidateArg.NotNull(typeName, "typeName");

            Type type = null;

            try
            {
                // This only works for the type is in the currently executing assembly or in Mscorlib.dll.
                type = Type.GetType(typeName);

                if (type == null)
                {
                    type = Type.GetType(typeName.Replace("Version=4.0.0.0", "Version=2.0.0.0")); // Try 2.0 version as discovery returns version of 4.0 for all cases
                }

                // For UAP the type namespace for System.Uri,System.TimeSpan and System.DateTimeOffset differs from the desktop version.
                if (type == null && typeName.StartsWith("System.Uri"))
                {
                    type = typeof(System.Uri);
                }
                else if (type == null && typeName.StartsWith("System.TimeSpan"))
                {
                    type = typeof(System.TimeSpan);
                }
                else if (type == null && typeName.StartsWith("System.DateTimeOffset"))
                {
                    type = typeof(System.DateTimeOffset);
                }
                else if (type == null && typeName.StartsWith("System.Int16"))
                {
                    // For LineNumber property - Int is required
                    type = typeof(System.Int16);
                }
                else if (type == null && typeName.StartsWith("System.Int32"))
                {
                    type = typeof(System.Int32);
                }
                else if (type == null && typeName.StartsWith("System.Int64"))
                {
                    type = typeof(System.Int64);
                }
            }
            catch (Exception)
            {
#if FullCLR
                // Try to see if the typeName contains Windows Phone PKT in that case load it from
                // desktop side
                if (typeName.Contains(s_windowsPhonePKT))
                {
                    type = this.GetType(typeName.Replace(s_windowsPhonePKT, s_visualStudioPKT));
                }

                if (type == null)
                {
                    System.Diagnostics.Debug.Fail("The test property type " + typeName + " of property " + this.id + "is not supported.");
#else
                System.Diagnostics.Debug.WriteLine("The test property type " + typeName + " of property " + this.Id + "is not supported.");
#endif
#if FullCLR
                }
#endif
            }
            finally
            {
                // default is of string type.
                if (type == null)
                {
                    type = typeof(string);
                }
            }

            return type;
        }
Пример #7
0
 internal DiaSession(string binaryPath, string searchPath, ISymbolReader symbolReader)
 {
     this.symbolReader = symbolReader;
     ValidateArg.NotNullOrEmpty(binaryPath, "binaryPath");
     this.symbolReader.CacheSymbols(binaryPath, searchPath);
 }
Пример #8
0
        public void Add(string name, string value)
        {
            ValidateArg.NotNull(name, "name");

            this.Add(new Trait(name, value));
        }
Пример #9
0
        public void Add(Trait trait)
        {
            ValidateArg.NotNull(trait, "trait");

            this.AddRange(new[] { trait });
        }
Пример #10
0
        internal TraitCollection(TestObject testObject)
        {
            ValidateArg.NotNull(testObject, "testObject");

            this.testObject = testObject;
        }
Пример #11
0
        /// <summary>
        /// Initializes with the name of the test case.
        /// </summary>
        /// <param name="name">The name of the test case.</param>
        protected TestRunSettings(string name)
        {
            ValidateArg.NotNullOrEmpty(name, "name");

            this.name = name;
        }
Пример #12
0
        /// <summary>
        /// Loads RunConfiguration from XmlReader.
        /// </summary>
        /// <param name="reader">XmlReader having run configuration node.</param>
        /// <returns></returns>
        public static RunConfiguration FromXml(XmlReader reader)
        {
            ValidateArg.NotNull <XmlReader>(reader, "reader");
            var runConfiguration = new RunConfiguration();
            var empty            = reader.IsEmptyElement;

            XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);

            // Process the fields in Xml elements
            reader.Read();
            if (!empty)
            {
                while (reader.NodeType == XmlNodeType.Element)
                {
                    string elementName = reader.Name;
                    switch (elementName)
                    {
                    case "ResultsDirectory":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
                        runConfiguration.ResultsDirectory = reader.ReadElementContentAsString();
                        break;

                    case "MaxCpuCount":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);

                        string cpuCount = reader.ReadElementContentAsString();
                        int    count;
                        if (!int.TryParse(cpuCount, out count) || count < 0)
                        {
                            throw new SettingsException(
                                      string.Format(
                                          CultureInfo.CurrentCulture,
                                          Resources.Resources.InvalidSettingsIncorrectValue,
                                          Constants.RunConfigurationSettingsName,
                                          cpuCount,
                                          elementName));
                        }

                        runConfiguration.MaxCpuCount = count;
                        break;

                    case "DisableAppDomain":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);

                        string disableAppDomainValueString = reader.ReadElementContentAsString();
                        bool   disableAppDomainCheck;
                        if (!bool.TryParse(disableAppDomainValueString, out disableAppDomainCheck))
                        {
                            throw new SettingsException(String.Format(CultureInfo.CurrentCulture,
                                                                      Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, disableAppDomainValueString, elementName));
                        }
                        runConfiguration.DisableAppDomain = disableAppDomainCheck;
                        break;

                    case "DisableParallelization":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);

                        string disableParallelizationValueString = reader.ReadElementContentAsString();
                        bool   disableParallelizationCheck;
                        if (!bool.TryParse(disableParallelizationValueString, out disableParallelizationCheck))
                        {
                            throw new SettingsException(String.Format(CultureInfo.CurrentCulture,
                                                                      Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, disableParallelizationValueString, elementName));
                        }
                        runConfiguration.DisableParallelization = disableParallelizationCheck;
                        break;

                    case "TargetPlatform":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
                        Architecture archType;
                        string       value = reader.ReadElementContentAsString();
                        try
                        {
                            archType = (Architecture)Enum.Parse(typeof(Architecture), value, true);
                            if (archType != Architecture.X64 && archType != Architecture.X86 && archType != Architecture.ARM)
                            {
                                throw new SettingsException(
                                          string.Format(
                                              CultureInfo.CurrentCulture,
                                              Resources.Resources.InvalidSettingsIncorrectValue,
                                              Constants.RunConfigurationSettingsName,
                                              value,
                                              elementName));
                            }
                        }
                        catch (ArgumentException)
                        {
                            throw new SettingsException(string.Format(CultureInfo.CurrentCulture,
                                                                      Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, value, elementName));
                        }

                        runConfiguration.TargetPlatform = archType;
                        break;

                    case "TargetFrameworkVersion":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
                        Framework frameworkType;
                        value = reader.ReadElementContentAsString();
                        try
                        {
                            frameworkType = Framework.FromString(value);

                            if (frameworkType == null)
                            {
                                throw new SettingsException(
                                          string.Format(
                                              CultureInfo.CurrentCulture,
                                              Resources.Resources.InvalidSettingsIncorrectValue,
                                              Constants.RunConfigurationSettingsName,
                                              value,
                                              elementName));
                            }
                        }
                        catch (ArgumentException)
                        {
                            throw new SettingsException(string.Format(CultureInfo.CurrentCulture,
                                                                      Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, value, elementName));
                        }

                        runConfiguration.TargetFrameworkVersion = frameworkType;
                        break;

                    case "TestAdaptersPaths":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
                        runConfiguration.TestAdaptersPaths = reader.ReadElementContentAsString();
                        break;

                    case "TreatTestAdapterErrorsAsWarnings":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
                        bool treatTestAdapterErrorsAsWarnings = false;

                        value = reader.ReadElementContentAsString();

                        try
                        {
                            treatTestAdapterErrorsAsWarnings = bool.Parse(value);
                        }
                        catch (ArgumentException)
                        {
                            throw new SettingsException(string.Format(CultureInfo.CurrentCulture,
                                                                      Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, value, elementName));
                        }
                        catch (FormatException)
                        {
                            throw new SettingsException(string.Format(CultureInfo.CurrentCulture,
                                                                      Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, value, elementName));
                        }

                        runConfiguration.TreatTestAdapterErrorsAsWarnings = treatTestAdapterErrorsAsWarnings;
                        break;

                    case "SolutionDirectory":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
                        string solutionDirectory = reader.ReadElementContentAsString();
                        solutionDirectory = Environment.ExpandEnvironmentVariables(solutionDirectory);
                        if (string.IsNullOrEmpty(solutionDirectory) || !Directory.Exists(solutionDirectory))
                        {
                            if (EqtTrace.IsErrorEnabled)
                            {
                                EqtTrace.Error(string.Format(CultureInfo.CurrentCulture, Resources.Resources.SolutionDirectoryNotExists, solutionDirectory));
                            }

                            solutionDirectory = null;
                        }

                        runConfiguration.SolutionDirectory = solutionDirectory;

                        break;

                    case "BinariesRoot":
                        XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
                        runConfiguration.BinariesRoot = reader.ReadElementContentAsString();
                        break;

                    default:
                        throw new SettingsException(
                                  string.Format(
                                      CultureInfo.CurrentCulture,
                                      Resources.Resources.InvalidSettingsXmlElement,
                                      Constants.RunConfigurationSettingsName,
                                      reader.Name));
                    }
                }

                reader.ReadEndElement();
            }

            return(runConfiguration);
        }