コード例 #1
0
        public void NotCallingFlush_DoesNotWriteData_ToSystemConsole()
        {
            // Arrange
            var systemConsole = new TestAnsiSystemConsole();
            var console = new AnsiLogConsole(systemConsole);
            var message = "Request received";
            var expectedMessage = message + Environment.NewLine;

            // Act
            console.WriteLine(message, background: null, foreground: null);

            // Assert
            Assert.Null(systemConsole.Message);
        }
コード例 #2
0
        public void WritesMessage_WithoutEscapeCodes_AndNoForegroundOrBackgroundColorsSpecified()
        {
            // Arrange
            var systemConsole = new TestAnsiSystemConsole();
            var console = new AnsiLogConsole(systemConsole);
            var message = "Request received";
            var expectedMessage = message + Environment.NewLine;

            // Act
            console.WriteLine(message, background: null, foreground: null);
            console.Flush();

            // Assert
            Assert.Equal(expectedMessage, systemConsole.Message);
        }
コード例 #3
0
        public void DoesNotAddNewLine()
        {
            // Arrange
            var systemConsole = new TestAnsiSystemConsole();
            var console = new AnsiLogConsole(systemConsole);
            var message = "Request received";
            var expectedMessage = message;

            // Act
            console.Write(message, background: null, foreground: null);
            console.Flush();

            // Assert
            Assert.Equal(expectedMessage, systemConsole.Message);
        }
コード例 #4
0
        public void WritesMessage_WithForegroundEscapeCode_AndNoBackgroundColorSpecified()
        {
            // Arrange
            var systemConsole = new TestAnsiSystemConsole();
            var console = new AnsiLogConsole(systemConsole);
            var message = "Request received";
            var expectedMessage = GetForegroundColorEscapeCode(ConsoleColor.DarkGreen)
                + message
                + "\x1B[39m"; //resets foreground color

            // Act
            console.WriteLine(message, background: null, foreground: ConsoleColor.DarkGreen);
            console.Flush();

            // Assert
            Assert.Equal(expectedMessage + Environment.NewLine, systemConsole.Message);
        }
コード例 #5
0
        public void CallingFlush_ClearsData_FromOutputBuilder()
        {
            // Arrange
            var systemConsole = new TestAnsiSystemConsole();
            var console = new AnsiLogConsole(systemConsole);
            var message = "Request received";
            var expectedMessage = message + Environment.NewLine;

            // Act
            console.WriteLine(message, background: null, foreground: null);
            console.Flush();
            console.WriteLine(message, background: null, foreground: null);
            console.Flush();

            // Assert
            Assert.Equal(expectedMessage, systemConsole.Message);
        }
コード例 #6
0
ファイル: ConsoleLogger.cs プロジェクト: ravindrapro/Logging
        public ConsoleLogger(string name, Func<string, LogLevel, bool> filter, bool includeScopes)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            
            Name = name;
            Filter = filter ?? ((category, logLevel) => true);
            IncludeScopes = includeScopes;

            if (RuntimeEnvironmentHelper.IsWindows)
            {
                Console = new WindowsLogConsole();
            }
            else
            {
                Console = new AnsiLogConsole(new AnsiSystemConsole());
            }
        }
コード例 #7
0
        public void WriteMessage_InOrder_WhenBothForegroundOrBackgroundColorsSpecified()
        {
            // Arrange
            var systemConsole = new TestAnsiSystemConsole();
            var console = new AnsiLogConsole(systemConsole);
            var message = "Request received";
            var expectedMessage = GetBackgroundColorEscapeCode(ConsoleColor.Red)
                + GetForegroundColorEscapeCode(ConsoleColor.DarkGreen)
                + "Request received"
                + "\x1B[39m" //resets foreground color
                + "\x1B[0m" //resets background color
                + Environment.NewLine;

            // Act
            console.WriteLine(message, background: ConsoleColor.Red, foreground: ConsoleColor.DarkGreen);
            console.Flush();

            // Assert
            Assert.Equal(expectedMessage, systemConsole.Message);
        }