RulerTests.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using Microsoft.VisualStudio.TestPlatform.Utilities;
  2. using UnitTests;
  3. using UnitTests.Parallelizable;
  4. using Xunit.Abstractions;
  5. namespace UnitTests_Parallelizable.DrawingTests;
  6. /// <summary>
  7. /// Pure unit tests for <see cref="Ruler"/> that don't require Application.Driver or View context.
  8. /// These tests focus on properties and behavior that don't depend on rendering.
  9. ///
  10. /// Note: Tests that verify rendered output (Draw methods) require Application.Driver and remain in UnitTests as integration tests.
  11. /// </summary>
  12. public class RulerTests (ITestOutputHelper output): ParallelizableBase
  13. {
  14. [Fact]
  15. public void Constructor_Defaults ()
  16. {
  17. var r = new Ruler ();
  18. Assert.Equal (0, r.Length);
  19. Assert.Equal (Orientation.Horizontal, r.Orientation);
  20. }
  21. [Fact]
  22. public void Attribute_Set ()
  23. {
  24. var newAttribute = new Attribute (Color.Red, Color.Green);
  25. var r = new Ruler ();
  26. r.Attribute = newAttribute;
  27. Assert.Equal (newAttribute, r.Attribute);
  28. }
  29. [Fact]
  30. public void Length_Set ()
  31. {
  32. var r = new Ruler ();
  33. Assert.Equal (0, r.Length);
  34. r.Length = 42;
  35. Assert.Equal (42, r.Length);
  36. }
  37. [Fact]
  38. public void Orientation_Set ()
  39. {
  40. var r = new Ruler ();
  41. Assert.Equal (Orientation.Horizontal, r.Orientation);
  42. r.Orientation = Orientation.Vertical;
  43. Assert.Equal (Orientation.Vertical, r.Orientation);
  44. }
  45. [Fact]
  46. public void Draw_Default ()
  47. {
  48. IConsoleDriver driver = CreateFakeDriver ();
  49. var r = new Ruler ();
  50. r.Draw (Point.Empty, driver: driver);
  51. DriverAssert.AssertDriverContentsWithFrameAre (@"", output, driver);
  52. }
  53. [Fact]
  54. public void Draw_Horizontal ()
  55. {
  56. IConsoleDriver driver = CreateFakeDriver ();
  57. var len = 15;
  58. var r = new Ruler ();
  59. Assert.Equal (Orientation.Horizontal, r.Orientation);
  60. r.Length = len;
  61. r.Draw (Point.Empty, driver: driver);
  62. DriverAssert.AssertDriverContentsWithFrameAre (
  63. @"
  64. |123456789|1234",
  65. output,
  66. driver
  67. );
  68. // Postive offset
  69. r.Draw (new (1, 1), driver: driver);
  70. DriverAssert.AssertDriverContentsAre (
  71. @"
  72. |123456789|1234
  73. |123456789|1234
  74. ",
  75. output,
  76. driver
  77. );
  78. // Negative offset
  79. r.Draw (new (-1, 3), driver: driver);
  80. DriverAssert.AssertDriverContentsAre (
  81. @"
  82. |123456789|1234
  83. |123456789|1234
  84. 123456789|1234
  85. ",
  86. output,
  87. driver
  88. );
  89. }
  90. [Fact]
  91. public void Draw_Vertical ()
  92. {
  93. IConsoleDriver driver = CreateFakeDriver ();
  94. var len = 15;
  95. var r = new Ruler ();
  96. r.Orientation = Orientation.Vertical;
  97. r.Length = len;
  98. r.Draw (Point.Empty, driver: driver);
  99. DriverAssert.AssertDriverContentsWithFrameAre (
  100. @"
  101. -
  102. 1
  103. 2
  104. 3
  105. 4
  106. 5
  107. 6
  108. 7
  109. 8
  110. 9
  111. -
  112. 1
  113. 2
  114. 3
  115. 4",
  116. output,
  117. driver
  118. );
  119. r.Draw (new (1, 1), driver: driver);
  120. DriverAssert.AssertDriverContentsWithFrameAre (
  121. @"
  122. -
  123. 1-
  124. 21
  125. 32
  126. 43
  127. 54
  128. 65
  129. 76
  130. 87
  131. 98
  132. -9
  133. 1-
  134. 21
  135. 32
  136. 43
  137. 4",
  138. output,
  139. driver
  140. );
  141. // Negative offset
  142. r.Draw (new (2, -1), driver: driver);
  143. DriverAssert.AssertDriverContentsWithFrameAre (
  144. @"
  145. - 1
  146. 1-2
  147. 213
  148. 324
  149. 435
  150. 546
  151. 657
  152. 768
  153. 879
  154. 98-
  155. -91
  156. 1-2
  157. 213
  158. 324
  159. 43
  160. 4 ",
  161. output,
  162. driver
  163. );
  164. }
  165. }