Exemplo n.º 1
0
        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 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");
		}
Exemplo n.º 3
0
        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.CreateDefaultTimedScope(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());
            }
        }
Exemplo n.º 4
0
        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.CreateDefaultTimedScope(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);
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        public void AbortTimer_ShouldDisableTimerActive()
        {
            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: machineInformation,
                                                                        timedScopeStackManager: timedScopeStackManager))
            {
                Assert.True(scope.IsScopeActive, "Default scope should have timer active.");

                scope.AbortTimer();
                Assert.False(scope.IsScopeActive, "Aborting timer should stop timer.");
            }
        }
Exemplo n.º 6
0
        public void AddLoggingValue_WithNullKey_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))
            {
                scope.AddLoggingValue(null, "My Application.");

                Assert.Equal(TraceErrors.Count(), 1);
                LoggedEvents.Clear();
            }
        }
Exemplo n.º 7
0
        public void Start_DisposedTimedScope_ShoudLogError()
        {
            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);

            TimedScope scope = TestHooks.CreateDefaultTimedScope(timedScopeLoggerMock.Object, replyEventConfiguratorMock.Object, machineInformation, timedScopeStackManager);

            scope.Dispose();

            scope.Start();

            Assert.Equal(TraceErrors.Count(), 1);
            LoggedEvents.Clear();
        }
Exemplo n.º 8
0
        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);
            }
        }
Exemplo n.º 9
0
        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.CreateDefaultTimedScope(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);
            }
        }
Exemplo n.º 10
0
        public void Create_ShouldConstructTimedScope_WithTimerInactive()
        {
            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,
                       true,
                       false))
            {
                Assert.False(scope.IsScopeActive, "Creating a scope should not start the timer.");

                Assert.True(scope.IsSuccessful.HasValue, "IsSuccessful should be set.");
                Assert.True(scope.IsSuccessful.Value, "IsSuccessful should be set to true.");
            }
        }
Exemplo n.º 11
0
        public void AbortTimer_ShouldDisableTimerActive_AndSetResultsToFalse()
        {
            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(scopeLogger: timedScopeLoggerMock.Object, replayEventConfigurator: replyEventConfiguratorMock.Object,
                                                                        machineInformation: machineInformation, timedScopeStackManager: timedScopeStackManager, startScope: false))
            {
                Assert.False(scope.IsScopeActive, "Default scope started without an active scope should have timer active.");

                scope.Start();

                Assert.True(scope.IsScopeActive, "Default scope should have timer active.");

                scope.AbortTimer(false);
                Assert.False(scope.IsScopeActive, "Aborting timer should stop timer.");
                Assert.True(scope.IsSuccessful.HasValue, "IsSuccessful should be set.");
                Assert.False(scope.IsSuccessful.Value, "IsSuccesful should be set to false.");
            }
        }