Ejemplo n.º 1
0
 public void GetColorTest()
 {
     // act, assert
     Assert.True(QuantifyClientHelper.GetColor(nameof(ConsoleColor.Red)).Equals(ConsoleColor.Red));
     Assert.True(QuantifyClientHelper.GetColor(nameof(ConsoleColor.Black)).Equals(ConsoleColor.Black));
     Assert.True(QuantifyClientHelper.GetColor(nameof(ConsoleColor.DarkBlue)).Equals(ConsoleColor.DarkBlue));
     Assert.True(QuantifyClientHelper.GetColor(nameof(ConsoleColor.DarkGreen)).Equals(ConsoleColor.DarkGreen));
     Assert.True(QuantifyClientHelper.GetColor(nameof(ConsoleColor.DarkCyan)).Equals(ConsoleColor.DarkCyan));
     Assert.True(QuantifyClientHelper.GetColor(nameof(ConsoleColor.DarkRed)).Equals(ConsoleColor.DarkRed));
     Assert.True(QuantifyClientHelper.GetColor(nameof(ConsoleColor.DarkMagenta)).Equals(ConsoleColor.DarkMagenta));
     Assert.True(QuantifyClientHelper.GetColor(nameof(ConsoleColor.DarkYellow)).Equals(ConsoleColor.DarkYellow));
     Assert.True(QuantifyClientHelper.GetColor(nameof(ConsoleColor.Gray)).Equals(ConsoleColor.Gray));
     Assert.True(QuantifyClientHelper.GetColor(nameof(ConsoleColor.DarkGray)).Equals(ConsoleColor.DarkGray));
     Assert.True(QuantifyClientHelper.GetColor(nameof(ConsoleColor.Blue)).Equals(ConsoleColor.Blue));
     Assert.True(QuantifyClientHelper.GetColor(nameof(ConsoleColor.Green)).Equals(ConsoleColor.Green));
     Assert.True(QuantifyClientHelper.GetColor(nameof(ConsoleColor.Cyan)).Equals(ConsoleColor.Cyan));
     Assert.True(QuantifyClientHelper.GetColor(nameof(ConsoleColor.Magenta)).Equals(ConsoleColor.Magenta));
     Assert.True(QuantifyClientHelper.GetColor(nameof(ConsoleColor.Yellow)).Equals(ConsoleColor.Yellow));
     Assert.True(QuantifyClientHelper.GetColor(nameof(ConsoleColor.White)).Equals(ConsoleColor.White));
 }
Ejemplo n.º 2
0
        private static void PrintResult(
            QuantifierResult quantifierResult,
            ClientOutputType clientOutputType)
        {
            Console.ForegroundColor = QuantifyClientHelper.GetColor(quantifierResult.Color);

            switch (clientOutputType)
            {
            case ClientOutputType.None:
            {
                Console.WriteLine(quantifierResult.ToConsoleOutput().Result);
                break;
            }

            case ClientOutputType.Detailed:
            {
                Console.WriteLine(JsonSerializer.Serialize(
                                      quantifierResult,
                                      new JsonSerializerOptions {
                        WriteIndented = true
                    }));
                break;
            }

            case ClientOutputType.SummaryByFile:
            {
                Console.WriteLine(JsonSerializer.Serialize(
                                      new
                    {
                        quantifierResult.Label,
                        quantifierResult.QuantifiedLinesAdded,
                        quantifierResult.QuantifiedLinesDeleted,
                        Formula = quantifierResult.Formula.ToString(),
                        quantifierResult.PercentileAddition,
                        quantifierResult.PercentileDeletion,
                        Details = quantifierResult.QuantifierInput.Changes.Select(s =>
                                                                                  new
                        {
                            s.FilePath,
                            s.QuantifiedLinesAdded,
                            s.QuantifiedLinesDeleted,
                            s.DiscardFromCounting
                        })
                    },
                                      new JsonSerializerOptions {
                        WriteIndented = true
                    }));
                break;
            }

            case ClientOutputType.SummaryByExt:
            {
                Console.WriteLine(JsonSerializer.Serialize(
                                      new
                    {
                        quantifierResult.Label,
                        quantifierResult.QuantifiedLinesAdded,
                        quantifierResult.QuantifiedLinesDeleted,
                        Formula = quantifierResult.Formula.ToString(),
                        quantifierResult.PercentileAddition,
                        quantifierResult.PercentileDeletion,
                        Details = quantifierResult.QuantifierInput.Changes.GroupBy(c => c.FileExtension).Select(g =>
                                                                                                                new
                        {
                            FileExtension          = g.Key,
                            QuantifiedLinesAdded   = g.Sum(v => v.QuantifiedLinesAdded),
                            QuantifiedLinesDeleted = g.Sum(v => v.QuantifiedLinesDeleted)
                        })
                    },
                                      new JsonSerializerOptions {
                        WriteIndented = true
                    }));
                break;
            }

            default:
                throw new ArgumentOutOfRangeException(nameof(clientOutputType), clientOutputType, null);
            }

            Console.ResetColor();
        }