public void Get_Detailed_Output_Without_Steps(string name, decimal budgetMs, decimal durationMs, string expected)
        {
            var result = new PerformanceBudgetResult(name, budgetMs, durationMs, null);
            string actual = result.GetDetailedOutput();

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 2
0
 static void LogResult(PerformanceBudgetResult result)
 {
     if(result.IsOver) {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine("Over Budget!");
         Console.ForegroundColor = ConsoleColor.White;
         Console.WriteLine(result.GetDetailedOutput());
     } else {
         Console.ForegroundColor = ConsoleColor.Green;
         Console.WriteLine("Under Budget!");
         Console.ForegroundColor = ConsoleColor.White;
         Console.WriteLine(result.GetDetailedOutput());
     }
 }
        public void Get_Detailed_Output_With_Duplicate_Steps()
        {
            string expected = "Budget was set to 2.000ms\r\nDuration was 1.000ms\r\nAction was under performance budget by 50.000% (1.000ms).\r\n  Step: duplicate occured 3 times and took 1.000ms on average. 1 did not finish.\r\n";

            var steps = new List<PerformanceStepResult>() {
                new PerformanceStepResult("duplicate", 1.0M),
                new PerformanceStepResult("duplicate", 1.0M),
                new PerformanceStepResult("duplicate", null),
            };

            var result = new PerformanceBudgetResult(null, 2.0M, 1.0M, null) { Steps = steps };

            string actual = result.GetDetailedOutput();

            Assert.Equal(expected, actual);
        }
        public void Calculates_Ms_Diff(decimal budgetMs, decimal durationMs)
        {
            bool isOver = budgetMs < durationMs;
            decimal msDiff = Math.Abs(durationMs - budgetMs);
            decimal diffPercentage = (msDiff / budgetMs) * 100;

            var result = new PerformanceBudgetResult("test", budgetMs, durationMs, null);

            Assert.Equal(isOver, result.IsOver);
            Assert.Equal(isOver, result.OverBudgetPercentage.HasValue);
            Assert.Equal(isOver, result.OverBudgetMilliseconds.HasValue);
            Assert.Equal(!isOver, result.UnderBudgetPercentage.HasValue);
            Assert.Equal(!isOver, result.UnderBudgetMilliseconds.HasValue);

            if (isOver) {
                Assert.Equal(diffPercentage, result.OverBudgetPercentage.Value);
                Assert.Equal(msDiff, result.OverBudgetMilliseconds.Value);
            } else {
                Assert.Equal(diffPercentage, result.UnderBudgetPercentage.Value);
                Assert.Equal(msDiff, result.UnderBudgetMilliseconds.Value);
            }
        }
 private static void AssertResult(bool hasMonitor, string stepName, PerformanceBudgetResult result) {
     if (hasMonitor) {
         Assert.NotNull(result);
         Assert.Equal(1, result.Steps.Count());
         Assert.Equal(stepName, result.Steps.Single().Name);
     } else {
         Assert.Null(result);
     }
 }
        public void Get_Detailed_Output_With_Steps()
        {
            string expected = "Budget was set to 2.000ms\r\nDuration was 1.000ms\r\nAction was under performance budget by 50.000% (1.000ms).\r\n  Step: one took 1.000ms\r\n";

            var steps = new List<PerformanceStepResult>() {
                new PerformanceStepResult("one", 1.0M)
            };

            var result = new PerformanceBudgetResult(null, 2.0M, 1.0M, null) { Steps = steps };

            string actual = result.GetDetailedOutput();

            Assert.Equal(expected, actual);
        }
 public void Steps_initialised()
 {
     var result = new PerformanceBudgetResult("test", 1.0M, 1.0M, null);
     Assert.NotNull(result.Steps);
     Assert.Empty(result.Steps);
 }
        public void Get_Result_Message(string name, decimal budgetMs, decimal durationMs, string expected)
        {
            var result = new PerformanceBudgetResult(name, budgetMs, durationMs, null);
            string actual = result.GetResultMessage();

            Assert.Equal(expected, actual);
        }