ScrollBarViewTests.cs 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using Xunit;
  5. using Xunit.Abstractions;
  6. namespace Terminal.Gui.ViewsTests;
  7. public class ScrollBarViewTests {
  8. static HostView _hostView;
  9. readonly ITestOutputHelper output;
  10. bool _added;
  11. ScrollBarView _scrollBar;
  12. public ScrollBarViewTests (ITestOutputHelper output) => this.output = output;
  13. [Fact]
  14. [AutoInitShutdown]
  15. public void Horizontal_Default_Draws_Correctly ()
  16. {
  17. var width = 40;
  18. var height = 3;
  19. var super = new Window { Id = "super", Width = Dim.Fill (), Height = Dim.Fill () };
  20. Application.Top.Add (super);
  21. var sbv = new ScrollBarView {
  22. Id = "sbv",
  23. Size = width * 2,
  24. // BUGBUG: ScrollBarView should work if Host is null
  25. Host = super,
  26. ShowScrollIndicator = true
  27. };
  28. super.Add (sbv);
  29. Application.Begin (Application.Top);
  30. ((FakeDriver)Application.Driver).SetBufferSize (width, height);
  31. var expected = @"
  32. ┌──────────────────────────────────────┐
  33. │◄├────────────────┤░░░░░░░░░░░░░░░░░░►│
  34. └──────────────────────────────────────┘";
  35. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  36. }
  37. [Fact]
  38. [AutoInitShutdown]
  39. public void Vertical_Default_Draws_Correctly ()
  40. {
  41. var width = 3;
  42. var height = 40;
  43. var super = new Window { Id = "super", Width = Dim.Fill (), Height = Dim.Fill () };
  44. Application.Top.Add (super);
  45. var sbv = new ScrollBarView {
  46. Id = "sbv",
  47. Size = height * 2,
  48. // BUGBUG: ScrollBarView should work if Host is null
  49. Host = super,
  50. ShowScrollIndicator = true,
  51. IsVertical = true
  52. };
  53. super.Add (sbv);
  54. Application.Begin (Application.Top);
  55. ((FakeDriver)Application.Driver).SetBufferSize (width, height);
  56. var expected = @"
  57. ┌─┐
  58. │▲│
  59. │┬│
  60. │││
  61. │││
  62. │││
  63. │││
  64. │││
  65. │││
  66. │││
  67. │││
  68. │││
  69. │││
  70. │││
  71. │││
  72. │││
  73. │││
  74. │││
  75. │││
  76. │┴│
  77. │░│
  78. │░│
  79. │░│
  80. │░│
  81. │░│
  82. │░│
  83. │░│
  84. │░│
  85. │░│
  86. │░│
  87. │░│
  88. │░│
  89. │░│
  90. │░│
  91. │░│
  92. │░│
  93. │░│
  94. │░│
  95. │▼│
  96. └─┘";
  97. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  98. }
  99. [Fact]
  100. [AutoInitShutdown]
  101. public void Both_Default_Draws_Correctly ()
  102. {
  103. var width = 3;
  104. var height = 40;
  105. var super = new Window { Id = "super", Width = Dim.Fill (), Height = Dim.Fill () };
  106. Application.Top.Add (super);
  107. var horiz = new ScrollBarView {
  108. Id = "horiz",
  109. Size = width * 2,
  110. // BUGBUG: ScrollBarView should work if Host is null
  111. Host = super,
  112. ShowScrollIndicator = true,
  113. IsVertical = true
  114. };
  115. super.Add (horiz);
  116. var vert = new ScrollBarView {
  117. Id = "vert",
  118. Size = height * 2,
  119. // BUGBUG: ScrollBarView should work if Host is null
  120. Host = super,
  121. ShowScrollIndicator = true,
  122. IsVertical = true
  123. };
  124. super.Add (vert);
  125. Application.Begin (Application.Top);
  126. ((FakeDriver)Application.Driver).SetBufferSize (width, height);
  127. var expected = @"
  128. ┌─┐
  129. │▲│
  130. │┬│
  131. │││
  132. │││
  133. │││
  134. │││
  135. │││
  136. │││
  137. │││
  138. │││
  139. │││
  140. │││
  141. │││
  142. │││
  143. │││
  144. │││
  145. │││
  146. │││
  147. │┴│
  148. │░│
  149. │░│
  150. │░│
  151. │░│
  152. │░│
  153. │░│
  154. │░│
  155. │░│
  156. │░│
  157. │░│
  158. │░│
  159. │░│
  160. │░│
  161. │░│
  162. │░│
  163. │░│
  164. │░│
  165. │░│
  166. │▼│
  167. └─┘";
  168. _ = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  169. }
  170. void AddHandlers ()
  171. {
  172. if (!_added) {
  173. _hostView.DrawContent += _hostView_DrawContent;
  174. _scrollBar.ChangedPosition += _scrollBar_ChangedPosition;
  175. _scrollBar.OtherScrollBarView.ChangedPosition += _scrollBar_OtherScrollBarView_ChangedPosition;
  176. }
  177. _added = true;
  178. }
  179. void RemoveHandlers ()
  180. {
  181. if (_added) {
  182. _hostView.DrawContent -= _hostView_DrawContent;
  183. _scrollBar.ChangedPosition -= _scrollBar_ChangedPosition;
  184. _scrollBar.OtherScrollBarView.ChangedPosition -= _scrollBar_OtherScrollBarView_ChangedPosition;
  185. }
  186. _added = false;
  187. }
  188. void _hostView_DrawContent (object sender, DrawEventArgs e)
  189. {
  190. _scrollBar.Size = _hostView.Lines;
  191. _scrollBar.Position = _hostView.Top;
  192. _scrollBar.OtherScrollBarView.Size = _hostView.Cols;
  193. _scrollBar.OtherScrollBarView.Position = _hostView.Left;
  194. _scrollBar.Refresh ();
  195. }
  196. void _scrollBar_ChangedPosition (object sender, EventArgs e)
  197. {
  198. _hostView.Top = _scrollBar.Position;
  199. if (_hostView.Top != _scrollBar.Position) {
  200. _scrollBar.Position = _hostView.Top;
  201. }
  202. _hostView.SetNeedsDisplay ();
  203. }
  204. void _scrollBar_OtherScrollBarView_ChangedPosition (object sender, EventArgs e)
  205. {
  206. _hostView.Left = _scrollBar.OtherScrollBarView.Position;
  207. if (_hostView.Left != _scrollBar.OtherScrollBarView.Position) {
  208. _scrollBar.OtherScrollBarView.Position = _hostView.Left;
  209. }
  210. _hostView.SetNeedsDisplay ();
  211. }
  212. [Fact]
  213. [ScrollBarAutoInitShutdown]
  214. public void Hosting_A_Null_View_To_A_ScrollBarView_Throws_ArgumentNullException ()
  215. {
  216. Assert.Throws<ArgumentNullException> ("The host parameter can't be null.",
  217. () => new ScrollBarView (null, true));
  218. Assert.Throws<ArgumentNullException> ("The host parameter can't be null.",
  219. () => new ScrollBarView (null, false));
  220. }
  221. [Fact]
  222. [ScrollBarAutoInitShutdown]
  223. public void Hosting_A_Null_SuperView_View_To_A_ScrollBarView_Throws_ArgumentNullException ()
  224. {
  225. Assert.Throws<ArgumentNullException> ("The host SuperView parameter can't be null.",
  226. () => new ScrollBarView (new View (), true));
  227. Assert.Throws<ArgumentNullException> ("The host SuperView parameter can't be null.",
  228. () => new ScrollBarView (new View (), false));
  229. }
  230. [Fact]
  231. [ScrollBarAutoInitShutdown]
  232. public void Hosting_Two_Vertical_ScrollBarView_Throws_ArgumentException ()
  233. {
  234. var top = new Toplevel ();
  235. var host = new View ();
  236. top.Add (host);
  237. var v = new ScrollBarView (host, true);
  238. var h = new ScrollBarView (host, true);
  239. Assert.Throws<ArgumentException> (() => v.OtherScrollBarView = h);
  240. Assert.Throws<ArgumentException> (() => h.OtherScrollBarView = v);
  241. }
  242. [Fact]
  243. [ScrollBarAutoInitShutdown]
  244. public void Hosting_Two_Horizontal_ScrollBarView_Throws_ArgumentException ()
  245. {
  246. var top = new Toplevel ();
  247. var host = new View ();
  248. top.Add (host);
  249. var v = new ScrollBarView (host, false);
  250. var h = new ScrollBarView (host, false);
  251. Assert.Throws<ArgumentException> (() => v.OtherScrollBarView = h);
  252. Assert.Throws<ArgumentException> (() => h.OtherScrollBarView = v);
  253. }
  254. [Fact]
  255. [ScrollBarAutoInitShutdown]
  256. public void Scrolling_With_Default_Constructor_Do_Not_Scroll ()
  257. {
  258. var sbv = new ScrollBarView {
  259. Position = 1
  260. };
  261. Assert.Equal (1, sbv.Position);
  262. Assert.NotEqual (0, sbv.Position);
  263. }
  264. [Fact]
  265. [ScrollBarAutoInitShutdown]
  266. public void Hosting_A_View_To_A_ScrollBarView ()
  267. {
  268. RemoveHandlers ();
  269. _scrollBar = new ScrollBarView (_hostView, true);
  270. Application.Begin (Application.Top);
  271. Assert.True (_scrollBar.IsVertical);
  272. Assert.False (_scrollBar.OtherScrollBarView.IsVertical);
  273. Assert.Equal (_scrollBar.Position, _hostView.Top);
  274. Assert.NotEqual (_scrollBar.Size, _hostView.Lines);
  275. Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
  276. Assert.NotEqual (_scrollBar.OtherScrollBarView.Size, _hostView.Cols);
  277. AddHandlers ();
  278. _hostView.SuperView.LayoutSubviews ();
  279. _hostView.Draw ();
  280. Assert.Equal (_scrollBar.Position, _hostView.Top);
  281. Assert.Equal (_scrollBar.Size, _hostView.Lines);
  282. Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
  283. Assert.Equal (_scrollBar.OtherScrollBarView.Size, _hostView.Cols);
  284. }
  285. [Fact]
  286. [ScrollBarAutoInitShutdown]
  287. public void ChangedPosition_Update_The_Hosted_View ()
  288. {
  289. Hosting_A_View_To_A_ScrollBarView ();
  290. AddHandlers ();
  291. _scrollBar.Position = 2;
  292. Assert.Equal (_scrollBar.Position, _hostView.Top);
  293. _scrollBar.OtherScrollBarView.Position = 5;
  294. Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
  295. }
  296. [Fact]
  297. [ScrollBarAutoInitShutdown]
  298. public void ChangedPosition_Scrolling ()
  299. {
  300. Hosting_A_View_To_A_ScrollBarView ();
  301. AddHandlers ();
  302. for (var i = 0; i < _scrollBar.Size; i++) {
  303. _scrollBar.Position += 1;
  304. Assert.Equal (_scrollBar.Position, _hostView.Top);
  305. }
  306. for (var i = _scrollBar.Size - 1; i >= 0; i--) {
  307. _scrollBar.Position -= 1;
  308. Assert.Equal (_scrollBar.Position, _hostView.Top);
  309. }
  310. for (var i = 0; i < _scrollBar.OtherScrollBarView.Size; i++) {
  311. _scrollBar.OtherScrollBarView.Position += i;
  312. Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
  313. }
  314. for (var i = _scrollBar.OtherScrollBarView.Size - 1; i >= 0; i--) {
  315. _scrollBar.OtherScrollBarView.Position -= 1;
  316. Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
  317. }
  318. }
  319. [Fact]
  320. [ScrollBarAutoInitShutdown]
  321. public void ChangedPosition_Negative_Value ()
  322. {
  323. Hosting_A_View_To_A_ScrollBarView ();
  324. AddHandlers ();
  325. _scrollBar.Position = -20;
  326. Assert.Equal (0, _scrollBar.Position);
  327. Assert.Equal (_scrollBar.Position, _hostView.Top);
  328. _scrollBar.OtherScrollBarView.Position = -50;
  329. Assert.Equal (0, _scrollBar.OtherScrollBarView.Position);
  330. Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
  331. }
  332. [Fact]
  333. [ScrollBarAutoInitShutdown]
  334. public void DrawContent_Update_The_ScrollBarView_Position ()
  335. {
  336. Hosting_A_View_To_A_ScrollBarView ();
  337. AddHandlers ();
  338. _hostView.Top = 3;
  339. _hostView.Draw ();
  340. Assert.Equal (_scrollBar.Position, _hostView.Top);
  341. _hostView.Left = 6;
  342. _hostView.Draw ();
  343. Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
  344. }
  345. [Fact]
  346. [ScrollBarAutoInitShutdown]
  347. public void OtherScrollBarView_Not_Null ()
  348. {
  349. Hosting_A_View_To_A_ScrollBarView ();
  350. AddHandlers ();
  351. Assert.NotNull (_scrollBar.OtherScrollBarView);
  352. Assert.NotEqual (_scrollBar, _scrollBar.OtherScrollBarView);
  353. Assert.Equal (_scrollBar.OtherScrollBarView.OtherScrollBarView, _scrollBar);
  354. }
  355. [Fact]
  356. [ScrollBarAutoInitShutdown]
  357. public void ShowScrollIndicator_Check ()
  358. {
  359. Hosting_A_View_To_A_ScrollBarView ();
  360. AddHandlers ();
  361. Assert.True (_scrollBar.ShowScrollIndicator);
  362. Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
  363. }
  364. [Fact]
  365. [ScrollBarAutoInitShutdown]
  366. public void KeepContentAlwaysInViewport_True ()
  367. {
  368. Hosting_A_View_To_A_ScrollBarView ();
  369. AddHandlers ();
  370. Assert.Equal (80, _hostView.Bounds.Width);
  371. Assert.Equal (25, _hostView.Bounds.Height);
  372. Assert.Equal (79, _scrollBar.OtherScrollBarView.Bounds.Width);
  373. Assert.Equal (24, _scrollBar.Bounds.Height);
  374. Assert.Equal (30, _scrollBar.Size);
  375. Assert.Equal (100, _scrollBar.OtherScrollBarView.Size);
  376. Assert.True (_scrollBar.ShowScrollIndicator);
  377. Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
  378. Assert.True (_scrollBar.Visible);
  379. Assert.True (_scrollBar.OtherScrollBarView.Visible);
  380. _scrollBar.Position = 50;
  381. Assert.Equal (_scrollBar.Position, _scrollBar.Size - _scrollBar.Bounds.Height);
  382. Assert.Equal (_scrollBar.Position, _hostView.Top);
  383. Assert.Equal (6, _scrollBar.Position);
  384. Assert.Equal (6, _hostView.Top);
  385. Assert.True (_scrollBar.ShowScrollIndicator);
  386. Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
  387. Assert.True (_scrollBar.Visible);
  388. Assert.True (_scrollBar.OtherScrollBarView.Visible);
  389. _scrollBar.OtherScrollBarView.Position = 150;
  390. Assert.Equal (_scrollBar.OtherScrollBarView.Position, _scrollBar.OtherScrollBarView.Size - _scrollBar.OtherScrollBarView.Bounds.Width);
  391. Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
  392. Assert.Equal (21, _scrollBar.OtherScrollBarView.Position);
  393. Assert.Equal (21, _hostView.Left);
  394. Assert.True (_scrollBar.ShowScrollIndicator);
  395. Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
  396. Assert.True (_scrollBar.Visible);
  397. Assert.True (_scrollBar.OtherScrollBarView.Visible);
  398. }
  399. [Fact]
  400. [ScrollBarAutoInitShutdown]
  401. public void KeepContentAlwaysInViewport_False ()
  402. {
  403. Hosting_A_View_To_A_ScrollBarView ();
  404. AddHandlers ();
  405. _scrollBar.KeepContentAlwaysInViewport = false;
  406. _scrollBar.Position = 50;
  407. Assert.Equal (_scrollBar.Position, _scrollBar.Size - 1);
  408. Assert.Equal (_scrollBar.Position, _hostView.Top);
  409. Assert.Equal (29, _scrollBar.Position);
  410. Assert.Equal (29, _hostView.Top);
  411. _scrollBar.OtherScrollBarView.Position = 150;
  412. Assert.Equal (_scrollBar.OtherScrollBarView.Position, _scrollBar.OtherScrollBarView.Size - 1);
  413. Assert.Equal (_scrollBar.OtherScrollBarView.Position, _hostView.Left);
  414. Assert.Equal (99, _scrollBar.OtherScrollBarView.Position);
  415. Assert.Equal (99, _hostView.Left);
  416. }
  417. [Fact]
  418. [ScrollBarAutoInitShutdown]
  419. public void AutoHideScrollBars_Check ()
  420. {
  421. Hosting_A_View_To_A_ScrollBarView ();
  422. AddHandlers ();
  423. _hostView.Draw ();
  424. Assert.True (_scrollBar.ShowScrollIndicator);
  425. Assert.True (_scrollBar.Visible);
  426. Assert.Equal ("Absolute(1)", _scrollBar.Width.ToString ());
  427. Assert.Equal (1, _scrollBar.Bounds.Width);
  428. Assert.Equal ("Combine(View(Height,HostView()(0,0,80,25))-Absolute(1))",
  429. _scrollBar.Height.ToString ());
  430. Assert.Equal (24, _scrollBar.Bounds.Height);
  431. Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
  432. Assert.True (_scrollBar.OtherScrollBarView.Visible);
  433. Assert.Equal ("Combine(View(Width,HostView()(0,0,80,25))-Absolute(1))",
  434. _scrollBar.OtherScrollBarView.Width.ToString ());
  435. Assert.Equal (79, _scrollBar.OtherScrollBarView.Bounds.Width);
  436. Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ());
  437. Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height);
  438. _hostView.Lines = 10;
  439. _hostView.Draw ();
  440. Assert.False (_scrollBar.ShowScrollIndicator);
  441. Assert.False (_scrollBar.Visible);
  442. Assert.Equal ("Absolute(1)", _scrollBar.Width.ToString ());
  443. Assert.Equal (1, _scrollBar.Bounds.Width);
  444. Assert.Equal ("Combine(View(Height,HostView()(0,0,80,25))-Absolute(1))",
  445. _scrollBar.Height.ToString ());
  446. Assert.Equal (24, _scrollBar.Bounds.Height);
  447. Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
  448. Assert.True (_scrollBar.OtherScrollBarView.Visible);
  449. Assert.Equal ("View(Width,HostView()(0,0,80,25))",
  450. _scrollBar.OtherScrollBarView.Width.ToString ());
  451. Assert.Equal (80, _scrollBar.OtherScrollBarView.Bounds.Width);
  452. Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ());
  453. Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height);
  454. _hostView.Cols = 60;
  455. _hostView.Draw ();
  456. Assert.False (_scrollBar.ShowScrollIndicator);
  457. Assert.False (_scrollBar.Visible);
  458. Assert.Equal ("Absolute(1)", _scrollBar.Width.ToString ());
  459. Assert.Equal (1, _scrollBar.Bounds.Width);
  460. Assert.Equal ("Combine(View(Height,HostView()(0,0,80,25))-Absolute(1))",
  461. _scrollBar.Height.ToString ());
  462. Assert.Equal (24, _scrollBar.Bounds.Height);
  463. Assert.False (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
  464. Assert.False (_scrollBar.OtherScrollBarView.Visible);
  465. Assert.Equal ("View(Width,HostView()(0,0,80,25))",
  466. _scrollBar.OtherScrollBarView.Width.ToString ());
  467. Assert.Equal (80, _scrollBar.OtherScrollBarView.Bounds.Width);
  468. Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ());
  469. Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height);
  470. _hostView.Lines = 40;
  471. _hostView.Draw ();
  472. Assert.True (_scrollBar.ShowScrollIndicator);
  473. Assert.True (_scrollBar.Visible);
  474. Assert.Equal ("Absolute(1)", _scrollBar.Width.ToString ());
  475. Assert.Equal (1, _scrollBar.Bounds.Width);
  476. Assert.Equal ("View(Height,HostView()(0,0,80,25))",
  477. _scrollBar.Height.ToString ());
  478. Assert.Equal (25, _scrollBar.Bounds.Height);
  479. Assert.False (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
  480. Assert.False (_scrollBar.OtherScrollBarView.Visible);
  481. Assert.Equal ("View(Width,HostView()(0,0,80,25))",
  482. _scrollBar.OtherScrollBarView.Width.ToString ());
  483. Assert.Equal (80, _scrollBar.OtherScrollBarView.Bounds.Width);
  484. Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ());
  485. Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height);
  486. _hostView.Cols = 120;
  487. _hostView.Draw ();
  488. Assert.True (_scrollBar.ShowScrollIndicator);
  489. Assert.True (_scrollBar.Visible);
  490. Assert.Equal ("Absolute(1)", _scrollBar.Width.ToString ());
  491. Assert.Equal (1, _scrollBar.Bounds.Width);
  492. Assert.Equal ("Combine(View(Height,HostView()(0,0,80,25))-Absolute(1))",
  493. _scrollBar.Height.ToString ());
  494. Assert.Equal (24, _scrollBar.Bounds.Height);
  495. Assert.True (_scrollBar.OtherScrollBarView.ShowScrollIndicator);
  496. Assert.True (_scrollBar.OtherScrollBarView.Visible);
  497. Assert.Equal ("Combine(View(Width,HostView()(0,0,80,25))-Absolute(1))",
  498. _scrollBar.OtherScrollBarView.Width.ToString ());
  499. Assert.Equal (79, _scrollBar.OtherScrollBarView.Bounds.Width);
  500. Assert.Equal ("Absolute(1)", _scrollBar.OtherScrollBarView.Height.ToString ());
  501. Assert.Equal (1, _scrollBar.OtherScrollBarView.Bounds.Height);
  502. }
  503. [Fact]
  504. public void Constructor_ShowBothScrollIndicator_False_And_IsVertical_True_Refresh_Does_Not_Throws_An_Object_Null_Exception ()
  505. {
  506. var exception = Record.Exception (() => {
  507. Application.Init (new FakeDriver ());
  508. var top = Application.Top;
  509. var win = new Window {
  510. X = 0,
  511. Y = 0,
  512. Width = Dim.Fill (),
  513. Height = Dim.Fill ()
  514. };
  515. var source = new List<string> ();
  516. for (var i = 0; i < 50; i++) {
  517. source.Add ($"item {i}");
  518. }
  519. var listView = new ListView (source) {
  520. X = 0,
  521. Y = 0,
  522. Width = Dim.Fill (),
  523. Height = Dim.Fill ()
  524. };
  525. win.Add (listView);
  526. var newScrollBarView = new ScrollBarView (listView, true, false) {
  527. KeepContentAlwaysInViewport = true
  528. };
  529. win.Add (newScrollBarView);
  530. newScrollBarView.ChangedPosition += (s, e) => {
  531. listView.TopItem = newScrollBarView.Position;
  532. if (listView.TopItem != newScrollBarView.Position) {
  533. newScrollBarView.Position = listView.TopItem;
  534. }
  535. Assert.Equal (newScrollBarView.Position, listView.TopItem);
  536. listView.SetNeedsDisplay ();
  537. };
  538. listView.DrawContent += (s, e) => {
  539. newScrollBarView.Size = listView.Source.Count;
  540. Assert.Equal (newScrollBarView.Size, listView.Source.Count);
  541. newScrollBarView.Position = listView.TopItem;
  542. Assert.Equal (newScrollBarView.Position, listView.TopItem);
  543. newScrollBarView.Refresh ();
  544. };
  545. top.Ready += (s, e) => {
  546. newScrollBarView.Position = 45;
  547. Assert.Equal (newScrollBarView.Position, newScrollBarView.Size - listView.TopItem + (listView.TopItem - listView.Bounds.Height));
  548. Assert.Equal (newScrollBarView.Position, listView.TopItem);
  549. Assert.Equal (27, newScrollBarView.Position);
  550. Assert.Equal (27, listView.TopItem);
  551. Application.RequestStop ();
  552. };
  553. top.Add (win);
  554. Application.Run ();
  555. Application.Shutdown ();
  556. });
  557. Assert.Null (exception);
  558. }
  559. [Fact]
  560. public void Constructor_ShowBothScrollIndicator_False_And_IsVertical_False_Refresh_Does_Not_Throws_An_Object_Null_Exception ()
  561. {
  562. // BUGBUG: v2 - Tig broke these tests; @bdisp help?
  563. //var exception = Record.Exception (() => {
  564. Application.Init (new FakeDriver ());
  565. var top = Application.Top;
  566. var win = new Window {
  567. X = 0,
  568. Y = 0,
  569. Width = Dim.Fill (),
  570. Height = Dim.Fill ()
  571. };
  572. var source = new List<string> ();
  573. for (var i = 0; i < 50; i++) {
  574. var text = $"item {i} - ";
  575. for (var j = 0; j < 160; j++) {
  576. var col = j.ToString ();
  577. text += col.Length == 1 ? col [0] : col [1];
  578. }
  579. source.Add (text);
  580. }
  581. var listView = new ListView (source) {
  582. X = 0,
  583. Y = 0,
  584. Width = Dim.Fill (),
  585. Height = Dim.Fill ()
  586. };
  587. win.Add (listView);
  588. var newScrollBarView = new ScrollBarView (listView, false, false) {
  589. KeepContentAlwaysInViewport = true
  590. };
  591. win.Add (newScrollBarView);
  592. newScrollBarView.ChangedPosition += (s, e) => {
  593. listView.LeftItem = newScrollBarView.Position;
  594. if (listView.LeftItem != newScrollBarView.Position) {
  595. newScrollBarView.Position = listView.LeftItem;
  596. }
  597. Assert.Equal (newScrollBarView.Position, listView.LeftItem);
  598. listView.SetNeedsDisplay ();
  599. };
  600. listView.DrawContent += (s, e) => {
  601. newScrollBarView.Size = listView.Maxlength;
  602. Assert.Equal (newScrollBarView.Size, listView.Maxlength);
  603. newScrollBarView.Position = listView.LeftItem;
  604. Assert.Equal (newScrollBarView.Position, listView.LeftItem);
  605. newScrollBarView.Refresh ();
  606. };
  607. top.Ready += (s, e) => {
  608. newScrollBarView.Position = 100;
  609. //Assert.Equal (newScrollBarView.Position, newScrollBarView.Size - listView.LeftItem + (listView.LeftItem - listView.Bounds.Width));
  610. Assert.Equal (newScrollBarView.Position, listView.LeftItem);
  611. //Assert.Equal (92, newScrollBarView.Position);
  612. //Assert.Equal (92, listView.LeftItem);
  613. Application.RequestStop ();
  614. };
  615. top.Add (win);
  616. Application.Run ();
  617. Application.Shutdown ();
  618. //});
  619. //Assert.Null (exception);
  620. }
  621. [Fact]
  622. [AutoInitShutdown]
  623. public void Internal_Tests ()
  624. {
  625. var top = Application.Top;
  626. Assert.Equal (new Rect (0, 0, 80, 25), top.Bounds);
  627. var view = new View { Width = Dim.Fill (), Height = Dim.Fill () };
  628. top.Add (view);
  629. var sbv = new ScrollBarView (view, true);
  630. top.Add (sbv);
  631. Assert.Equal (view, sbv.Host);
  632. sbv.Size = 40;
  633. sbv.Position = 0;
  634. sbv.OtherScrollBarView.Size = 100;
  635. sbv.OtherScrollBarView.Position = 0;
  636. // Host bounds is not empty.
  637. Assert.True (sbv.CanScroll (10, out var max, sbv.IsVertical));
  638. Assert.Equal (10, max);
  639. Assert.True (sbv.OtherScrollBarView.CanScroll (10, out max, sbv.OtherScrollBarView.IsVertical));
  640. Assert.Equal (10, max);
  641. Application.Begin (top);
  642. // They are visible so they are drawn.
  643. Assert.True (sbv.Visible);
  644. Assert.True (sbv.OtherScrollBarView.Visible);
  645. top.LayoutSubviews ();
  646. // Now the host bounds is not empty.
  647. Assert.True (sbv.CanScroll (10, out max, sbv.IsVertical));
  648. Assert.Equal (10, max);
  649. Assert.True (sbv.OtherScrollBarView.CanScroll (10, out max, sbv.OtherScrollBarView.IsVertical));
  650. Assert.Equal (10, max);
  651. Assert.True (sbv.CanScroll (50, out max, sbv.IsVertical));
  652. Assert.Equal (40, sbv.Size);
  653. Assert.Equal (16, max); // 16+25=41
  654. Assert.True (sbv.OtherScrollBarView.CanScroll (150, out max, sbv.OtherScrollBarView.IsVertical));
  655. Assert.Equal (100, sbv.OtherScrollBarView.Size);
  656. Assert.Equal (21, max); // 21+80=101
  657. Assert.True (sbv.Visible);
  658. Assert.True (sbv.OtherScrollBarView.Visible);
  659. sbv.KeepContentAlwaysInViewport = false;
  660. sbv.OtherScrollBarView.KeepContentAlwaysInViewport = false;
  661. Assert.True (sbv.CanScroll (50, out max, sbv.IsVertical));
  662. Assert.Equal (39, max);
  663. Assert.True (sbv.OtherScrollBarView.CanScroll (150, out max, sbv.OtherScrollBarView.IsVertical));
  664. Assert.Equal (99, max);
  665. Assert.True (sbv.Visible);
  666. Assert.True (sbv.OtherScrollBarView.Visible);
  667. }
  668. [Fact]
  669. [AutoInitShutdown]
  670. public void Hosting_ShowBothScrollIndicator_Invisible ()
  671. {
  672. var textView = new TextView {
  673. Width = Dim.Fill (),
  674. Height = Dim.Fill (),
  675. Text = "This is the help text for the Second Step.\n\nPress the button to see a message box.\n\nEnter name too."
  676. };
  677. var win = new Window {
  678. Width = Dim.Fill (),
  679. Height = Dim.Fill ()
  680. };
  681. win.Add (textView);
  682. var scrollBar = new ScrollBarView (textView, true);
  683. scrollBar.ChangedPosition += (s, e) => {
  684. textView.TopRow = scrollBar.Position;
  685. if (textView.TopRow != scrollBar.Position) {
  686. scrollBar.Position = textView.TopRow;
  687. }
  688. textView.SetNeedsDisplay ();
  689. };
  690. scrollBar.OtherScrollBarView.ChangedPosition += (s, e) => {
  691. textView.LeftColumn = scrollBar.OtherScrollBarView.Position;
  692. if (textView.LeftColumn != scrollBar.OtherScrollBarView.Position) {
  693. scrollBar.OtherScrollBarView.Position = textView.LeftColumn;
  694. }
  695. textView.SetNeedsDisplay ();
  696. };
  697. scrollBar.VisibleChanged += (s, e) => {
  698. if (scrollBar.Visible && textView.RightOffset == 0) {
  699. textView.RightOffset = 1;
  700. } else if (!scrollBar.Visible && textView.RightOffset == 1) {
  701. textView.RightOffset = 0;
  702. }
  703. };
  704. scrollBar.OtherScrollBarView.VisibleChanged += (s, e) => {
  705. if (scrollBar.OtherScrollBarView.Visible && textView.BottomOffset == 0) {
  706. textView.BottomOffset = 1;
  707. } else if (!scrollBar.OtherScrollBarView.Visible && textView.BottomOffset == 1) {
  708. textView.BottomOffset = 0;
  709. }
  710. };
  711. textView.LayoutComplete += (s, e) => {
  712. scrollBar.Size = textView.Lines;
  713. scrollBar.Position = textView.TopRow;
  714. if (scrollBar.OtherScrollBarView != null) {
  715. scrollBar.OtherScrollBarView.Size = textView.Maxlength;
  716. scrollBar.OtherScrollBarView.Position = textView.LeftColumn;
  717. }
  718. scrollBar.LayoutSubviews ();
  719. scrollBar.Refresh ();
  720. };
  721. Application.Top.Add (win);
  722. Application.Begin (Application.Top);
  723. ((FakeDriver)Application.Driver).SetBufferSize (45, 20);
  724. Assert.True (scrollBar.AutoHideScrollBars);
  725. Assert.False (scrollBar.ShowScrollIndicator);
  726. Assert.False (scrollBar.OtherScrollBarView.ShowScrollIndicator);
  727. Assert.Equal (5, textView.Lines);
  728. Assert.Equal (42, textView.Maxlength);
  729. Assert.Equal (0, textView.LeftColumn);
  730. Assert.Equal (0, scrollBar.Position);
  731. Assert.Equal (0, scrollBar.OtherScrollBarView.Position);
  732. var expected = @"
  733. ┌───────────────────────────────────────────┐
  734. │This is the help text for the Second Step. │
  735. │ │
  736. │Press the button to see a message box. │
  737. │ │
  738. │Enter name too. │
  739. │ │
  740. │ │
  741. │ │
  742. │ │
  743. │ │
  744. │ │
  745. │ │
  746. │ │
  747. │ │
  748. │ │
  749. │ │
  750. │ │
  751. │ │
  752. └───────────────────────────────────────────┘
  753. ";
  754. var pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  755. Assert.Equal (new Rect (0, 0, 45, 20), pos);
  756. textView.WordWrap = true;
  757. ((FakeDriver)Application.Driver).SetBufferSize (26, 20);
  758. Application.Refresh ();
  759. Assert.True (textView.WordWrap);
  760. Assert.True (scrollBar.AutoHideScrollBars);
  761. Assert.Equal (7, textView.Lines);
  762. Assert.Equal (22, textView.Maxlength);
  763. Assert.Equal (0, textView.LeftColumn);
  764. Assert.Equal (0, scrollBar.Position);
  765. Assert.Equal (0, scrollBar.OtherScrollBarView.Position);
  766. expected = @"
  767. ┌────────────────────────┐
  768. │This is the help text │
  769. │for the Second Step. │
  770. │ │
  771. │Press the button to │
  772. │see a message box. │
  773. │ │
  774. │Enter name too. │
  775. │ │
  776. │ │
  777. │ │
  778. │ │
  779. │ │
  780. │ │
  781. │ │
  782. │ │
  783. │ │
  784. │ │
  785. │ │
  786. └────────────────────────┘
  787. ";
  788. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  789. Assert.Equal (new Rect (0, 0, 26, 20), pos);
  790. ((FakeDriver)Application.Driver).SetBufferSize (10, 10);
  791. Application.Refresh ();
  792. Assert.True (textView.WordWrap);
  793. Assert.True (scrollBar.AutoHideScrollBars);
  794. Assert.Equal (20, textView.Lines);
  795. Assert.Equal (7, textView.Maxlength);
  796. Assert.Equal (0, textView.LeftColumn);
  797. Assert.Equal (0, scrollBar.Position);
  798. Assert.Equal (0, scrollBar.OtherScrollBarView.Position);
  799. Assert.True (scrollBar.ShowScrollIndicator);
  800. expected = @"
  801. ┌────────┐
  802. │This ▲│
  803. │is the ┬│
  804. │help ││
  805. │text ┴│
  806. │for ░│
  807. │the ░│
  808. │Second ░│
  809. │Step. ▼│
  810. └────────┘
  811. ";
  812. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, output);
  813. Assert.Equal (new Rect (0, 0, 10, 10), pos);
  814. }
  815. [Fact]
  816. [AutoInitShutdown]
  817. public void ContentBottomRightCorner_Not_Redraw_If_Both_Size_Equal_To_Zero ()
  818. {
  819. var text = "This is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test";
  820. var label = new Label (text);
  821. Application.Top.Add (label);
  822. var sbv = new ScrollBarView (label, true) {
  823. Size = 100
  824. };
  825. sbv.OtherScrollBarView.Size = 100;
  826. Application.Begin (Application.Top);
  827. Assert.Equal (100, sbv.Size);
  828. Assert.Equal (100, sbv.OtherScrollBarView.Size);
  829. Assert.True (sbv.ShowScrollIndicator);
  830. Assert.True (sbv.OtherScrollBarView.ShowScrollIndicator);
  831. Assert.True (sbv.Visible);
  832. Assert.True (sbv.OtherScrollBarView.Visible);
  833. TestHelpers.AssertDriverContentsWithFrameAre (@"
  834. This is a tes▲
  835. This is a tes┬
  836. This is a tes┴
  837. This is a tes░
  838. This is a tes▼
  839. ◄├─┤░░░░░░░░►
  840. ", output);
  841. sbv.Size = 0;
  842. sbv.OtherScrollBarView.Size = 0;
  843. Assert.Equal (0, sbv.Size);
  844. Assert.Equal (0, sbv.OtherScrollBarView.Size);
  845. Assert.False (sbv.ShowScrollIndicator);
  846. Assert.False (sbv.OtherScrollBarView.ShowScrollIndicator);
  847. Assert.False (sbv.Visible);
  848. Assert.False (sbv.OtherScrollBarView.Visible);
  849. Application.Top.Draw ();
  850. TestHelpers.AssertDriverContentsWithFrameAre (@"
  851. This is a test
  852. This is a test
  853. This is a test
  854. This is a test
  855. This is a test
  856. This is a test
  857. ", output);
  858. sbv.Size = 50;
  859. sbv.OtherScrollBarView.Size = 50;
  860. Assert.Equal (50, sbv.Size);
  861. Assert.Equal (50, sbv.OtherScrollBarView.Size);
  862. Assert.True (sbv.ShowScrollIndicator);
  863. Assert.True (sbv.OtherScrollBarView.ShowScrollIndicator);
  864. Assert.True (sbv.Visible);
  865. Assert.True (sbv.OtherScrollBarView.Visible);
  866. Application.Top.Draw ();
  867. TestHelpers.AssertDriverContentsWithFrameAre (@"
  868. This is a tes▲
  869. This is a tes┬
  870. This is a tes┴
  871. This is a tes░
  872. This is a tes▼
  873. ◄├──┤░░░░░░░►
  874. ", output);
  875. }
  876. [Fact]
  877. [AutoInitShutdown]
  878. public void ContentBottomRightCorner_Not_Redraw_If_One_Size_Equal_To_Zero ()
  879. {
  880. var text = "This is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test";
  881. var label = new Label (text);
  882. Application.Top.Add (label);
  883. var sbv = new ScrollBarView (label, true, false) {
  884. Size = 100
  885. };
  886. Application.Begin (Application.Top);
  887. Assert.Equal (100, sbv.Size);
  888. Assert.Null (sbv.OtherScrollBarView);
  889. Assert.True (sbv.ShowScrollIndicator);
  890. Assert.True (sbv.Visible);
  891. TestHelpers.AssertDriverContentsWithFrameAre (@"
  892. This is a tes▲
  893. This is a tes┬
  894. This is a tes┴
  895. This is a tes░
  896. This is a tes░
  897. This is a tes▼
  898. ", output);
  899. sbv.Size = 0;
  900. Assert.Equal (0, sbv.Size);
  901. Assert.False (sbv.ShowScrollIndicator);
  902. Assert.False (sbv.Visible);
  903. Application.Top.Draw ();
  904. TestHelpers.AssertDriverContentsWithFrameAre (@"
  905. This is a test
  906. This is a test
  907. This is a test
  908. This is a test
  909. This is a test
  910. This is a test
  911. ", output);
  912. }
  913. [Fact]
  914. [AutoInitShutdown]
  915. public void ShowScrollIndicator_False_Must_Also_Set_Visible_To_False_To_Not_Respond_To_Events ()
  916. {
  917. var clicked = false;
  918. var text = "This is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test";
  919. var label = new Label (text) { Width = 14, Height = 5 };
  920. var btn = new Button (14, 0, "Click Me!");
  921. btn.Clicked += (s, e) => clicked = true;
  922. Application.Top.Add (label, btn);
  923. var sbv = new ScrollBarView (label, true, false) {
  924. Size = 5
  925. };
  926. Application.Begin (Application.Top);
  927. Assert.Equal (5, sbv.Size);
  928. Assert.Null (sbv.OtherScrollBarView);
  929. Assert.False (sbv.ShowScrollIndicator);
  930. Assert.False (sbv.Visible);
  931. TestHelpers.AssertDriverContentsWithFrameAre (@$"
  932. This is a test{CM.Glyphs.LeftBracket} Click Me! {CM.Glyphs.RightBracket}
  933. This is a test
  934. This is a test
  935. This is a test
  936. This is a test ", output);
  937. Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent {
  938. X = 15,
  939. Y = 0,
  940. Flags = MouseFlags.Button1Clicked
  941. }));
  942. Assert.Null (Application.MouseGrabView);
  943. Assert.True (clicked);
  944. clicked = false;
  945. sbv.Visible = true;
  946. Assert.Equal (5, sbv.Size);
  947. Assert.False (sbv.ShowScrollIndicator);
  948. Assert.True (sbv.Visible);
  949. Application.Top.Draw ();
  950. Assert.False (sbv.Visible);
  951. TestHelpers.AssertDriverContentsWithFrameAre (@$"
  952. This is a test{CM.Glyphs.LeftBracket} Click Me! {CM.Glyphs.RightBracket}
  953. This is a test
  954. This is a test
  955. This is a test
  956. This is a test ", output);
  957. Application.OnMouseEvent (new MouseEventEventArgs (new MouseEvent {
  958. X = 15,
  959. Y = 0,
  960. Flags = MouseFlags.Button1Clicked
  961. }));
  962. Assert.Null (Application.MouseGrabView);
  963. Assert.True (clicked);
  964. Assert.Equal (5, sbv.Size);
  965. Assert.False (sbv.ShowScrollIndicator);
  966. Assert.False (sbv.Visible);
  967. }
  968. [Fact]
  969. [AutoInitShutdown]
  970. public void ClearOnVisibleFalse_Gets_Sets ()
  971. {
  972. var text = "This is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test\nThis is a test";
  973. var label = new Label (text);
  974. Application.Top.Add (label);
  975. var sbv = new ScrollBarView (label, true, false) {
  976. Size = 100,
  977. ClearOnVisibleFalse = false
  978. };
  979. Application.Begin (Application.Top);
  980. Assert.True (sbv.Visible);
  981. TestHelpers.AssertDriverContentsWithFrameAre (@"
  982. This is a tes▲
  983. This is a tes┬
  984. This is a tes┴
  985. This is a tes░
  986. This is a tes░
  987. This is a tes▼
  988. ", output);
  989. sbv.Visible = false;
  990. Assert.False (sbv.Visible);
  991. Application.Top.Draw ();
  992. TestHelpers.AssertDriverContentsWithFrameAre (@"
  993. This is a test
  994. This is a test
  995. This is a test
  996. This is a test
  997. This is a test
  998. This is a test
  999. ", output);
  1000. sbv.Visible = true;
  1001. Assert.True (sbv.Visible);
  1002. Application.Top.Draw ();
  1003. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1004. This is a tes▲
  1005. This is a tes┬
  1006. This is a tes┴
  1007. This is a tes░
  1008. This is a tes░
  1009. This is a tes▼
  1010. ", output);
  1011. sbv.ClearOnVisibleFalse = true;
  1012. sbv.Visible = false;
  1013. Assert.False (sbv.Visible);
  1014. TestHelpers.AssertDriverContentsWithFrameAre (@"
  1015. This is a tes
  1016. This is a tes
  1017. This is a tes
  1018. This is a tes
  1019. This is a tes
  1020. This is a tes
  1021. ", output);
  1022. }
  1023. // This class enables test functions annotated with the [InitShutdown] attribute
  1024. // to have a function called before the test function is called and after.
  1025. //
  1026. // This is necessary because a) Application is a singleton and Init/Shutdown must be called
  1027. // as a pair, and b) all unit test functions should be atomic.
  1028. [AttributeUsage (AttributeTargets.Class | AttributeTargets.Method)]
  1029. public class ScrollBarAutoInitShutdownAttribute : AutoInitShutdownAttribute {
  1030. public override void Before (MethodInfo methodUnderTest)
  1031. {
  1032. base.Before (methodUnderTest);
  1033. _hostView = new HostView {
  1034. Width = Dim.Fill (),
  1035. Height = Dim.Fill (),
  1036. Top = 0,
  1037. Lines = 30,
  1038. Left = 0,
  1039. Cols = 100
  1040. };
  1041. Application.Top.Add (_hostView);
  1042. }
  1043. public override void After (MethodInfo methodUnderTest)
  1044. {
  1045. _hostView = null;
  1046. base.After (methodUnderTest);
  1047. }
  1048. }
  1049. public class HostView : View {
  1050. public int Top { get; set; }
  1051. public int Lines { get; set; }
  1052. public int Left { get; set; }
  1053. public int Cols { get; set; }
  1054. }
  1055. }