Dim.Tests.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. using System.Globalization;
  2. using System.Text;
  3. using Xunit.Abstractions;
  4. using static Terminal.Gui.Dim;
  5. namespace Terminal.Gui.LayoutTests;
  6. public class DimTests
  7. {
  8. private readonly ITestOutputHelper _output;
  9. public DimTests (ITestOutputHelper output)
  10. {
  11. _output = output;
  12. Console.OutputEncoding = Encoding.Default;
  13. // Change current culture
  14. var culture = CultureInfo.CreateSpecificCulture ("en-US");
  15. Thread.CurrentThread.CurrentCulture = culture;
  16. Thread.CurrentThread.CurrentUICulture = culture;
  17. }
  18. [Fact]
  19. public void DimAbsolute_Calculate_ReturnsCorrectValue ()
  20. {
  21. var dim = new DimAbsolute (10);
  22. int result = dim.Calculate (0, 100, null, Dimension.None);
  23. Assert.Equal (10, result);
  24. }
  25. // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
  26. // A new test that does not depend on Application is needed.
  27. [Fact]
  28. [AutoInitShutdown]
  29. public void Dim_Add_Operator ()
  30. {
  31. Toplevel top = new ();
  32. var view = new View { X = 0, Y = 0, Width = 20, Height = 0 };
  33. var field = new TextField { X = 0, Y = Pos.Bottom (view), Width = 20 };
  34. var count = 0;
  35. field.KeyDown += (s, k) =>
  36. {
  37. if (k.KeyCode == KeyCode.Enter)
  38. {
  39. field.Text = $"Label {count}";
  40. var label = new Label { X = 0, Y = view.Viewport.Height, /*Width = 20,*/ Text = field.Text };
  41. view.Add (label);
  42. Assert.Equal ($"Label {count}", label.Text);
  43. Assert.Equal ($"Absolute({count})", label.Y.ToString ());
  44. Assert.Equal ($"Absolute({count})", view.Height.ToString ());
  45. view.Height += 1;
  46. count++;
  47. Assert.Equal ($"Absolute({count})", view.Height.ToString ());
  48. }
  49. };
  50. Application.Iteration += (s, a) =>
  51. {
  52. while (count < 20)
  53. {
  54. field.NewKeyDownEvent (Key.Enter);
  55. }
  56. Application.RequestStop ();
  57. };
  58. var win = new Window ();
  59. win.Add (view);
  60. win.Add (field);
  61. top.Add (win);
  62. Application.Run (top);
  63. top.Dispose ();
  64. Assert.Equal (20, count);
  65. }
  66. // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
  67. // TODO: A new test that calls SetRelativeLayout directly is needed.
  68. [Fact]
  69. [AutoInitShutdown]
  70. public void Dim_Subtract_Operator ()
  71. {
  72. Toplevel top = new ();
  73. var view = new View { X = 0, Y = 0, Width = 20, Height = 0 };
  74. var field = new TextField { X = 0, Y = Pos.Bottom (view), Width = 20 };
  75. var count = 20;
  76. List<Label> listLabels = new ();
  77. for (var i = 0; i < count; i++)
  78. {
  79. field.Text = $"Label {i}";
  80. var label = new Label { X = 0, Y = view.Viewport.Height, /*Width = 20,*/ Text = field.Text };
  81. view.Add (label);
  82. Assert.Equal ($"Label {i}", label.Text);
  83. Assert.Equal ($"Absolute({i})", label.Y.ToString ());
  84. listLabels.Add (label);
  85. Assert.Equal ($"Absolute({i})", view.Height.ToString ());
  86. view.Height += 1;
  87. Assert.Equal ($"Absolute({i + 1})", view.Height.ToString ());
  88. }
  89. field.KeyDown += (s, k) =>
  90. {
  91. if (k.KeyCode == KeyCode.Enter)
  92. {
  93. Assert.Equal ($"Label {count - 1}", listLabels [count - 1].Text);
  94. view.Remove (listLabels [count - 1]);
  95. listLabels [count - 1].Dispose ();
  96. Assert.Equal ($"Absolute({count})", view.Height.ToString ());
  97. view.Height -= 1;
  98. count--;
  99. Assert.Equal ($"Absolute({count})", view.Height.ToString ());
  100. }
  101. };
  102. Application.Iteration += (s, a) =>
  103. {
  104. while (count > 0)
  105. {
  106. field.NewKeyDownEvent (Key.Enter);
  107. }
  108. Application.RequestStop ();
  109. };
  110. var win = new Window ();
  111. win.Add (view);
  112. win.Add (field);
  113. top.Add (win);
  114. Application.Run (top);
  115. Assert.Equal (0, count);
  116. top.Dispose ();
  117. }
  118. // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
  119. // TODO: A new test that calls SetRelativeLayout directly is needed.
  120. [Fact]
  121. [TestRespondersDisposed]
  122. public void Dim_Validation_Do_Not_Throws_If_NewValue_Is_DimAbsolute_And_OldValue_Is_Null ()
  123. {
  124. var t = new View { Width = 80, Height = 25, Text = "top" };
  125. var w = new Window
  126. {
  127. X = 1,
  128. Y = 2,
  129. Width = 4,
  130. Height = 5,
  131. Title = "w"
  132. };
  133. t.Add (w);
  134. t.LayoutSubviews ();
  135. Assert.Equal (3, w.Width = 3);
  136. Assert.Equal (4, w.Height = 4);
  137. t.Dispose ();
  138. }
  139. [Fact]
  140. public void DimHeight_Set_To_Null_Throws ()
  141. {
  142. Dim dim = Height (null);
  143. Assert.Throws<NullReferenceException> (() => dim.ToString ());
  144. }
  145. [Fact]
  146. [TestRespondersDisposed]
  147. public void DimHeight_SetsValue ()
  148. {
  149. var testVal = Rectangle.Empty;
  150. var testValview = new View { Frame = testVal };
  151. Dim dim = Height (testValview);
  152. Assert.Equal ($"View(Height,View(){testVal})", dim.ToString ());
  153. testValview.Dispose ();
  154. testVal = new (1, 2, 3, 4);
  155. testValview = new() { Frame = testVal };
  156. dim = Height (testValview);
  157. Assert.Equal ($"View(Height,View(){testVal})", dim.ToString ());
  158. testValview.Dispose ();
  159. }
  160. [Fact]
  161. [TestRespondersDisposed]
  162. public void Internal_Tests ()
  163. {
  164. var dimFactor = new DimPercent (10);
  165. Assert.Equal (10, dimFactor.GetAnchor (100));
  166. var dimAbsolute = new DimAbsolute (10);
  167. Assert.Equal (10, dimAbsolute.GetAnchor (0));
  168. var dimFill = new DimFill (1);
  169. Assert.Equal (99, dimFill.GetAnchor (100));
  170. var dimCombine = new DimCombine (AddOrSubtract.Add, dimFactor, dimAbsolute);
  171. Assert.Equal (dimCombine.Left, dimFactor);
  172. Assert.Equal (dimCombine.Right, dimAbsolute);
  173. Assert.Equal (20, dimCombine.GetAnchor (100));
  174. var view = new View { Frame = new (20, 10, 20, 1) };
  175. var dimViewHeight = new DimView (view, Dimension.Height);
  176. Assert.Equal (1, dimViewHeight.GetAnchor (0));
  177. var dimViewWidth = new DimView (view, Dimension.Width);
  178. Assert.Equal (20, dimViewWidth.GetAnchor (0));
  179. view.Dispose ();
  180. }
  181. // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
  182. // TODO: A new test that calls SetRelativeLayout directly is needed.
  183. [Fact]
  184. [AutoInitShutdown]
  185. public void Only_DimAbsolute_And_DimFactor_As_A_Different_Procedure_For_Assigning_Value_To_Width_Or_Height ()
  186. {
  187. // Testing with the Button because it properly handles the Dim class.
  188. Toplevel t = new ();
  189. var w = new Window { Width = 100, Height = 100 };
  190. var f1 = new FrameView
  191. {
  192. X = 0,
  193. Y = 0,
  194. Width = Percent (50),
  195. Height = 5,
  196. Title = "f1"
  197. };
  198. var f2 = new FrameView
  199. {
  200. X = Pos.Right (f1),
  201. Y = 0,
  202. Width = Fill (),
  203. Height = 5,
  204. Title = "f2"
  205. };
  206. var v1 = new Button
  207. {
  208. X = Pos.X (f1) + 2,
  209. Y = Pos.Bottom (f1) + 2,
  210. Width = Width (f1) - 2,
  211. Height = Fill () - 2,
  212. ValidatePosDim = true,
  213. Text = "v1"
  214. };
  215. var v2 = new Button
  216. {
  217. X = Pos.X (f2) + 2,
  218. Y = Pos.Bottom (f2) + 2,
  219. Width = Width (f2) - 2,
  220. Height = Fill () - 2,
  221. ValidatePosDim = true,
  222. Text = "v2"
  223. };
  224. var v3 = new Button
  225. {
  226. Width = Percent (10),
  227. Height = Percent (10),
  228. ValidatePosDim = true,
  229. Text = "v3"
  230. };
  231. var v4 = new Button
  232. {
  233. Width = Absolute (50),
  234. Height = Absolute (50),
  235. ValidatePosDim = true,
  236. Text = "v4"
  237. };
  238. var v5 = new Button
  239. {
  240. Width = Width (v1) - Width (v3),
  241. Height = Height (v1) - Height (v3),
  242. ValidatePosDim = true,
  243. Text = "v5"
  244. };
  245. var v6 = new Button
  246. {
  247. X = Pos.X (f2),
  248. Y = Pos.Bottom (f2) + 2,
  249. Width = Percent (20, DimPercentMode.Position),
  250. Height = Percent (20, DimPercentMode.Position),
  251. ValidatePosDim = true,
  252. Text = "v6"
  253. };
  254. w.Add (f1, f2, v1, v2, v3, v4, v5, v6);
  255. t.Add (w);
  256. t.Ready += (s, e) =>
  257. {
  258. Assert.Equal ("Absolute(100)", w.Width.ToString ());
  259. Assert.Equal ("Absolute(100)", w.Height.ToString ());
  260. Assert.Equal (100, w.Frame.Width);
  261. Assert.Equal (100, w.Frame.Height);
  262. Assert.Equal ("Absolute(5)", f1.Height.ToString ());
  263. Assert.Equal (49, f1.Frame.Width); // 50-1=49
  264. Assert.Equal (5, f1.Frame.Height);
  265. Assert.Equal ("Fill(Absolute(0))", f2.Width.ToString ());
  266. Assert.Equal ("Absolute(5)", f2.Height.ToString ());
  267. Assert.Equal (49, f2.Frame.Width); // 50-1=49
  268. Assert.Equal (5, f2.Frame.Height);
  269. #if DEBUG
  270. Assert.Equal ($"Combine(View(Width,FrameView(f1){f1.Border.Frame})-Absolute(2))", v1.Width.ToString ());
  271. #else
  272. Assert.Equal ($"Combine(View(Width,FrameView(){f1.Border.Frame})-Absolute(2))", v1.Width.ToString ());
  273. #endif
  274. Assert.Equal ("Combine(Fill(Absolute(0))-Absolute(2))", v1.Height.ToString ());
  275. Assert.Equal (47, v1.Frame.Width); // 49-2=47
  276. Assert.Equal (89, v1.Frame.Height); // 98-5-2-2=89
  277. #if DEBUG
  278. Assert.Equal (
  279. $"Combine(View(Width,FrameView(f2){f2.Frame})-Absolute(2))",
  280. v2.Width.ToString ()
  281. #else
  282. Assert.Equal (
  283. $"Combine(View(Width,FrameView(){f2.Frame})-Absolute(2))",
  284. v2.Width.ToString ()
  285. #endif
  286. );
  287. #if DEBUG
  288. Assert.Equal ("Combine(Fill(Absolute(0))-Absolute(2))", v2.Height.ToString ());
  289. #else
  290. Assert.Equal ("Combine(Fill(Absolute(0)-Absolute(2))", v2.Height.ToString ());
  291. #endif
  292. Assert.Equal (47, v2.Frame.Width); // 49-2=47
  293. Assert.Equal (89, v2.Frame.Height); // 98-5-2-2=89
  294. Assert.Equal (9, v3.Frame.Width); // 98*10%=9
  295. Assert.Equal (9, v3.Frame.Height); // 98*10%=9
  296. Assert.Equal ("Absolute(50)", v4.Width.ToString ());
  297. Assert.Equal ("Absolute(50)", v4.Height.ToString ());
  298. Assert.Equal (50, v4.Frame.Width);
  299. Assert.Equal (50, v4.Frame.Height);
  300. #if DEBUG
  301. Assert.Equal ($"Combine(View(Width,Button(v1){v1.Frame})-View(Width,Button(v3){v3.Viewport}))", v5.Width.ToString ());
  302. #else
  303. Assert.Equal ($"Combine(View(Height,Button(){v1.Frame})-View(Height,Button(){v3.Viewport}))", v5.Height.ToString ( ));
  304. #endif
  305. Assert.Equal (38, v5.Frame.Width); // 47-9=38
  306. Assert.Equal (80, v5.Frame.Height); // 89-9=80
  307. Assert.Equal (9, v6.Frame.Width); // 47*20%=9
  308. Assert.Equal (18, v6.Frame.Height); // 89*20%=18
  309. w.Width = 200;
  310. Assert.True (t.LayoutNeeded);
  311. w.Height = 200;
  312. t.LayoutSubviews ();
  313. Assert.Equal ("Absolute(200)", w.Width.ToString ());
  314. Assert.Equal ("Absolute(200)", w.Height.ToString ());
  315. Assert.Equal (200, w.Frame.Width);
  316. Assert.Equal (200, w.Frame.Height);
  317. f1.Text = "Frame1";
  318. Assert.Equal (99, f1.Frame.Width); // 100-1=99
  319. Assert.Equal (5, f1.Frame.Height);
  320. f2.Text = "Frame2";
  321. Assert.Equal ("Fill(Absolute(0))", f2.Width.ToString ());
  322. Assert.Equal ("Absolute(5)", f2.Height.ToString ());
  323. Assert.Equal (99, f2.Frame.Width); // 100-1=99
  324. Assert.Equal (5, f2.Frame.Height);
  325. v1.Text = "Button1";
  326. #if DEBUG
  327. Assert.Equal ($"Combine(View(Width,FrameView(f1){f1.Frame})-Absolute(2))", v1.Width.ToString ());
  328. #else
  329. Assert.Equal ($"Combine(View(Width,FrameView(){f1.Frame})-Absolute(2))", v1.Width.ToString ());
  330. #endif
  331. Assert.Equal ("Combine(Fill(Absolute(0))-Absolute(2))", v1.Height.ToString ());
  332. Assert.Equal (97, v1.Frame.Width); // 99-2=97
  333. Assert.Equal (189, v1.Frame.Height); // 198-2-7=189
  334. v2.Text = "Button2";
  335. #if DEBUG
  336. Assert.Equal ($"Combine(View(Width,FrameView(f2){f2.Frame})-Absolute(2))", v2.Width.ToString ());
  337. #else
  338. Assert.Equal ($"Combine(View(Width,FrameView(){f2.Frame})-Absolute(2))", v2.Width.ToString ());
  339. #endif
  340. Assert.Equal ("Combine(Fill(Absolute(0))-Absolute(2))", v2.Height.ToString ());
  341. Assert.Equal (97, v2.Frame.Width); // 99-2=97
  342. Assert.Equal (189, v2.Frame.Height); // 198-2-7=189
  343. v3.Text = "Button3";
  344. // 198*10%=19 * Percent is related to the super-view if it isn't null otherwise the view width
  345. Assert.Equal (19, v3.Frame.Width);
  346. // 199*10%=19
  347. Assert.Equal (19, v3.Frame.Height);
  348. v4.Text = "Button4";
  349. v4.Width = Auto (DimAutoStyle.Text);
  350. v4.Height = Auto (DimAutoStyle.Text);
  351. Assert.Equal (Auto (DimAutoStyle.Text), v4.Width);
  352. Assert.Equal (Auto (DimAutoStyle.Text), v4.Height);
  353. Assert.Equal (11, v4.Frame.Width); // 11 is the text length and because is DimAbsolute
  354. Assert.Equal (1, v4.Frame.Height); // 1 because is DimAbsolute
  355. v5.Text = "Button5";
  356. #if DEBUG
  357. Assert.Equal ($"Combine(View(Width,Button(v1){v1.Frame})-View(Width,Button(v3){v3.Frame}))", v5.Width.ToString ());
  358. Assert.Equal ($"Combine(View(Height,Button(v1){v1.Frame})-View(Height,Button(v3){v3.Frame}))", v5.Height.ToString ());
  359. #else
  360. Assert.Equal ($"Combine(View(Width,Button(){v1.Frame})-View(Width,Button(){v3.Frame}))", v5.Width.ToString ());
  361. Assert.Equal ($"Combine(View(Height,Button(){v1.Frame})-View(Height,Button(){v3.Frame}))", v5.Height.ToString ());
  362. #endif
  363. Assert.Equal (78, v5.Frame.Width); // 97-9=78
  364. Assert.Equal (170, v5.Frame.Height); // 189-19=170
  365. v6.Text = "Button6";
  366. Assert.Equal (19, v6.Frame.Width); // 99*20%=19
  367. Assert.Equal (38, v6.Frame.Height); // 198-7*20=18
  368. };
  369. Application.Iteration += (s, a) => Application.RequestStop ();
  370. Application.Run (t);
  371. t.Dispose ();
  372. }
  373. // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
  374. // TODO: A new test that calls SetRelativeLayout directly is needed.
  375. [Fact]
  376. [TestRespondersDisposed]
  377. public void Referencing_SuperView_Does_Not_Throw ()
  378. {
  379. var super = new View { Width = 10, Height = 10, Text = "super" };
  380. var view = new View
  381. {
  382. Width = Width (super), // this is allowed
  383. Height = Height (super), // this is allowed
  384. Text = "view"
  385. };
  386. super.Add (view);
  387. super.BeginInit ();
  388. super.EndInit ();
  389. Exception exception = Record.Exception (super.LayoutSubviews);
  390. Assert.Null (exception);
  391. super.Dispose ();
  392. }
  393. [Fact]
  394. public void DimSized_Equals ()
  395. {
  396. var n1 = 0;
  397. var n2 = 0;
  398. Dim dim1 = Absolute (n1);
  399. Dim dim2 = Absolute (n2);
  400. Assert.Equal (dim1, dim2);
  401. n1 = n2 = 1;
  402. dim1 = Absolute (n1);
  403. dim2 = Absolute (n2);
  404. Assert.Equal (dim1, dim2);
  405. n1 = n2 = -1;
  406. dim1 = Absolute (n1);
  407. dim2 = Absolute (n2);
  408. Assert.Equal (dim1, dim2);
  409. n1 = 0;
  410. n2 = 1;
  411. dim1 = Absolute (n1);
  412. dim2 = Absolute (n2);
  413. Assert.NotEqual (dim1, dim2);
  414. }
  415. [Fact]
  416. public void DimSized_SetsValue ()
  417. {
  418. Dim dim = Absolute (0);
  419. Assert.Equal ("Absolute(0)", dim.ToString ());
  420. var testVal = 5;
  421. dim = Absolute (testVal);
  422. Assert.Equal ($"Absolute({testVal})", dim.ToString ());
  423. testVal = -1;
  424. dim = Absolute (testVal);
  425. Assert.Equal ($"Absolute({testVal})", dim.ToString ());
  426. }
  427. // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
  428. // TODO: A new test that calls SetRelativeLayout directly is needed.
  429. [Fact]
  430. [TestRespondersDisposed]
  431. public void SyperView_Referencing_SubView_Throws ()
  432. {
  433. var super = new View { Width = 10, Height = 10, Text = "super" };
  434. var view2 = new View { Width = 10, Height = 10, Text = "view2" };
  435. var view = new View
  436. {
  437. Width = Width (view2), // this is not allowed
  438. Height = Height (view2), // this is not allowed
  439. Text = "view"
  440. };
  441. view.Add (view2);
  442. super.Add (view);
  443. super.BeginInit ();
  444. super.EndInit ();
  445. Assert.Throws<InvalidOperationException> (super.LayoutSubviews);
  446. super.Dispose ();
  447. }
  448. // TODO: This actually a SetRelativeLayout/LayoutSubViews test and should be moved
  449. // TODO: A new test that calls SetRelativeLayout directly is needed.
  450. [Fact]
  451. [TestRespondersDisposed]
  452. public void Validation_Does_Not_Throw_If_NewValue_Is_DimAbsolute_And_OldValue_Is_Null ()
  453. {
  454. var t = new View { Width = 80, Height = 25, Text = "top" };
  455. var w = new Window
  456. {
  457. X = 1,
  458. Y = 2,
  459. Width = 4,
  460. Height = 5,
  461. Title = "w"
  462. };
  463. t.Add (w);
  464. t.LayoutSubviews ();
  465. Assert.Equal (3, w.Width = 3);
  466. Assert.Equal (4, w.Height = 4);
  467. t.Dispose ();
  468. }
  469. [Fact]
  470. [TestRespondersDisposed]
  471. public void DimWidth_Equals ()
  472. {
  473. var testRect1 = Rectangle.Empty;
  474. var view1 = new View { Frame = testRect1 };
  475. var testRect2 = Rectangle.Empty;
  476. var view2 = new View { Frame = testRect2 };
  477. Dim dim1 = Width (view1);
  478. Dim dim2 = Width (view1);
  479. // FIXED: Dim.Width should support Equals() and this should change to Equal.
  480. Assert.Equal (dim1, dim2);
  481. dim2 = Width (view2);
  482. Assert.NotEqual (dim1, dim2);
  483. testRect1 = new (0, 1, 2, 3);
  484. view1 = new() { Frame = testRect1 };
  485. testRect2 = new (0, 1, 2, 3);
  486. dim1 = Width (view1);
  487. dim2 = Width (view1);
  488. // FIXED: Dim.Width should support Equals() and this should change to Equal.
  489. Assert.Equal (dim1, dim2);
  490. testRect1 = new (0, -1, 2, 3);
  491. view1 = new() { Frame = testRect1 };
  492. testRect2 = new (0, -1, 2, 3);
  493. dim1 = Width (view1);
  494. dim2 = Width (view1);
  495. // FIXED: Dim.Width should support Equals() and this should change to Equal.
  496. Assert.Equal (dim1, dim2);
  497. testRect1 = new (0, -1, 2, 3);
  498. view1 = new() { Frame = testRect1 };
  499. testRect2 = Rectangle.Empty;
  500. view2 = new() { Frame = testRect2 };
  501. dim1 = Width (view1);
  502. dim2 = Width (view2);
  503. Assert.NotEqual (dim1, dim2);
  504. #if DEBUG_IDISPOSABLE
  505. // HACK: Force clean up of Responders to avoid having to Dispose all the Views created above.
  506. Responder.Instances.Clear ();
  507. Assert.Empty (Responder.Instances);
  508. #endif
  509. }
  510. [Fact]
  511. public void DimWidth_Set_To_Null_Throws ()
  512. {
  513. Dim dim = Width (null);
  514. Assert.Throws<NullReferenceException> (() => dim.ToString ());
  515. }
  516. [Fact]
  517. [TestRespondersDisposed]
  518. public void DimWidth_SetsValue ()
  519. {
  520. var testVal = Rectangle.Empty;
  521. var testValView = new View { Frame = testVal };
  522. Dim dim = Width (testValView);
  523. Assert.Equal ($"View(Width,View(){testVal})", dim.ToString ());
  524. testValView.Dispose ();
  525. testVal = new (1, 2, 3, 4);
  526. testValView = new() { Frame = testVal };
  527. dim = Width (testValView);
  528. Assert.Equal ($"View(Width,View(){testVal})", dim.ToString ());
  529. testValView.Dispose ();
  530. }
  531. }