public void OnAllMutantsTested(IReadOnlyProjectComponent reportComponent)
        {
            Tree root = null;

            var stack = new Stack <IHasTreeNodes>();

            // setup display handlers
            reportComponent.DisplayFolder = (IReadOnlyProjectComponent current) =>
            {
                var name = Path.GetFileName(current.RelativePath);

                if (root is null)
                {
                    root = new Tree("All files" + DisplayComponent(current));
                    stack.Push(root);
                }
                else if (!string.IsNullOrWhiteSpace(name))
                {
                    stack.Push(stack.Peek().AddNode(name + DisplayComponent(current)));
                }
            };

            reportComponent.DisplayFile = (IReadOnlyProjectComponent current) =>
            {
                var name = Path.GetFileName(current.RelativePath);

                var fileNode = stack.Peek().AddNode(name + DisplayComponent(current));

                if (current.FullPath == current.Parent.Children.Last().FullPath)
                {
                    stack.Pop();
                }

                var totalMutants = current.TotalMutants();
                foreach (var mutant in totalMutants)
                {
                    var status = mutant.ResultStatus switch
                    {
                        MutantStatus.Killed or MutantStatus.Timeout => $"[Green][[{mutant.ResultStatus}]][/]",
                             MutantStatus.NoCoverage => $"[Yellow][[{mutant.ResultStatus}]][/]",
                             _ => $"[Red][[{mutant.ResultStatus}]][/]",
                    };

                    var mutantNode = fileNode.AddNode(status + $" {mutant.Mutation.DisplayName} on line {mutant.Line}");
                    mutantNode.AddNode(Markup.Escape($"[-] {mutant.Mutation.OriginalNode}"));
                    mutantNode.AddNode(Markup.Escape($"[+] {mutant.Mutation.ReplacementNode}"));
                }
            };

            // print empty line for readability
            _console.WriteLine();
            _console.WriteLine();
            _console.WriteLine("All mutants have been tested, and your mutation score has been calculated");

            // start recursive invocation of handlers
            reportComponent.Display();

            _console.Write(root);
        }
Beispiel #2
0
        public void Should_Escape_Markup_As_Expected(string input, string expected)
        {
            // Given, When
            var result = Markup.Escape(input);

            // Then
            result.ShouldBe(expected);
        }
Beispiel #3
0
        public static void LogError <T>(string message)
        {
            if (string.IsNullOrEmpty(message))
            {
                AnsiConsole.WriteLine();
                return;
            }

            var name = typeof(T).FullName;

            AnsiConsole.MarkupLine($"[bold red]fail[/]: {name}");
            AnsiConsole.MarkupLine($"      {Markup.Escape(message)}");
        }
Beispiel #4
0
        /// <inheritdoc cref="ILogger.Log{TState}(LogLevel, EventId, TState, Exception?, Func{TState, Exception?, string})"/>
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception?exception, Func <TState, Exception?, string> formatter)
        {
            if (!IsEnabled(logLevel))
            {
                return;
            }

            var stringBuilder = new StringBuilder(80);

            stringBuilder.Append(GetLevelMarkup(logLevel));
            stringBuilder.AppendFormat("[dim grey]{0}[/] ", _name);
            stringBuilder.Append(Markup.Escape(formatter(state, exception)));
            _console.MarkupLine(stringBuilder.ToString());
        }
        public static async ValueTask StartTaskAsync(
            this ProgressContext progressContext,
            string description,
            Func <ProgressTask, ValueTask> performOperationAsync)
        {
            var progressTask = progressContext.AddTask(
                // Don't recognize random square brackets as style tags
                Markup.Escape(description),
                new ProgressTaskSettings {
                MaxValue = 1
            }
                );

            try
            {
                await performOperationAsync(progressTask);
            }
            finally
            {
                progressTask.StopTask();
            }
        }
Beispiel #6
0
 public static void WriteWarning(string message)
 => AnsiConsole.MarkupLine($"[yellow]{Markup.Escape(message)}[/]");
Beispiel #7
0
 public static void WriteError(string message)
 => AnsiConsole.MarkupLine($"[red]{Markup.Escape(message)}[/]");
Beispiel #8
0
 public static void WriteInfo(string message)
 => AnsiConsole.MarkupLine($"[blue]{Markup.Escape(message)}[/]");
