ConsoleDriverTests.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using Terminal.Gui;
  3. using Xunit;
  4. // Alais Console to MockConsole so we don't accidentally use Console
  5. using Console = Terminal.Gui.FakeConsole;
  6. namespace Terminal.Gui {
  7. public class ConsoleDriverTests {
  8. [Fact]
  9. public void Init_Inits ()
  10. {
  11. var driver = new FakeDriver ();
  12. Application.Init (driver, new NetMainLoop (() => FakeConsole.ReadKey (true)));
  13. driver.Init (() => { });
  14. Assert.Equal (80, Console.BufferWidth);
  15. Assert.Equal (25, Console.BufferHeight);
  16. // MockDriver is always 80x25
  17. Assert.Equal (Console.BufferWidth, driver.Cols);
  18. Assert.Equal (Console.BufferHeight, driver.Rows);
  19. driver.End ();
  20. }
  21. [Fact]
  22. public void End_Cleans_Up ()
  23. {
  24. var driver = new FakeDriver ();
  25. Application.Init (driver, new NetMainLoop (() => FakeConsole.ReadKey (true)));
  26. driver.Init (() => { });
  27. FakeConsole.ForegroundColor = ConsoleColor.Red;
  28. Assert.Equal (ConsoleColor.Red, Console.ForegroundColor);
  29. FakeConsole.BackgroundColor = ConsoleColor.Green;
  30. Assert.Equal (ConsoleColor.Green, Console.BackgroundColor);
  31. driver.Move (2, 3);
  32. Assert.Equal (2, Console.CursorLeft);
  33. Assert.Equal (3, Console.CursorTop);
  34. driver.End ();
  35. Assert.Equal (0, Console.CursorLeft);
  36. Assert.Equal (0, Console.CursorTop);
  37. Assert.Equal (ConsoleColor.Gray, Console.ForegroundColor);
  38. Assert.Equal (ConsoleColor.Black, Console.BackgroundColor);
  39. }
  40. [Fact]
  41. public void SetColors_Changes_Colors ()
  42. {
  43. var driver = new FakeDriver ();
  44. Application.Init (driver, new NetMainLoop (() => FakeConsole.ReadKey (true)));
  45. driver.Init (() => { });
  46. Assert.Equal (ConsoleColor.Gray, Console.ForegroundColor);
  47. Assert.Equal (ConsoleColor.Black, Console.BackgroundColor);
  48. Console.ForegroundColor = ConsoleColor.Red;
  49. Assert.Equal (ConsoleColor.Red, Console.ForegroundColor);
  50. Console.BackgroundColor = ConsoleColor.Green;
  51. Assert.Equal (ConsoleColor.Green, Console.BackgroundColor);
  52. Console.ResetColor ();
  53. Assert.Equal (ConsoleColor.Gray, Console.ForegroundColor);
  54. Assert.Equal (ConsoleColor.Black, Console.BackgroundColor);
  55. driver.End ();
  56. }
  57. }
  58. }