private void ReadConfig(string configFile) { if (string.IsNullOrEmpty(configFile)) { throw new ArgumentNullException(); //illegal use } XmlDocument config = new XmlDocument(); try { config.Load(configFile); } catch (FileNotFoundException) { string errorMsg = string.Format("{0} file not found", configFile); throw new FileNotFoundException(errorMsg); } catch (Exception) { throw; } XmlNode root = config.SelectSingleNode("TestConfig"); if (root != null) { foreach (XmlNode node in root.ChildNodes) { XmlElement eleNode = node as XmlElement; if (eleNode == null) { continue; } if (string.Compare(eleNode.Name.ToLower(), "testclass") == 0 && eleNode.Attributes["name"] != null) { ClassConfig classConfig = this[eleNode.Attributes["name"].Value]; if(classConfig == null) classConfig = new ClassConfig(); foreach (XmlNode subnode in eleNode.ChildNodes) { XmlElement eleSubnode = subnode as XmlElement; if (eleSubnode == null) { continue; } if (string.Compare(eleSubnode.Name.ToLower(), "testmethod") == 0 && eleSubnode.Attributes["name"] != null) { MethodConfig methodConfig = classConfig[eleSubnode.Attributes["name"].Value]; if (methodConfig == null) methodConfig = new MethodConfig(); foreach (XmlNode methodParamNode in eleSubnode.ChildNodes) { XmlElement eleMethodParamNode = methodParamNode as XmlElement; if (eleMethodParamNode == null) { continue; } methodConfig[eleMethodParamNode.Name] = eleMethodParamNode.InnerText; } classConfig[eleSubnode.Attributes["name"].Value] = methodConfig; continue; } classConfig.ClassParams[eleSubnode.Name] = eleSubnode.InnerText; } this[eleNode.Attributes["name"].Value] = classConfig; continue; } TestParams[eleNode.Name] = eleNode.InnerText; } } }
private void ReadConfig(string configFile) { if (string.IsNullOrEmpty(configFile)) { throw new ArgumentNullException(); //illegal use } XmlDocument config = new XmlDocument(); try { config.Load(configFile); } catch (FileNotFoundException) { string errorMsg = string.Format("{0} file not found", configFile); throw new FileNotFoundException(errorMsg); } catch (Exception) { throw; } XmlNode root = config.SelectSingleNode("TestConfig"); if (root != null) { foreach (XmlNode node in root.ChildNodes) { XmlElement eleNode = node as XmlElement; if (eleNode == null) { continue; } if (string.Compare(eleNode.Name.ToLower(), "testclass") == 0 && eleNode.Attributes["name"] != null) { ClassConfig classConfig = this[eleNode.Attributes["name"].Value]; if (classConfig == null) { classConfig = new ClassConfig(); } foreach (XmlNode subnode in eleNode.ChildNodes) { XmlElement eleSubnode = subnode as XmlElement; if (eleSubnode == null) { continue; } if (string.Compare(eleSubnode.Name.ToLower(), "testmethod") == 0 && eleSubnode.Attributes["name"] != null) { MethodConfig methodConfig = classConfig[eleSubnode.Attributes["name"].Value]; if (methodConfig == null) { methodConfig = new MethodConfig(); } foreach (XmlNode methodParamNode in eleSubnode.ChildNodes) { XmlElement eleMethodParamNode = methodParamNode as XmlElement; if (eleMethodParamNode == null) { continue; } methodConfig[eleMethodParamNode.Name] = eleMethodParamNode.InnerText; } classConfig[eleSubnode.Attributes["name"].Value] = methodConfig; continue; } classConfig.ClassParams[eleSubnode.Name] = eleSubnode.InnerText; } this[eleNode.Attributes["name"].Value] = classConfig; continue; } TestParams[eleNode.Name] = eleNode.InnerText; } } }
private void ReadConfig(string configFile) { if (string.IsNullOrEmpty(configFile)) { throw new ArgumentNullException(); //illegal use } XmlDocument config = new XmlDocument(); try { #if DOTNET5_4 Stream configStream = File.OpenRead(configFile); config.Load(configStream); #else config.Load(configFile); #endif } catch (FileNotFoundException) { string errorMsg = string.Format("{0} file not found", configFile); throw new FileNotFoundException(errorMsg); } catch (Exception) { throw; } #if DOTNET5_4 System.Xml.XPath.XPathNavigator navigator = config.DocumentElement.CreateNavigator(); XmlNode root = navigator.SelectSingleNode("/TestConfig").UnderlyingObject as XmlNode; #else XmlNode root = config.SelectSingleNode("TestConfig"); #endif if (root != null) { foreach (XmlNode node in root.ChildNodes) { XmlElement eleNode = node as XmlElement; if (eleNode == null) { continue; } if (string.Compare(eleNode.Name.ToLower(), "testclass") == 0 && eleNode.Attributes["name"] != null) { ClassConfig classConfig = this[eleNode.Attributes["name"].Value]; if (classConfig == null) { classConfig = new ClassConfig(); } foreach (XmlNode subnode in eleNode.ChildNodes) { XmlElement eleSubnode = subnode as XmlElement; if (eleSubnode == null) { continue; } if (string.Compare(eleSubnode.Name.ToLower(), "testmethod") == 0 && eleSubnode.Attributes["name"] != null) { MethodConfig methodConfig = classConfig[eleSubnode.Attributes["name"].Value]; if (methodConfig == null) { methodConfig = new MethodConfig(); } foreach (XmlNode methodParamNode in eleSubnode.ChildNodes) { XmlElement eleMethodParamNode = methodParamNode as XmlElement; if (eleMethodParamNode == null) { continue; } methodConfig[eleMethodParamNode.Name] = eleMethodParamNode.InnerText; } classConfig[eleSubnode.Attributes["name"].Value] = methodConfig; continue; } classConfig.ClassParams[eleSubnode.Name] = eleSubnode.InnerText; } this[eleNode.Attributes["name"].Value] = classConfig; continue; } TestParams[eleNode.Name] = eleNode.InnerText; } } }