Ejemplo n.º 1
0
        /// <summary>
        /// Provides a way of seeing what got "rendered" on the Screen. Use this when you want
        /// to understand which elements and properties are present at the screen.
        /// </summary>
        /// <remarks>If you want to customize how this method works, check <see cref="DebugOptions"/>.</remarks>
        /// <returns>A string representing the screen's elements and its properties.</returns>
        public string Debug()
        {
            var renderedHierarchy = new Tree(Container);
            var _ = Container.GetPageHierarchy <View>(renderedHierarchy).ToList();

            var debugText = TestingLibraryOptions.DebugOptions.TreeFormatter.FormatTree(renderedHierarchy);

            TestingLibraryOptions.DebugOptions.OutputTextWriter.Write(debugText);

            return(debugText);
        }
        public string FormatTree(Tree debugTree)
        {
            using var stringBuffer   = new StringWriter();
            _ansiConsoleSettings.Out = stringBuffer;
            var ansiConsole = AnsiConsole.Create(_ansiConsoleSettings);

            var consoleTree = new SpectreTree(debugTree.Root.DebugElement.Element.GetType().Name);

            foreach (var rootNode in debugTree.Nodes)
            {
                FormatTreeNode(rootNode, consoleTree);
            }

            ansiConsole.Render(consoleTree);
            return(stringBuffer.ToString());
        }