public void Smoke_Test() { // Arrange using var stdin = new StringReader("hello world"); using var stdout = new StringWriter(); using var stderr = new StringWriter(); var console = new VirtualConsole(stdin, stdout, stderr); // Act console.ResetColor(); console.ForegroundColor = ConsoleColor.DarkMagenta; console.BackgroundColor = ConsoleColor.DarkMagenta; // Assert console.Input.Should().BeSameAs(stdin); console.Input.Should().NotBeSameAs(Console.In); console.IsInputRedirected.Should().BeTrue(); console.Output.Should().BeSameAs(stdout); console.Output.Should().NotBeSameAs(Console.Out); console.IsOutputRedirected.Should().BeTrue(); console.Error.Should().BeSameAs(stderr); console.Error.Should().NotBeSameAs(Console.Error); console.IsErrorRedirected.Should().BeTrue(); console.ForegroundColor.Should().NotBe(Console.ForegroundColor); console.BackgroundColor.Should().NotBe(Console.BackgroundColor); }
public void Fake_implementation_of_console_can_be_used_to_execute_commands_in_isolation() { // Arrange using MemoryStream stdIn = new(Console.InputEncoding.GetBytes("input")); using MemoryStream stdOut = new(); using MemoryStream stdErr = new(); using IConsole console = new VirtualConsole(input: stdIn, output: stdOut, error: stdErr); // Act console.Output.Write("output"); console.Error.Write("error"); var stdInData = console.Input.ReadToEnd(); var stdOutData = console.Output.Encoding.GetString(stdOut.ToArray()); var stdErrData = console.Error.Encoding.GetString(stdErr.ToArray()); console.Clear(); console.ResetColor(); console.ForegroundColor = ConsoleColor.DarkMagenta; console.BackgroundColor = ConsoleColor.DarkMagenta; console.CursorLeft = 42; console.CursorTop = 24; console.BufferHeight = 80; console.BufferWidth = 120; console.WindowWidth = 45; console.WindowHeight = 70; console.SetCursorPosition(24, 42); // Assert stdInData.Should().Be("input"); stdOutData.Should().Be("output"); stdErrData.Should().Be("error"); console.Input.Should().NotBeSameAs(Console.In); console.Output.Should().NotBeSameAs(Console.Out); console.Error.Should().NotBeSameAs(Console.Error); console.Input.IsRedirected.Should().BeTrue(); console.Output.IsRedirected.Should().BeTrue(); console.Error.IsRedirected.Should().BeTrue(); console.ForegroundColor.Should().NotBe(Console.ForegroundColor); console.BackgroundColor.Should().NotBe(Console.BackgroundColor); }
public void Fake_implementation_of_console_can_be_used_to_execute_commands_in_isolation() { // Arrange using var stdIn = new MemoryStream(Console.InputEncoding.GetBytes("input")); using var stdOut = new MemoryStream(); using var stdErr = new MemoryStream(); var console = new VirtualConsole( input: stdIn, output: stdOut, error: stdErr ); // Act console.Output.Write("output"); console.Error.Write("error"); var stdInData = console.Input.ReadToEnd(); var stdOutData = console.Output.Encoding.GetString(stdOut.ToArray()); var stdErrData = console.Error.Encoding.GetString(stdErr.ToArray()); console.ResetColor(); console.ForegroundColor = ConsoleColor.DarkMagenta; console.BackgroundColor = ConsoleColor.DarkMagenta; console.CursorLeft = 42; console.CursorTop = 24; // Assert stdInData.Should().Be("input"); stdOutData.Should().Be("output"); stdErrData.Should().Be("error"); console.Input.Should().NotBeSameAs(Console.In); console.Output.Should().NotBeSameAs(Console.Out); console.Error.Should().NotBeSameAs(Console.Error); console.IsInputRedirected.Should().BeTrue(); console.IsOutputRedirected.Should().BeTrue(); console.IsErrorRedirected.Should().BeTrue(); console.ForegroundColor.Should().NotBe(Console.ForegroundColor); console.BackgroundColor.Should().NotBe(Console.BackgroundColor); }