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");
		}
示例#2
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);
        }
示例#3
0
        /// <summary>
        /// Logs the scope end to ULS
        /// </summary>
        private void LogEnd(IMachineInformation machineInformation)
        {
            if (!IsSuccessful.HasValue)
            {
                ULSLogging.LogTraceTag(0x238174e3 /* tag_96xt9 */, Categories.TimingGeneral, Levels.Warning,
                                       "Result not set for scope {0}. Considered as SystemError", Name);

                Result             = TimedScopeResult.SystemError;
                FailureDescription = InternalFailureDescription.UnknownResultAsSystemError;
            }

            CorrelationData scopeData = ConstructCorrelationDataEntries(machineInformation);

            ScopeLogger.LogScopeEnd(this, scopeData);

            ReplayEventConfigurator.ConfigureReplayEventsOnScopeEnd(this);
        }