public void TimerContext_Stop_StopsTiming() { TimerContext context = new TimerContext("some-name", new Logger(), LogLevelEnum.LOG_DEBUG); context.Start(); Thread.Sleep(5); context.Stop(); var firstTime = context.GetElapsedTime(); Thread.Sleep(5); var secondTime = context.GetElapsedTime(); Assert.True(firstTime > 0); Assert.True(secondTime == firstTime); }
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 }
public void TimerContext_Constructor_PopulatesProperties() { Logger logger = new Logger(); string name = "some-name"; LogLevelEnum level = LogLevelEnum.LOG_EXCEPT; TimerContext context = new TimerContext("some-name", logger, level); Assert.Equal(logger, context.Logger); Assert.Equal(name, context.TimerName); Assert.Equal(level, context.LogLevel); Assert.Null(context.TimerMessage); Assert.Equal(-1, context.GetElapsedTime()); // Indicates that the timer is not started }
public void TimerContext_Finish_DoesNothingIfTimerHasNotBeenStarted() { var writer = new StringWriter(); var logger = new Logger() { OutWriter = writer }; TimerContext context = new TimerContext("some-name", logger, LogLevelEnum.LOG_DEBUG); context.Finish(); writer.Flush(); Assert.Equal(-1, context.GetElapsedTime()); Assert.Equal(0, writer.GetStringBuilder().Length); }
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()); }