public void End_WithDisposedTimedScope_ShouldLogError() { FailOnErrors = false; Mock <ITimedScopeLogger> timedScopeLoggerMock = new Mock <ITimedScopeLogger>(); Mock <IReplayEventConfigurator> replyEventConfiguratorMock = new Mock <IReplayEventConfigurator>(); Mock <ICallContextManager> callContextManagerMock = new Mock <ICallContextManager>(); IMachineInformation machineInformation = new UnitTestMachineInformation(); ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(callContextManagerMock.Object, machineInformation); using (TimedScope scope = TestHooks.CreateDefaultTimedScope(timedScopeLoggerMock.Object, replyEventConfiguratorMock.Object, machineInformation, timedScopeStackManager)) { Assert.True(scope.IsScopeActive, "Timer should be active."); scope.Dispose(); Assert.False(scope.IsScopeActive, "Dispose should turn off timer."); scope.End(); Assert.Equal(TraceErrors.Count(), 1); LoggedEvents.Clear(); } }
public void AddLoggingValue_ShouldOutputValueInLogEvent() { Mock <ITimedScopeLogger> timedScopeLoggerMock = new Mock <ITimedScopeLogger>(); Mock <IReplayEventConfigurator> replyEventConfiguratorMock = new Mock <IReplayEventConfigurator>(); Mock <ICallContextManager> callContextManagerMock = new Mock <ICallContextManager>(); IMachineInformation machineInformation = new UnitTestMachineInformation(); ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(callContextManagerMock.Object, machineInformation); using (TimedScope scope = TestHooks.CreateTestCountersUnitTestTimedScope(machineInformation: machineInformation, scopeLogger: timedScopeLoggerMock.Object, replayEventConfigurator: replyEventConfiguratorMock.Object, timedScopeStackManager: timedScopeStackManager)) { scope.AddLoggingValue(TimedScopeDataKeys.Category, "MyCategory"); scope.End(); // There should be one 'Ending' transaction log call with formatted output foreach (LogEventArgs args in LoggedEvents) { if (args.CategoryId == Categories.TimingGeneral) { if (args.FullMessage.Contains("Ending timed scope")) { Assert.Contains("Category:'MyCategory';", args.FullMessage, StringComparison.Ordinal); } } } } }