/// <summary> /// Create a feature mapping table /// </summary> /// <returns>A feature mapping table</returns> private Dictionary <string, List <Rule> > CreateFeatureMappingTable() { if (targetFilterIndex == -1 || mappingFilterIndex == -1) { return(null); } Dictionary <string, List <Rule> > featureMappingTable = new Dictionary <string, List <Rule> >(); RuleGroup targetFilterGroup = filter[targetFilterIndex]; RuleGroup mappingFilterGroup = filter[mappingFilterIndex]; Dictionary <string, Rule> mappingRuleTable = createRuleTableFromRuleGroup(mappingFilterGroup); Dictionary <string, Rule> targetRuleTable = createRuleTableFromRuleGroup(targetFilterGroup); List <TestCase> testCaseList = testSuite.TestCaseList; foreach (TestCase testCase in testCaseList) { List <string> categories = testCase.Category; foreach (string target in targetRuleTable.Keys) { if (categories.Contains(target)) { Rule currentRule; foreach (string category in categories) { if (!category.Equals(target)) { mappingRuleTable.TryGetValue(category, out currentRule); if (currentRule == null) { continue; } if (featureMappingTable.ContainsKey(target)) { featureMappingTable[target].Add(currentRule); } else { featureMappingTable[target] = new List <Rule> { currentRule }; } } } break; } } } return(featureMappingTable); }
public static RuleGroup FromXmlNode(XmlNode node) { RuleType ruletype = RuleType.Selector; var ruleTypeAttribute = node.Attributes["type"]; if (ruleTypeAttribute != null) { ruletype = (RuleType)Enum.Parse(typeof(RuleType), ruleTypeAttribute.Value); } RuleGroup gp = new RuleGroup() { Name = node.Attributes["name"].Value, RuleGroupType = ruletype }; var rules = node.SelectNodes("Rule"); foreach (XmlNode rule in rules) { gp.Add(Rule.FromXmlNode(rule)); } return(gp); }
/// <summary> /// Create a dictionary (key: rule name, value: rule) to store rules from a given ruleGroup to speedup rule lookup performance /// </summary> /// <param name="ruleGroup">A rule group</param> /// <returns>A rule table</returns> private Dictionary <string, Rule> createRuleTableFromRuleGroup(RuleGroup ruleGroup) { Dictionary <string, Rule> ruleTable = new Dictionary <string, Rule>(); Stack <Rule> ruleStack = new Stack <Rule>(); foreach (Rule r in ruleGroup) { ruleStack.Push(r); } while (ruleStack.Count > 0) { Rule r = ruleStack.Pop(); if (r.CategoryList.Count != 0 && !ruleTable.ContainsKey(r.CategoryList[0])) { ruleTable.Add(r.CategoryList[0], r); } foreach (Rule childRule in r) { ruleStack.Push(childRule); } } return(ruleTable); }
/// <summary> /// Loads test suite assembly. /// </summary> public void LoadTestSuiteAssembly() { try { appConfig.GetAdapterMethods(); } catch (ReflectionTypeLoadException ex) { StringBuilder sb = new StringBuilder(); foreach (Exception exSub in ex.LoaderExceptions) { sb.AppendLine(exSub.Message); FileNotFoundException exFileNotFound = exSub as FileNotFoundException; if (exFileNotFound != null) { if (!string.IsNullOrEmpty(exFileNotFound.FusionLog)) { sb.AppendLine("Fusion Log:"); sb.AppendLine(exFileNotFound.FusionLog); } } sb.AppendLine(); } throw new Exception(string.Format(StringResource.LoadAdapterError, sb.ToString())); } catch (Exception e) { throw new Exception(string.Format(StringResource.LoadAdapterError, e.Message)); } testSuite = new TestSuite(); try { testSuite.LoadFrom(appConfig.VSTestPath, appConfig.TestSuiteDirectory, appConfig.TestSuiteAssembly); } catch (Exception e) { throw new Exception(string.Format(StringResource.LoadAssemblyError, e.Message)); } if (appConfig.TestCategory != null) { try { testSuite.AppendCategoryByConfigFile(appConfig.TestCategory); } catch (Exception e) { throw new Exception(string.Format(StringResource.AppendCategoryError, e.Message)); } } if (filter != null) { Dictionary <string, List <Rule> > reverseMappingTable; Dictionary <string, List <Rule> > featureMappingTable = CreateFeatureMappingTable(out reverseMappingTable); if (featureMappingTable != null) { RuleGroup targetFilterGroup = filter[targetFilterIndex]; RuleGroup mappingFilterGroup = filter[mappingFilterIndex]; targetFilterGroup.featureMappingTable = featureMappingTable; targetFilterGroup.mappingRuleGroup = mappingFilterGroup; mappingFilterGroup.reverseFeatureMappingTable = reverseMappingTable; mappingFilterGroup.targetRuleGroup = targetFilterGroup; } } }