Exemple #1
0
        public void DebugAndInfoMessagesHandledOnlyByConsoleLogger()
        {
            var message1 = Guid.NewGuid().ToString();
            var message2 = Guid.NewGuid().ToString();

            var consoleWriter = new Mock <IConsole>();
            var emailWriter   = new Mock <IEmail>();
            var fileWriter    = new Mock <IFileWriter>();

            var logger = new ConsoleLoggerChainOfResponsibility(LogLevel.All, consoleWriter.Object)
                         .AddNext(
                new EmailLoggerChainOfResponsibility(
                    LogLevel.FunctionalMessage | LogLevel.FunctionalError,
                    emailWriter.Object))
                         .AddNext(
                new FileLoggerChainOfResponsibility(LogLevel.Warning | LogLevel.Error, fileWriter.Object));

            logger.LogMessage(LogLevel.Debug, message1);
            logger.LogMessage(LogLevel.Info, message2);

            // Assert
            consoleWriter.Verify(m => m.WriteMessage(message1), Times.Once);
            consoleWriter.Verify(m => m.WriteMessage(message2), Times.Once);

            emailWriter.Verify(m => m.SendEmail(It.IsAny <string>()), Times.Never);
            fileWriter.Verify(m => m.AppendToLogFile(It.IsAny <string>()), Times.Never);
        }
Exemple #2
0
        public void MessagesHandledBySingleConsoleLogger(LogLevel logLevel)
        {
            var message1      = Guid.NewGuid().ToString();
            var consoleWriter = new Mock <IConsole>();
            var logger        = new ConsoleLoggerChainOfResponsibility(logLevel, consoleWriter.Object);

            logger.LogMessage(logLevel, message1);

            // Assert
            consoleWriter.Verify(m => m.WriteMessage(message1), Times.Once);
        }