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); }
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(); }
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(); }
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(); }
public static LogMessageExpectations GenerateWithException(bool formattedMessage) { Faker faker = new Faker(); LogMessageExpectations props = GenerateWithMessageOnly(formattedMessage); props.ExpectedException = faker.System .Exception(); return(props); }
public static TargetLoggerMockLoggerSetupProperties FatalEnabledWithExpectations(LogMessageExpectations expectations) { return(new TargetLoggerMockLoggerSetupProperties() { IsFatalEnabled = true, FatalMessageExpectations = expectations }); }
private LogMessageExpectations GenerateLogMessageExpectations(bool formattedMessage) { return(LogMessageExpectations.GenerateWithMessageOnly(formattedMessage)); }
private LogMessageExpectations GenerateLogExceptionExpectations(bool withException, bool withFormattedMessage) { return(withException ? LogMessageExpectations.GenerateWithException(withFormattedMessage) : LogMessageExpectations.GenerateWithMessageOnly(withFormattedMessage)); }