public void DefaultTimedScopeResult_LogsAsSystemError() { LoggedEvents.Clear(); CorrelationData data = new CorrelationData(); UnitTestTimedScopeLogger unitTestTimedScopeLogger = new UnitTestTimedScopeLogger(); 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.Create(data, machineInformation, TestHooks.DefaultTimedScopeName, "description", unitTestTimedScopeLogger, replyEventConfiguratorMock.Object, timedScopeStackManager, default(TimedScopeResult))) { } TimedScopeLogEvent evt = unitTestTimedScopeLogger.SingleTimedScopeEvent(TestHooks.DefaultTimedScopeName); if (VerifyNotNullAndReturn(evt, "A scope event has been logged")) { Assert.Equal(TimedScopeResult.SystemError, evt.Result); } }
public void FailedScope_ResultAndFailureDescription_ShouldOutputValueInLogEvent() { FailOnErrors = false; UnitTestTimedScopeLogger unitTestTimedScopeLogger = new UnitTestTimedScopeLogger(); 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: unitTestTimedScopeLogger, replayEventConfigurator: replyEventConfiguratorMock.Object, timedScopeStackManager: timedScopeStackManager)) { scope.Result = TimedScopeResult.ExpectedError; scope.FailureDescription = UnitTestFailureDescription.ExampleDescription; } TimedScopeLogEvent scopeEvent = unitTestTimedScopeLogger.Events.SingleOrDefault(); if (VerifyNotNullAndReturn(scopeEvent, "Scope end event should be logged")) { Assert.Equal(scopeEvent.Result, TimedScopeResult.ExpectedError); Assert.Equal(scopeEvent.FailureDescription, UnitTestFailureDescription.ExampleDescription.ToString()); } }
public void NotSettingTimedScopeResult_ChangesToSystemError() { LoggedEvents.Clear(); UnitTestTimedScopeLogger unitTestTimedScopeLogger = new UnitTestTimedScopeLogger(); 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(unitTestTimedScopeLogger, replyEventConfiguratorMock.Object, machineInformation, timedScopeStackManager)) { } TimedScopeLogEvent evt = unitTestTimedScopeLogger.SingleTimedScopeEvent(TestHooks.DefaultTimedScopeName); if (VerifyNotNullAndReturn(evt, "A scope event has been logged")) { Assert.Equal(evt.Result, TimedScopeResult.SystemError); } }
public void SucceededScope_Result_ShouldOutputValueInLogEvent() { UnitTestTimedScopeLogger unitTestTimedScopeLogger = new UnitTestTimedScopeLogger(); 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: unitTestTimedScopeLogger, replayEventConfigurator: replyEventConfiguratorMock.Object, timedScopeStackManager: timedScopeStackManager)) { scope.Result = TimedScopeResult.Success; } TimedScopeLogEvent scopeEvent = unitTestTimedScopeLogger.Events.SingleOrDefault(); if (VerifyNotNullAndReturn(scopeEvent, "Timed scope should be logged")) { Assert.Equal(scopeEvent.Result, TimedScopeResult.Success); } }