Пример #1
0
        public static string DumpTree(DependencyObject root, DependencyObject excludedNode, IList <string> additionalProperties, DumpTreeMode mode)
        {
            var propertyFilter = new DefaultFilter();

            ((List <string>)propertyFilter.PropertyNameAllowList).AddRange(additionalProperties);

            IPropertyValueTranslator translator = (mode == DumpTreeMode.Json ?
                                                   new JsonPropertyValueTranslator() as IPropertyValueTranslator :
                                                   new DefaultPropertyValueTranslator());
            IVisualTreeLogger logger = (mode == DumpTreeMode.Json ?
                                        new JsonVisualTreeLogger() as IVisualTreeLogger :
                                        new DefaultVisualTreeLogger());
            Visitor visitor = new Visitor(propertyFilter, translator, logger);

            WalkThroughTree(root, excludedNode, visitor);

            return(visitor.ToString());
        }
Пример #2
0
        internal static async Task <bool> MatchTreeDumpFromLayoutUpdateAsync(string dumpID, string uiaId, TextBlock textBlock, IList <string> additionalProperties, DumpTreeMode mode, string dumpExpectedText)
        {
            // First find root
            DependencyObject current = textBlock;
            DependencyObject parent  = VisualTreeHelper.GetParent(current);

            while (parent != null)
            {
                current = parent;
                parent  = VisualTreeHelper.GetParent(current);
            }

            DependencyObject dumpRoot = current;

            // if UIAID is passed in from test, find the matching child as the root to dump
            if (uiaId != null)
            {
                var matchingNode = FindChildWithMatchingUIAID(current, uiaId);
                if (matchingNode != null)
                {
                    dumpRoot = matchingNode;
                }
            }

            string dumpText = VisualTreeDumper.DumpTree(dumpRoot, textBlock /* exclude */, additionalProperties, mode);

            if (dumpText != dumpExpectedText)
            {
                return(await MatchDump(dumpText, dumpID));
            }
            return(true);
        }