private static RootNode BuildTree(XmlNode treeNode) { XmlAttribute nameAttr = GetAttributeByName(treeNode, "name"); if (treeNode.Name == "test") { XmlAttribute fileAttr = GetAttributeByName(treeNode, "file"); if (nameAttr != null && fileAttr != null) { return new TestNode(nameAttr.Value, fileAttr.Value); } } else { if (nameAttr != null) { GroupNode groupNode = new GroupNode(nameAttr.Value); foreach (XmlNode childNode in treeNode.ChildNodes) { RootNode child = BuildTree(childNode); if (child != null) { groupNode.Nodes.Add(child); } } return groupNode; } } return null; }
private static RootNode AddSubDirs(string dirPath, bool includeSubDirs) { bool hasTests = false; string dirName = System.IO.Path.GetFileNameWithoutExtension(dirPath); RootNode dirNode = new GroupNode(dirName); if (includeSubDirs) { string[] subDirs = System.IO.Directory.GetDirectories(dirPath); if (subDirs.Count() > 0) { foreach (string subDir in subDirs) { RootNode subDirNode = AddSubDirs(subDir, includeSubDirs); if (subDirNode != null) { dirNode.Nodes.Add(subDirNode); hasTests = true; } } } } string[] files = System.IO.Directory.GetFiles(dirPath, "*.xml"); if (files.Count() > 0) { foreach (string file in files) { string testName = System.IO.Path.GetFileNameWithoutExtension(file); TestNode testNode = new TestNode(testName, file); dirNode.Nodes.Add(testNode); } hasTests = true; } if (hasTests) { return dirNode; } return null; }