2
0

RulerTests.cs 4.4 KB

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