예제 #1
0
        public void LogMessage_ReplayedMessageSavedUnitilTheLimit()
        {
            string    replayMessage1 = "ReplayMessage1";
            Exception exception1     = new ArgumentException("Error");
            string    replayMessage2 = "ReplayMessage2";
            Exception exception2     = new NullReferenceException("Error");

            string suffix  = nameof(LogMessage_ReplayedMessageSavedUnitilTheLimit);
            int    eventId = 7;
            Mock <ILogEventSender> eventSourceMock = CreateEventSourceMock(isReplayable: true);

            ReplayableActivity activity = CreateActivity(suffix);

            activity.Start();
            (ILogger logger, _) = LogMessage(eventSourceMock, eventId);
            logger.LogDebug(exception1, replayMessage1);
            logger.LogDebug(exception2, replayMessage2);
            activity.Stop();

            eventSourceMock.Verify(m_logExpression, Times.Exactly(3));
            List <LogMessageInformation> info = activity.GetLogEvents().ToList();

            Assert.AreEqual(2, info.Count);
            StringAssert.Contains(info[0].Message, replayMessage1);
            StringAssert.Contains(info[0].Message, exception1.ToString());
            StringAssert.Contains(info[1].Message, replayMessage2);
            StringAssert.Contains(info[1].Message, exception2.ToString());
        }
예제 #2
0
        public void LogMessage_UseIsReplayableMessageFlag()
        {
            string suffix = nameof(LogMessage_UseIsReplayableMessageFlag);
            Mock <ILogEventSender> eventSourceMock = CreateEventSourceMock(isReplayable: false);

            ReplayableActivity activity = CreateActivity(suffix);

            activity.Start();
            LogMessage(eventSourceMock);
            activity.Stop();

            eventSourceMock.Verify(m_logExpression, Times.Once);
            Assert.IsFalse(activity.GetLogEvents().Any(), "Log should not be stored for replay");
        }
예제 #3
0
        public void LogMessage_ReplayedMessageSaved()
        {
            string suffix  = nameof(LogMessage_ReplayedMessageSaved);
            int    eventId = 7;
            Mock <ILogEventSender> eventSourceMock = CreateEventSourceMock(isReplayable: true);

            ReplayableActivity activity = CreateActivity(suffix);

            activity.Start();
            LogMessage(eventSourceMock, eventId);
            activity.Stop();

            eventSourceMock.Verify(m_logExpression, Times.Once);
            LogMessageInformation info = activity.GetLogEvents().Single();

            Assert.AreEqual(GetLogCategory(suffix), info.Category);
            Assert.AreEqual(GetLogMessage(suffix), info.Message);
            Assert.AreEqual(CreateEventId(eventId, suffix), info.EventId);
        }
예제 #4
0
        public void LogMessage_ReplayedMessageSavedUnitilTheLimit()
        {
            string replayMessage1 = "ReplayMessage1";
            string replayMessage2 = "ReplayMessage2";

            string suffix  = nameof(LogMessage_ReplayedMessageSaved);
            int    eventId = 7;
            Mock <ILogEventSender> eventSourceMock = CreateEventSourceMock(isReplayable: true);

            ReplayableActivity activity = CreateActivity(suffix);

            activity.Start();
            (ILogger logger, _) = LogMessage(eventSourceMock, eventId);
            logger.LogDebug(replayMessage1);
            logger.LogDebug(replayMessage2);
            activity.Stop();

            eventSourceMock.Verify(m_logExpression, Times.Exactly(3));
            List <LogMessageInformation> info = activity.GetLogEvents().ToList();

            Assert.AreEqual(2, info.Count);
            Assert.AreEqual(replayMessage1, info[0].Message);
            Assert.AreEqual(replayMessage2, info[1].Message);
        }