Exemple #1
0
        private static Scope TimedLog(Action <string> doLog, string message, object[] args)
        {
            string formattedMessage = args == null || args.Length == 0 ? message : message.FormatInvariant(args);

            doLog("(Timed) " + formattedMessage);
            Stopwatch stopwatch = Stopwatch.StartNew();

            return(Scope.Create(
                       delegate
            {
                stopwatch.Stop();
                TimeSpan elapsed = stopwatch.Elapsed;
                doLog("({0}) {1}".FormatInvariant(TimeSpanUtility.FormatForLogging(elapsed.Ticks < 0 ? TimeSpan.Zero : elapsed), formattedMessage));
            }));
        }
 public void RoundUp()
 {
     Assert.AreEqual("1ms", TimeSpanUtility.FormatForLogging(TimeSpan.FromMilliseconds(0.5)));
 }
 public void NegativeTimeSpan()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => TimeSpanUtility.FormatForLogging(TimeSpan.FromMinutes(-1)));
 }
 public void FormatForLogging(int ms, string expected)
 {
     Assert.AreEqual(expected, TimeSpanUtility.FormatForLogging(TimeSpan.FromMilliseconds(ms)));
 }