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); }
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); }
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); }
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); }
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); }
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()); } }
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); }