コード例 #1
0
        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();
            }
        }
コード例 #2
0
		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");
		}
コード例 #3
0
        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);
        }
コード例 #4
0
        public void CorrelationStart_WithNullData_ShouldStartNewCorrelation()
        {
            Correlation = new Correlation(new MemoryCorrelationHandler(), CallContextManagerInstance, MachineInformation);
            Correlation.CorrelationStart(null);

            Assert.NotNull(Correlation.CurrentCorrelation);

            CallContextManagerInstance.CallContextOverride.EndCallContext();
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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();
            }
        }
コード例 #7
0
        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();
            }
        }
コード例 #8
0
        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();
            }
        }
コード例 #9
0
        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();
        }
コード例 #10
0
        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();
            }
        }
コード例 #11
0
        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();
            }
        }
コード例 #12
0
        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();
        }