public void CorrelationClear_ShouldClearAllCorrelations() { try { Correlation = new Correlation(new MemoryCorrelationHandler(), CallContextManagerInstance, MachineInformation); Correlation.CorrelationStart(null); CorrelationData previousCorrelation = Correlation.CurrentCorrelation; for (int i = 0; i < (new Random()).Next(3, 10); i++) { Correlation.CorrelationStart(null); CorrelationData parentCorrelation = Correlation.CurrentCorrelation.ParentCorrelation; Assert.Same(previousCorrelation, parentCorrelation); previousCorrelation = Correlation.CurrentCorrelation; } Assert.NotNull(Correlation.CurrentCorrelation); Correlation.CorrelationClear(); Assert.Null(Correlation.CurrentCorrelation); } finally { EndRequest(); } }
public void FailedTimedScope_ShouldReplayLogs() { Mock<ITimedScopeLogger> timedScopeLoggerMock = new Mock<ITimedScopeLogger>(); Mock<IReplayEventConfigurator> replyEventConfiguratorMock = new Mock<IReplayEventConfigurator>(); Mock<ILogEventCache> mockCache = new Mock<ILogEventCache>(); Correlation = new Correlation(new MemoryCorrelationHandler(), CallContextManagerInstance, MachineInformation); Correlation.CorrelationStart(new CorrelationData(mockCache.Object)); IMachineInformation machineInformation = new UnitTestMachineInformation(); ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(CallContextManagerInstance, machineInformation); CorrelationData currentCorrelation = Correlation.CurrentCorrelation; Assert.False(currentCorrelation.ShouldReplayUls, "Logs shouldn't be replayed"); using (TimedScope scope = TestHooks.CreateDefaultTimedScope( timedScopeLoggerMock.Object, replyEventConfiguratorMock.Object, machineInformation, timedScopeStackManager, startScope: true)) { scope.Result = TimedScopeResult.SystemError; Mock<IReplayEventDisabledTimedScopes> disabledScopes = new Mock<IReplayEventDisabledTimedScopes>(); disabledScopes.Setup(x => x.IsDisabled(scope.ScopeDefinition)).Returns(false); ReplayEventConfigurator configurator = new ReplayEventConfigurator(disabledScopes.Object, Correlation); configurator.ConfigureReplayEventsOnScopeEnd(scope); } Assert.True(currentCorrelation.ShouldReplayUls, "Logs should be replayed"); }
public void SuccessTimedScope_DoesntReplayLogs() { Mock <ITimedScopeLogger> timedScopeLoggerMock = new Mock <ITimedScopeLogger>(); Mock <IReplayEventConfigurator> replyEventConfiguratorMock = new Mock <IReplayEventConfigurator>(); Correlation = new Correlation(new MemoryCorrelationHandler(), CallContextManagerInstance, MachineInformation); Correlation.CorrelationStart(new CorrelationData()); IMachineInformation machineInformation = new UnitTestMachineInformation(); ITimedScopeStackManager timedScopeStackManager = new TimedScopeStackManager(CallContextManagerInstance, machineInformation); CorrelationData currentCorrelation = Correlation.CurrentCorrelation; Assert.False(currentCorrelation.ShouldReplayUls); using (TimedScope scope = TimedScope.Start(currentCorrelation, MachineInformation, "TestScope", customLogger: timedScopeLoggerMock.Object, replayEventConfigurator: replyEventConfiguratorMock.Object, timedScopeStackManager: timedScopeStackManager)) { scope.Result = TimedScopeResult.Success; Mock <IReplayEventDisabledTimedScopes> disabledScopes = new Mock <IReplayEventDisabledTimedScopes>(); disabledScopes.Setup(x => x.IsDisabled(scope.ScopeDefinition)).Returns(false); ReplayEventConfigurator configurator = new ReplayEventConfigurator(disabledScopes.Object, Correlation); configurator.ConfigureReplayEventsOnScopeEnd(scope); } Assert.False(currentCorrelation.ShouldReplayUls); }
public void CorrelationStart_WithNullData_ShouldStartNewCorrelation() { Correlation = new Correlation(new MemoryCorrelationHandler(), CallContextManagerInstance, MachineInformation); Correlation.CorrelationStart(null); Assert.NotNull(Correlation.CurrentCorrelation); CallContextManagerInstance.CallContextOverride.EndCallContext(); }
public void CurrentCorrelation_WithNoActiveCorrelation_ShouldReturnNull() { Correlation = new Correlation(new MemoryCorrelationHandler(), CallContextManagerInstance, MachineInformation); Correlation.CorrelationStart(new CorrelationData()); while (CallContextManagerInstance.CallContextHandler(MachineInformation).ExistingCallContext() != null) { CallContextManagerInstance.CallContextHandler(MachineInformation).EndCallContext(); } Assert.Null(Correlation.CurrentCorrelation); }
public void SettingShouldLogDirectly_OnBaseCorrelation_ShouldBeInheritedByCurrentCorrelation() { try { Correlation = new Correlation(new MemoryCorrelationHandler(), CallContextManagerInstance, MachineInformation); Assert.False(Correlation.ShouldLogDirectly, "ShouldLogDirectly should be set to false by default."); Correlation.CorrelationStart(null); Correlation.ShouldLogDirectly = true; Correlation.CorrelationStart(null); Assert.True(Correlation.ShouldLogDirectly, "ShouldLogDirectly should be set to true."); Correlation.CorrelationClear(); } finally { EndRequest(); } }
public void CorrelationData_Add_WithNullValue_ShouldThrowException() { try { FailOnErrors = false; Correlation = new Correlation(new MemoryCorrelationHandler(), CallContextManagerInstance, MachineInformation); Correlation.CorrelationStart(null); Assert.Throws <ArgumentNullException>(() => { Correlation.CorrelationAdd("key", null); }); } finally { EndRequest(); } }
public void CorrelationData_ToTransactionData_ShouldReturnSameData() { try { Correlation = new Correlation(new MemoryCorrelationHandler(), CallContextManagerInstance, MachineInformation); Correlation.CorrelationStart(null); CorrelationData data = Correlation.CurrentCorrelation; TransactionData transaction = data.ToTransactionData(); Assert.True(data.CallDepth == transaction.CallDepth, "Call depth properties should be equal."); Assert.True(data.EventSequenceNumber == transaction.EventSequenceNumber, "EventSequenceNumber properties should be equal."); Assert.True(data.TransactionId == transaction.TransactionId, "TransactionId properties should be equal."); Assert.True(data.UserHash == transaction.UserHash, "UserHash properties should be equal."); Assert.True(data.VisibleId == transaction.CorrelationId, "VisibleId and CorrelationId properties should be equal."); } finally { EndRequest(); } }
public void CorrelationStart_MultipleCorrelations_ShouldCreateAHierarchy() { Correlation = new Correlation(new MemoryCorrelationHandler(), CallContextManagerInstance, MachineInformation); for (int i = 0; i < 3; i++) { Correlation.CorrelationStart(null); CorrelationData currentCorrelation = Correlation.CurrentCorrelation; for (int j = i; j > 0; j--) { CorrelationData parentCorrelation = currentCorrelation.ParentCorrelation; Assert.NotNull(parentCorrelation); Assert.NotEqual(currentCorrelation.VisibleId, parentCorrelation.VisibleId); currentCorrelation = parentCorrelation; } Assert.Null(currentCorrelation.ParentCorrelation); } CallContextManagerInstance.CallContextOverride.EndCallContext(); }
public void SettingShouldLogDirectly_OnCurrentCorrelation_ShouldSetOnCorrelationOnly() { try { Correlation = new Correlation(new MemoryCorrelationHandler(), CallContextManagerInstance, MachineInformation); Assert.False(Correlation.ShouldLogDirectly, "ShouldLogDirectly should be set to false by default."); Correlation.CorrelationStart(null); Correlation.ShouldLogDirectly = true; Assert.True(Correlation.ShouldLogDirectly, "ShouldLogDirectly should be set to true."); Correlation.CorrelationEnd(); Assert.False(Correlation.ShouldLogDirectly, "ShouldLogDirectly should be set to false after correlation ended."); } finally { EndRequest(); } }
public void SettingShouldLogDirectly_WithoutAnActiveCorrelation_ShouldSetResetShouldLogDirectly() { try { Correlation = new Correlation(new MemoryCorrelationHandler(), CallContextManagerInstance, MachineInformation); Correlation.CorrelationStart(null); Assert.False(Correlation.ShouldLogDirectly, "ShouldLogDirectly should be set to false by default."); Correlation.ShouldLogDirectly = true; Assert.True(Correlation.ShouldLogDirectly, "ShouldLogDirectly should be set to true."); Correlation.ShouldLogDirectly = false; Assert.False(Correlation.ShouldLogDirectly, "ShouldLogDirectly should be reset to false."); } finally { EndRequest(); } }
public void CorrelationEnd_MultipleCorrelations_ShouldUnwindHierarchy() { Correlation = new Correlation(new MemoryCorrelationHandler(), CallContextManagerInstance, MachineInformation); Guid[] correlations = new Guid[3]; for (int i = 0; i < 3; i++) { Correlation.CorrelationStart(null); correlations[i] = Correlation.CurrentCorrelation.VisibleId; } for (int i = 2; i >= 0; i--) { CorrelationData currentCorrelation = Correlation.CurrentCorrelation; Assert.Equal(correlations[i], currentCorrelation.VisibleId); Correlation.CorrelationEnd(); } Assert.Null(Correlation.CurrentCorrelation); CallContextManagerInstance.CallContextOverride.EndCallContext(); }