コード例 #1
0
        private static LogMessageExpectations GenerateLogMessageExpectationsWithFormattedMessage()
        {
            Faker faker = new Faker();
            LogMessageExpectations props = new LogMessageExpectations();

            int placeholderCount = faker.Random.Int(0, 10);

            if (placeholderCount > 0)
            {
                string[] words = faker.Lorem.Random
                                 .WordsArray(placeholderCount + 1);

                props.ExpectedMessage =
                    GenerateLogMessageFormat(words);

                props.ExpectedMessageArgs = faker.Lorem.Random
                                            .WordsArray(placeholderCount);
            }
            else
            {
                props.ExpectedMessage     = faker.Lorem.Random.Words();
                props.ExpectedMessageArgs = LogMessageExpectations.NoMessageArgs;
            }

            return(props);
        }
コード例 #2
0
        private void RunErrorLogMessageTests(bool withException)
        {
            LogMessageExpectations logExceptionExpectations = GenerateLogExceptionExpectations(withException,
                                                                                               withFormattedMessage: false);

            TargetLoggerMockLoggerSetupProperties loggerSetupProps = TargetLoggerMockLoggerSetupProperties
                                                                     .ErrorEnabledWithExpectations(logExceptionExpectations);

            Mock <ILog> targetLoggerMock =
                CreateLog4NetLoggerMock(loggerSetupProps);

            Log4NetLogger stakhanoviseLogger =
                new Log4NetLogger(targetLoggerMock.Object);

            if (withException)
            {
                stakhanoviseLogger.Error(logExceptionExpectations.ExpectedMessage, logExceptionExpectations.ExpectedException);
            }
            else
            {
                stakhanoviseLogger.Error(logExceptionExpectations.ExpectedMessage);
            }

            targetLoggerMock.Verify();
        }
コード例 #3
0
        private void RunWarnLogMessageTestsWithoutException(bool withFormattedMessage)
        {
            LogMessageExpectations logWarnExpectations = GenerateLogExceptionExpectations(withException: false,
                                                                                          withFormattedMessage: withFormattedMessage);

            TargetLoggerMockLoggerSetupProperties loggerSetupProps = TargetLoggerMockLoggerSetupProperties
                                                                     .WarnEnabledWithExpectations(logWarnExpectations);

            Mock <ILog> targetLoggerMock =
                CreateLog4NetLoggerMock(loggerSetupProps);

            Log4NetLogger stakhanoviseLogger =
                new Log4NetLogger(targetLoggerMock.Object);

            if (withFormattedMessage)
            {
                stakhanoviseLogger.WarnFormat(logWarnExpectations.ExpectedMessage, logWarnExpectations.ExpectedMessageArgs);
            }
            else
            {
                stakhanoviseLogger.Warn(logWarnExpectations.ExpectedMessage);
            }

            targetLoggerMock.Verify();
        }
コード例 #4
0
        private void RunTraceLogMessageTests(bool withFormattedMessage)
        {
            LogMessageExpectations logMessageExpectations =
                GenerateLogMessageExpectations(withFormattedMessage);

            TargetLoggerMockLoggerSetupProperties targetLoggerSetupProps = TargetLoggerMockLoggerSetupProperties
                                                                           .TraceEnabledWithExpectations(logMessageExpectations);

            Mock <ILog> targetLoggerMock =
                CreateLog4NetLoggerMock(targetLoggerSetupProps);

            Log4NetLogger stakhanoviseLogger =
                new Log4NetLogger(targetLoggerMock.Object);

            if (withFormattedMessage)
            {
                stakhanoviseLogger.TraceFormat(logMessageExpectations.ExpectedMessage, logMessageExpectations.ExpectedMessageArgs);
            }
            else
            {
                stakhanoviseLogger.Trace(logMessageExpectations.ExpectedMessage);
            }

            targetLoggerMock.Verify();
        }
コード例 #5
0
        public static LogMessageExpectations GenerateWithException(bool formattedMessage)
        {
            Faker faker = new Faker();
            LogMessageExpectations props =
                GenerateWithMessageOnly(formattedMessage);

            props.ExpectedException = faker.System
                                      .Exception();

            return(props);
        }
コード例 #6
0
 public static TargetLoggerMockLoggerSetupProperties FatalEnabledWithExpectations(LogMessageExpectations expectations)
 {
     return(new TargetLoggerMockLoggerSetupProperties()
     {
         IsFatalEnabled = true,
         FatalMessageExpectations = expectations
     });
 }
コード例 #7
0
 private LogMessageExpectations GenerateLogMessageExpectations(bool formattedMessage)
 {
     return(LogMessageExpectations.GenerateWithMessageOnly(formattedMessage));
 }
コード例 #8
0
 private LogMessageExpectations GenerateLogExceptionExpectations(bool withException, bool withFormattedMessage)
 {
     return(withException
                         ? LogMessageExpectations.GenerateWithException(withFormattedMessage)
                         : LogMessageExpectations.GenerateWithMessageOnly(withFormattedMessage));
 }