private static ShowPlanElement ReadPlanElement(XPathNavigator elementNavigator) { ShowPlanOperator op = (ShowPlanOperator) Enum.Parse(typeof(ShowPlanOperator), elementNavigator.GetAttribute("operator", String.Empty)); List<ShowPlanProperty> properties = new List<ShowPlanProperty>(); foreach (XPathNavigator propertyNavigator in elementNavigator.Select("properties/property")) { string propertyName = propertyNavigator.GetAttribute("name", String.Empty); string propertyValue = propertyNavigator.GetAttribute("value", String.Empty); ShowPlanProperty property = new ShowPlanProperty(propertyName, propertyValue); properties.Add(property); } List<ShowPlanElement> children = new List<ShowPlanElement>(); foreach (XPathNavigator childNode in elementNavigator.Select("input/*")) { ShowPlanElement childElement = ReadPlanElement(childNode); children.Add(childElement); } ShowPlanElement element = new ShowPlanElement(op, properties, children); return element; }
private static void AreEqual(ShowPlanElement expectedPlanElement, ShowPlanElement actualPlanElement) { Assert.AreEqual(expectedPlanElement.Operator, actualPlanElement.Operator); Assert.AreEqual(expectedPlanElement.Properties.Count, actualPlanElement.Properties.Count, "Property count does not match."); for (int i = 0; i < expectedPlanElement.Properties.Count; i++) { ShowPlanProperty expectedProperty = expectedPlanElement.Properties[i]; ShowPlanProperty actualProperty = actualPlanElement.Properties[i]; Assert.AreEqual(expectedProperty.FullName, actualProperty.FullName, "Property full name does not match."); Assert.AreEqual(expectedProperty.Value, actualProperty.Value, "Value of property {0} does not match.", expectedProperty.FullName); } Assert.AreEqual(expectedPlanElement.Children.Count, actualPlanElement.Children.Count, "Count of children does not match."); for (int i = 0; i < expectedPlanElement.Children.Count; i++) { ShowPlanElement expectedChildElement = expectedPlanElement.Children[i]; ShowPlanElement actualChildElement = actualPlanElement.Children[i]; AreEqual(expectedChildElement, actualChildElement); } }
private static void AddChildrenToDictionary(List <ShowPlanProperty> target, string parentPath, Property property) { string path; if (parentPath == null) { path = Escape(property.Name); } else { path = parentPath + "." + Escape(property.Name); } if (property.Value != null) { ShowPlanProperty planProperty = new ShowPlanProperty(path, property.Value); target.Add(planProperty); } foreach (Property child in property.Children) { AddChildrenToDictionary(target, path, child); } }
private static void AddChildrenToDictionary(List<ShowPlanProperty> target, string parentPath, Property property) { string path; if (parentPath == null) path = Escape(property.Name); else path = parentPath + "." + Escape(property.Name); if (property.Value != null) { ShowPlanProperty planProperty = new ShowPlanProperty(path, property.Value); target.Add(planProperty); } foreach (Property child in property.Children) AddChildrenToDictionary(target, path, child); }