internal void TimeIt_Should_Throw_Exception_If_Log_Template_Is_Invalid() { var timer = ConfigureMockTimer(0); var timeit = new MockTimeIt(timer); var args = new object[] { "Too", "Few", "Args" }; var template = "{And} {Too} {Many} {Placeholders} {Elapsed}"; Should.Throw <FormatException>(() => timeit.Then.Log(_logger, template, args).Dispose()); }
internal void TimeIt_Should_Be_Configurable_To_Throw_On_Timeout(int elapsed, int timeout, bool shouldThrow) { var timer = ConfigureMockTimer(elapsed); var timeit = new MockTimeIt(timer); if (shouldThrow) { Should.Throw <TimeoutException>(() => timeit.Then.ThrowIfLongerThan(timeout).Dispose()); } else { Should.NotThrow(() => timeit.Then.ThrowIfLongerThan(timeout).Dispose()); } }
internal void TimeIt_Should_Be_Configurable_To_Log_Elapsed_Time( int elapsedTime, LogLevel logLevel, string template, object[] args, string expectedLogPattern) { var timer = ConfigureMockTimer(elapsedTime); var timeit = new MockTimeIt(timer); string log = null; _logger.GeneratedLog += (s, e) => log = e.Log; timeit.Then.Log(_logger, logLevel, template, args).Dispose(); log.ShouldMatch(expectedLogPattern); }
internal void TimeIt_Should_Be_Configurable_To_Do_Nothing() { var timeit = new MockTimeIt(Mock.Of <IRestartableTimer>()); Should.NotThrow(() => timeit.Then.DoNothing()); }