Example #1
0
 public Visitor(IFilter filter, IPropertyValueTranslator translator, IVisualTreeLogger logger)
 {
     _indent     = 0;
     _filter     = filter;
     _translator = translator;
     _logger     = logger;
 }
 public TestExecution(IPropertyValueTranslator translator = null, IFilter filter = null, IVisualTreeLogger logger = null, bool shouldLogMasterFile = true)
 {
     _translator          = translator;
     _filter              = filter;
     _logger              = logger;
     _shouldLogMasterFile = shouldLogMasterFile;
     _testResult          = new StringBuilder();
 }
Example #3
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());
        }
        public static string DumpVisualTree(DependencyObject root, IPropertyValueTranslator translator = null, IFilter filter = null, IVisualTreeLogger logger = null)
        {
            VisualTreeLog.LogDebugInfo("DumpVisualTree");

            string content = "";

            RunOnUIThread.Execute(() =>
            {
                content = VisualTreeDumper.DumpToXML(root, translator, filter, logger);
            });
            return(content);
        }
        public static void VerifyVisualTree(UIElement root, string masterFilePrefix, Theme theme = Theme.None, IPropertyValueTranslator translator = null, IFilter filter = null, IVisualTreeLogger logger = null)
        {
            VisualTreeLog.LogInfo("VerifyVisualTree for theme " + theme.ToString());
            TestExecution helper = new TestExecution(translator, filter, logger, AlwaysLogMasterFile);

            if (theme == Theme.None)
            {
                helper.DumpAndVerifyVisualTree(root, masterFilePrefix);
            }
            else
            {
                List <ElementTheme> themes = new List <ElementTheme>();
                if (theme == Theme.Dark)
                {
                    themes.Add(ElementTheme.Dark);
                }
                else if (theme == Theme.Light)
                {
                    themes.Add(ElementTheme.Light);
                }
                else if (theme == Theme.All)
                {
                    themes = new List <ElementTheme>()
                    {
                        ElementTheme.Dark, ElementTheme.Light
                    };
                }

                foreach (var requestedTheme in themes)
                {
                    string themeName = requestedTheme.ToString();
                    VisualTreeLog.LogInfo("Change RequestedTheme to " + themeName);
                    ChangeRequestedTheme(root, requestedTheme);

                    helper.DumpAndVerifyVisualTree(root, masterFilePrefix + "_" + themeName, "DumpAndVerifyVisualTree for " + themeName);
                }
            }
            if (helper.HasError())
            {
                Verify.Fail(helper.GetTestResult(), "Test Failed");
            }
        }
        public static void VerifyVisualTree(string xaml, string masterFilePrefix, Theme theme = Theme.None, IPropertyValueTranslator translator = null, IFilter filter = null, IVisualTreeLogger logger = null)
        {
            var root = SetupVisualTree(xaml);

            VerifyVisualTree(root, masterFilePrefix, theme, translator, filter, logger);
        }
Example #7
0
        public static string DumpToXML(DependencyObject root, IPropertyValueTranslator translator, IFilter filter, IVisualTreeLogger logger)
        {
            Visitor visitor = new Visitor(filter ?? new DefaultFilter(),
                                          translator ?? new DefaultPropertyValueTranslator(),
                                          logger ?? new DefaultVisualTreeLogger());

            WalkThroughTree(root, visitor);

            return(visitor.ToString());
        }
Example #8
0
 public void VerifyVisualTreeNoException(UIElement root, string verificationFileNamePrefix, Theme theme = Theme.None, IPropertyValueTranslator translator = null, IFilter filter = null, IVisualTreeLogger logger = null)
 {
     try
     {
         VisualTreeTestHelper.VerifyVisualTree(root, verificationFileNamePrefix, theme, translator, filter, logger);
     }
     catch (Exception e)
     {
         Log.Error(e.Message);
         hasFailed = true;
     }
 }
Example #9
0
 public void VerifyVisualTreeNoException(string xaml, string masterFilePrefix, Theme theme = Theme.None, IPropertyValueTranslator translator = null, IFilter filter = null, IVisualTreeLogger logger = null)
 {
     try
     {
         VisualTreeTestHelper.VerifyVisualTree(xaml, masterFilePrefix, theme, translator, filter, logger);
     }
     catch (Exception e)
     {
         Log.Error(e.Message);
         hasFailed = true;
     }
 }
Example #10
0
 public void VerifyVisualTree(UIElement root, string masterFilePrefix, Theme theme = Theme.None, IPropertyValueTranslator translator = null, IFilter filter = null, IVisualTreeLogger logger = null)
 {
     Verify.DisableVerifyFailureExceptions = true;
     try
     {
         if (!VisualTreeTestHelper.VerifyVisualTree(root, masterFilePrefix, theme, translator, filter, logger))
         {
             hasFailed = true;
         }
     }
     finally
     {
         Verify.DisableVerifyFailureExceptions = false;
     }
 }