Beispiel #9
0
 public static void WriteSuccess(string message)
 => AnsiConsole.MarkupLine($"[green]{Markup.Escape(message)}[/]");
Beispiel #10
0
        static void Main(string[] args)
        {
            TextPrompt <string> modePrompt = new TextPrompt <string>("Select DynamoDB Connect Mode")
                                             .InvalidChoiceMessage("[red]Invalid Mode[/]")
                                             .AddChoice("ApiKey")
                                             .AddChoice("CredentialsFile")
                                             .DefaultValue("ApiKey");

            var    apiKey = ApiKey;
            var    secret = Secret;
            string credentialsFilePath = string.Empty;
            string profileName         = string.Empty;

            var mode = AnsiConsole.Prompt(modePrompt);

            if (mode == "ApiKey")
            {
                if (string.IsNullOrEmpty(apiKey))
                {
                    apiKey = AnsiConsole.Ask <string>("Enter your DynamoDB [blue]API Key[/]");
                }

                TextPrompt <string> secretPrompt = new TextPrompt <string>("Enter your DynamoDB [blue]API Secret[/]")
                                                   .PromptStyle("red")
                                                   .Secret();

                if (string.IsNullOrEmpty(secret))
                {
                    secret = AnsiConsole.Prompt(secretPrompt);
                }
            }
            else
            {
                var credentialsFilePathPrompt = new TextPrompt <string>("Enter your [blue]Credentials File Path[/]");
                credentialsFilePath = AnsiConsole.Prompt(credentialsFilePathPrompt);

                var profilePrompt = new TextPrompt <string>("Enter your [blue]Credentials Profile name[/]");

                profileName = AnsiConsole.Prompt(profilePrompt);
            }

            TextPrompt <string> regionPrompt = new TextPrompt <string>("Enter your DynamoDB [blue]Region[/]?")
                                               .InvalidChoiceMessage("[red]Invalid Region[/]")
                                               .DefaultValue("APNortheast2");

            foreach (string regionName in Enum.GetNames(typeof(AwsRegion)))
            {
                regionPrompt.AddChoice(regionName);
            }

            var region = AnsiConsole.Prompt(regionPrompt);

            var connection = new PrimarSqlConnection(new PrimarSqlConnectionStringBuilder
            {
                AccessKey           = apiKey,
                AccessSecretKey     = secret,
                CredentialsFilePath = credentialsFilePath,
                ProfileName         = profileName,
                AwsRegion           = Enum.Parse <AwsRegion>(region),
            });

            connection.Open();

            while (true)
            {
                try
                {
                    var query   = AnsiConsole.Prompt(new TextPrompt <string>("[blue]Query[/]"));
                    var command = connection.CreateDbCommand(query);
                    using var dbDataReader = command.ExecuteReader();

                    var table = new Table
                    {
                        Border = TableBorder.Rounded
                    };

                    for (int i = 0; i < dbDataReader.FieldCount; i++)
                    {
                        table.AddColumn($"[green]{Markup.Escape(dbDataReader.GetName(i))}[/]");
                    }

                    while (dbDataReader.Read())
                    {
                        var list = new List <string>();

                        for (int i = 0; i < dbDataReader.FieldCount; i++)
                        {
                            var value = dbDataReader[i];

                            list.Add(Markup.Escape(value switch
                            {
                                byte[] bArr => Convert.ToBase64String(bArr),
                                DateTime dt => dt.ToString("u"),
                                _ => value.ToString()
                            }));
                        }

                        table.AddRow(list.ToArray());
                    }
Beispiel #11
0
 public static void WriteLine(string message)
 {
     AnsiConsole.MarkupLine(Markup.Escape(message));
 }
Beispiel #12
0
        void LogInternal(LogLevel logLevel, string message, Exception exception, long?sessionId)
        {
            if (CanLog(logLevel))
            {
                string sessionText = string.Empty;
                if (sessionId.HasValue)
                {
                    sessionText = $"Session {sessionId} -";
                }

                AnsiConsole.MarkupLine($"[#005f00]{DateTime.Now:s}[/] {FormatLevel(logLevel)} [#005fd7]{sessionText} {Markup.Escape(sourceContext)}[/] {Markup.Escape(message)}");

                if (exception != null)
                {
                    AnsiConsole.WriteLine();
                    AnsiConsole.WriteException(exception);
                    AnsiConsole.WriteLine();
                }
            }
        }