예제 #1
0
        public void TimerContext_Start_ContinuesTiming()
        {
            TimerContext context = new TimerContext("some-name", new Logger(), LogLevelEnum.LOG_DEBUG);

            context.Start();
            Thread.Sleep(5);
            context.Stop();
            var firstTime = context.GetElapsedTime();

            context.Start();
            Thread.Sleep(5);
            context.Stop();
            var secondTime = context.GetElapsedTime();

            Assert.True(firstTime > 0);
            Assert.True(secondTime > firstTime);
        }
예제 #2
0
        public void TimerContext_Start_RunsTimer()
        {
            TimerContext context = new TimerContext("some-name", new Logger(), LogLevelEnum.LOG_DEBUG);

            var result = context.Start();

            Thread.Sleep(5);

            Assert.Equal(context, result);
            Assert.True(context.GetElapsedTime() > 0);  // Indicates that the timer has been started
        }
예제 #3
0
        public void TimerContext_Finish_WritesMessageWithParenthesis()
        {
            var writer = new StringWriter();
            var logger = new Logger()
            {
                OutWriter = writer
            };
            TimerContext context = new TimerContext("some-name", logger, LogLevelEnum.LOG_INFO);

            context.Start();
            context.Message("msg1");  // Notice no colons at the end
            context.Finish();
            writer.Flush();

            var time            = context.GetElapsedTime();
            var expectedMessage = String.Format("[INFO]  msg1 ({0}ms)", time);

            Assert.Equal(expectedMessage, writer.GetStringBuilder().ToString().Substring(9).TrimEnd());
        }
예제 #4
0
 public void Start(long timeout, long repeat) =>
 _timerContext.Start(timeout, repeat);