CheckBoxTests.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. using System.ComponentModel;
  2. using Xunit.Abstractions;
  3. namespace Terminal.Gui.ViewsTests;
  4. public class CheckBoxTests
  5. {
  6. private readonly ITestOutputHelper _output;
  7. private static readonly Size _size25x1 = new (25, 1);
  8. public CheckBoxTests (ITestOutputHelper output) { _output = output; }
  9. // Test that Title and Text are the same
  10. [Fact]
  11. public void Text_Mirrors_Title ()
  12. {
  13. var view = new CheckBox ();
  14. view.Title = "Hello";
  15. Assert.Equal ("Hello", view.Title);
  16. Assert.Equal ($"Hello", view.TitleTextFormatter.Text);
  17. Assert.Equal ("Hello", view.Text);
  18. Assert.Equal ($"{CM.Glyphs.UnChecked} Hello", view.TextFormatter.Text);
  19. }
  20. [Fact]
  21. public void Title_Mirrors_Text ()
  22. {
  23. var view = new CheckBox ();
  24. view.Text = "Hello";
  25. Assert.Equal ("Hello", view.Text);
  26. Assert.Equal ($"{CM.Glyphs.UnChecked} Hello", view.TextFormatter.Text);
  27. Assert.Equal ("Hello", view.Title);
  28. Assert.Equal ($"Hello", view.TitleTextFormatter.Text);
  29. }
  30. [Fact]
  31. [AutoInitShutdown]
  32. public void AllowNullChecked_Get_Set ()
  33. {
  34. var checkBox = new CheckBox { Text = "Check this out 你" };
  35. Toplevel top = new ();
  36. top.Add (checkBox);
  37. Application.Begin (top);
  38. Assert.False (checkBox.Checked);
  39. Assert.True (checkBox.NewKeyDownEvent (Key.Space));
  40. Assert.True (checkBox.Checked);
  41. Assert.True (checkBox.NewMouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked }));
  42. Assert.False (checkBox.Checked);
  43. checkBox.AllowNullChecked = true;
  44. Assert.True (checkBox.NewKeyDownEvent (Key.Space));
  45. Assert.Null (checkBox.Checked);
  46. Application.Refresh ();
  47. TestHelpers.AssertDriverContentsWithFrameAre (
  48. @$"
  49. {CM.Glyphs.NullChecked} Check this out 你",
  50. _output
  51. );
  52. Assert.True (checkBox.NewMouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked }));
  53. Assert.True (checkBox.Checked);
  54. Assert.True (checkBox.NewKeyDownEvent (Key.Space));
  55. Assert.False (checkBox.Checked);
  56. Assert.True (checkBox.NewMouseEvent (new MouseEvent { X = 0, Y = 0, Flags = MouseFlags.Button1Clicked }));
  57. Assert.Null (checkBox.Checked);
  58. checkBox.AllowNullChecked = false;
  59. Assert.False (checkBox.Checked);
  60. }
  61. [Fact]
  62. [AutoInitShutdown]
  63. public void AutoSize_Stays_True_AnchorEnd_With_HotKeySpecifier ()
  64. {
  65. var checkBox = new CheckBox { Y = Pos.Center (), Text = "C_heck this out 你" };
  66. checkBox.X = Pos.AnchorEnd () - Pos.Function (() => checkBox.GetSizeNeededForTextWithoutHotKey ().Width);
  67. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
  68. win.Add (checkBox);
  69. var top = new Toplevel ();
  70. top.Add (win);
  71. Assert.True (checkBox.AutoSize);
  72. Application.Begin (top);
  73. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  74. var expected = @$"
  75. ┌┤Test Demo 你├──────────────┐
  76. │ │
  77. │ {CM.Glyphs.UnChecked} Check this out 你│
  78. │ │
  79. └────────────────────────────┘
  80. ";
  81. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  82. Assert.True (checkBox.AutoSize);
  83. checkBox.Text = "Check this out 你 changed";
  84. Assert.True (checkBox.AutoSize);
  85. Application.Refresh ();
  86. expected = @$"
  87. ┌┤Test Demo 你├──────────────┐
  88. │ │
  89. │ {CM.Glyphs.UnChecked} Check this out 你 changed│
  90. │ │
  91. └────────────────────────────┘
  92. ";
  93. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  94. }
  95. [Fact]
  96. [AutoInitShutdown]
  97. public void AutoSize_Stays_True_AnchorEnd_Without_HotKeySpecifier ()
  98. {
  99. var checkBox = new CheckBox { Y = Pos.Center (), Text = "Check this out 你" };
  100. checkBox.X = Pos.AnchorEnd () - Pos.Function (() => checkBox.GetSizeNeededForTextWithoutHotKey ().Width);
  101. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
  102. win.Add (checkBox);
  103. var top = new Toplevel ();
  104. top.Add (win);
  105. Assert.True (checkBox.AutoSize);
  106. Application.Begin (top);
  107. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  108. var expected = @$"
  109. ┌┤Test Demo 你├──────────────┐
  110. │ │
  111. │ {CM.Glyphs.UnChecked} Check this out 你│
  112. │ │
  113. └────────────────────────────┘
  114. ";
  115. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  116. Assert.True (checkBox.AutoSize);
  117. checkBox.Text = "Check this out 你 changed";
  118. Assert.True (checkBox.AutoSize);
  119. Application.Refresh ();
  120. expected = @$"
  121. ┌┤Test Demo 你├──────────────┐
  122. │ │
  123. │ {CM.Glyphs.UnChecked} Check this out 你 changed│
  124. │ │
  125. └────────────────────────────┘
  126. ";
  127. TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  128. }
  129. [Fact]
  130. [AutoInitShutdown]
  131. public void AutoSize_StaysVisible ()
  132. {
  133. var checkBox = new CheckBox { X = 1, Y = Pos.Center (), Text = "Check this out 你" };
  134. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
  135. win.Add (checkBox);
  136. var top = new Toplevel ();
  137. top.Add (win);
  138. Assert.False (checkBox.IsInitialized);
  139. RunState runstate = Application.Begin (top);
  140. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  141. Assert.True (checkBox.IsInitialized);
  142. Assert.Equal (new Rectangle (1, 1, 19, 1), checkBox.Frame);
  143. Assert.Equal ("Check this out 你", checkBox.Text);
  144. Assert.Equal ($"{CM.Glyphs.UnChecked} Check this out 你", checkBox.TextFormatter.Text);
  145. Assert.True (checkBox.AutoSize);
  146. Assert.Equal ("Absolute(19)", checkBox.Width.ToString ());
  147. checkBox.Checked = true;
  148. Assert.Equal ($"{CM.Glyphs.Checked} Check this out 你", checkBox.TextFormatter.Text);
  149. checkBox.AutoSize = false;
  150. // It isn't auto-size so the height is guaranteed by the SetMinWidthHeight
  151. checkBox.Text = "Check this out 你 changed";
  152. var firstIteration = false;
  153. Application.RunIteration (ref runstate, ref firstIteration);
  154. // BUGBUG - v2 - Autosize is busted; disabling tests for now
  155. Assert.Equal (new Rectangle (1, 1, 19, 1), checkBox.Frame);
  156. var expected = @"
  157. ┌┤Test Demo 你├──────────────┐
  158. │ │
  159. │ ☑ Check this out 你 │
  160. │ │
  161. └────────────────────────────┘";
  162. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  163. Assert.Equal (new Rectangle (0, 0, 30, 5), pos);
  164. checkBox.Width = 19;
  165. // It isn't auto-size so the height is guaranteed by the SetMinWidthHeight
  166. checkBox.Text = "Check this out 你 changed";
  167. Application.RunIteration (ref runstate, ref firstIteration);
  168. Assert.False (checkBox.AutoSize);
  169. Assert.Equal (new Rectangle (1, 1, 19, 1), checkBox.Frame);
  170. expected = @"
  171. ┌┤Test Demo 你├──────────────┐
  172. │ │
  173. │ ☑ Check this out 你 │
  174. │ │
  175. └────────────────────────────┘";
  176. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  177. Assert.Equal (new Rectangle (0, 0, 30, 5), pos);
  178. checkBox.AutoSize = true;
  179. Application.RunIteration (ref runstate, ref firstIteration);
  180. Assert.Equal (new Rectangle (1, 1, 27, 1), checkBox.Frame);
  181. expected = @"
  182. ┌┤Test Demo 你├──────────────┐
  183. │ │
  184. │ ☑ Check this out 你 changed│
  185. │ │
  186. └────────────────────────────┘";
  187. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  188. Assert.Equal (new Rectangle (0, 0, 30, 5), pos);
  189. }
  190. [Fact]
  191. public void Constructors_Defaults ()
  192. {
  193. var ckb = new CheckBox ();
  194. Assert.True (ckb.AutoSize);
  195. Assert.False (ckb.Checked);
  196. Assert.False (ckb.AllowNullChecked);
  197. Assert.Equal (string.Empty, ckb.Text);
  198. Assert.Equal ($"{CM.Glyphs.UnChecked} ", ckb.TextFormatter.Text);
  199. Assert.True (ckb.CanFocus);
  200. Assert.Equal (new Rectangle (0, 0, 2, 1), ckb.Frame);
  201. ckb = new CheckBox { Text = "Test", Checked = true };
  202. Assert.True (ckb.AutoSize);
  203. Assert.True (ckb.Checked);
  204. Assert.False (ckb.AllowNullChecked);
  205. Assert.Equal ("Test", ckb.Text);
  206. Assert.Equal ($"{CM.Glyphs.Checked} Test", ckb.TextFormatter.Text);
  207. Assert.True (ckb.CanFocus);
  208. Assert.Equal (new Rectangle (0, 0, 6, 1), ckb.Frame);
  209. ckb = new CheckBox { Text = "Test", X = 1, Y = 2 };
  210. Assert.True (ckb.AutoSize);
  211. Assert.False (ckb.Checked);
  212. Assert.False (ckb.AllowNullChecked);
  213. Assert.Equal ("Test", ckb.Text);
  214. Assert.Equal ($"{CM.Glyphs.UnChecked} Test", ckb.TextFormatter.Text);
  215. Assert.True (ckb.CanFocus);
  216. Assert.Equal (new Rectangle (1, 2, 6, 1), ckb.Frame);
  217. ckb = new CheckBox { Text = "Test", X = 3, Y = 4, Checked = true };
  218. Assert.True (ckb.AutoSize);
  219. Assert.True (ckb.Checked);
  220. Assert.False (ckb.AllowNullChecked);
  221. Assert.Equal ("Test", ckb.Text);
  222. Assert.Equal ($"{CM.Glyphs.Checked} Test", ckb.TextFormatter.Text);
  223. Assert.True (ckb.CanFocus);
  224. Assert.Equal (new Rectangle (3, 4, 6, 1), ckb.Frame);
  225. }
  226. [Fact]
  227. public void KeyBindings_Command ()
  228. {
  229. var toggled = false;
  230. var ckb = new CheckBox ();
  231. ckb.Toggled += (s, e) => toggled = true;
  232. Assert.False (ckb.Checked);
  233. Assert.False (toggled);
  234. Assert.Equal (Key.Empty, ckb.HotKey);
  235. ckb.Text = "_Test";
  236. Assert.Equal (Key.T, ckb.HotKey);
  237. Assert.True (ckb.NewKeyDownEvent (Key.T));
  238. Assert.True (ckb.Checked);
  239. Assert.True (toggled);
  240. ckb.Text = "T_est";
  241. toggled = false;
  242. Assert.Equal (Key.E, ckb.HotKey);
  243. Assert.True (ckb.NewKeyDownEvent (Key.E.WithAlt));
  244. Assert.True (toggled);
  245. Assert.False (ckb.Checked);
  246. toggled = false;
  247. Assert.Equal (Key.E, ckb.HotKey);
  248. Assert.True (ckb.NewKeyDownEvent (Key.E));
  249. Assert.True (toggled);
  250. Assert.True (ckb.Checked);
  251. toggled = false;
  252. Assert.True (ckb.NewKeyDownEvent (Key.Space));
  253. Assert.True (toggled);
  254. Assert.False (ckb.Checked);
  255. toggled = false;
  256. Assert.True (ckb.NewKeyDownEvent (Key.Space));
  257. Assert.True (toggled);
  258. Assert.True (ckb.Checked);
  259. toggled = false;
  260. Assert.False (ckb.NewKeyDownEvent (Key.Enter));
  261. Assert.False (toggled);
  262. Assert.True (ckb.Checked);
  263. }
  264. [Fact]
  265. public void Accept_Cancel_Event_OnAccept_Returns_True ()
  266. {
  267. var ckb = new CheckBox ();
  268. var acceptInvoked = false;
  269. ckb.Accept += ViewOnAccept;
  270. var ret = ckb.InvokeCommand (Command.Accept);
  271. Assert.True (ret);
  272. Assert.True (acceptInvoked);
  273. return;
  274. void ViewOnAccept (object sender, CancelEventArgs e)
  275. {
  276. acceptInvoked = true;
  277. e.Cancel = true;
  278. }
  279. }
  280. [Fact]
  281. [AutoInitShutdown]
  282. public void TextAlignment_Centered ()
  283. {
  284. var checkBox = new CheckBox
  285. {
  286. X = 1,
  287. Y = Pos.Center (),
  288. Text = "Check this out 你",
  289. TextAlignment = TextAlignment.Centered,
  290. AutoSize = false,
  291. Width = 25
  292. };
  293. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
  294. win.Add (checkBox);
  295. var top = new Toplevel ();
  296. top.Add (win);
  297. Application.Begin (top);
  298. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  299. Assert.Equal (TextAlignment.Centered, checkBox.TextAlignment);
  300. Assert.Equal (new (1, 1, 25, 1), checkBox.Frame);
  301. Assert.Equal (_size25x1, checkBox.TextFormatter.Size);
  302. Assert.False (checkBox.AutoSize);
  303. var expected = @$"
  304. ┌┤Test Demo 你├──────────────┐
  305. │ │
  306. │ {CM.Glyphs.UnChecked} Check this out 你 │
  307. │ │
  308. └────────────────────────────┘
  309. ";
  310. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  311. Assert.Equal (new (0, 0, 30, 5), pos);
  312. checkBox.Checked = true;
  313. Application.Refresh ();
  314. expected = @$"
  315. ┌┤Test Demo 你├──────────────┐
  316. │ │
  317. │ {CM.Glyphs.Checked} Check this out 你 │
  318. │ │
  319. └────────────────────────────┘
  320. ";
  321. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  322. Assert.Equal (new (0, 0, 30, 5), pos);
  323. }
  324. [Fact]
  325. [AutoInitShutdown]
  326. public void TextAlignment_Justified ()
  327. {
  328. var checkBox1 = new CheckBox
  329. {
  330. X = 1,
  331. Y = Pos.Center (),
  332. Text = "Check first out 你",
  333. TextAlignment = TextAlignment.Justified,
  334. AutoSize = false,
  335. Width = 25
  336. };
  337. var checkBox2 = new CheckBox
  338. {
  339. X = 1,
  340. Y = Pos.Bottom (checkBox1),
  341. Text = "Check second out 你",
  342. TextAlignment = TextAlignment.Justified,
  343. AutoSize = false,
  344. Width = 25
  345. };
  346. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
  347. win.Add (checkBox1, checkBox2);
  348. var top = new Toplevel ();
  349. top.Add (win);
  350. Application.Begin (top);
  351. ((FakeDriver)Application.Driver).SetBufferSize (30, 6);
  352. Assert.Equal (TextAlignment.Justified, checkBox1.TextAlignment);
  353. Assert.Equal (new (1, 1, 25, 1), checkBox1.Frame);
  354. Assert.Equal (_size25x1, checkBox1.TextFormatter.Size);
  355. Assert.Equal (TextAlignment.Justified, checkBox2.TextAlignment);
  356. Assert.Equal (new (1, 2, 25, 1), checkBox2.Frame);
  357. Assert.Equal (_size25x1, checkBox2.TextFormatter.Size);
  358. var expected = @$"
  359. ┌┤Test Demo 你├──────────────┐
  360. │ │
  361. │ {CM.Glyphs.UnChecked} Check first out 你 │
  362. │ {CM.Glyphs.UnChecked} Check second out 你 │
  363. │ │
  364. └────────────────────────────┘
  365. ";
  366. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  367. Assert.Equal (new (0, 0, 30, 6), pos);
  368. checkBox1.Checked = true;
  369. Assert.Equal (new (1, 1, 25, 1), checkBox1.Frame);
  370. Assert.Equal (_size25x1, checkBox1.TextFormatter.Size);
  371. checkBox2.Checked = true;
  372. Assert.Equal (new (1, 2, 25, 1), checkBox2.Frame);
  373. Assert.Equal (_size25x1, checkBox2.TextFormatter.Size);
  374. Application.Refresh ();
  375. expected = @$"
  376. ┌┤Test Demo 你├──────────────┐
  377. │ │
  378. │ {CM.Glyphs.Checked} Check first out 你 │
  379. │ {CM.Glyphs.Checked} Check second out 你 │
  380. │ │
  381. └────────────────────────────┘
  382. ";
  383. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  384. Assert.Equal (new (0, 0, 30, 6), pos);
  385. }
  386. [Fact]
  387. [AutoInitShutdown]
  388. public void TextAlignment_Left ()
  389. {
  390. var checkBox = new CheckBox
  391. {
  392. X = 1,
  393. Y = Pos.Center (),
  394. Text = "Check this out 你",
  395. AutoSize = false,
  396. Width = 25
  397. };
  398. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
  399. win.Add (checkBox);
  400. var top = new Toplevel ();
  401. top.Add (win);
  402. Application.Begin (top);
  403. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  404. Assert.Equal (TextAlignment.Left, checkBox.TextAlignment);
  405. Assert.Equal (new (1, 1, 25, 1), checkBox.Frame);
  406. Assert.Equal (_size25x1, checkBox.TextFormatter.Size);
  407. var expected = @$"
  408. ┌┤Test Demo 你├──────────────┐
  409. │ │
  410. │ {CM.Glyphs.UnChecked} Check this out 你 │
  411. │ │
  412. └────────────────────────────┘
  413. ";
  414. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  415. Assert.Equal (new (0, 0, 30, 5), pos);
  416. checkBox.Checked = true;
  417. Application.Refresh ();
  418. expected = @$"
  419. ┌┤Test Demo 你├──────────────┐
  420. │ │
  421. │ {CM.Glyphs.Checked} Check this out 你 │
  422. │ │
  423. └────────────────────────────┘
  424. ";
  425. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  426. Assert.Equal (new (0, 0, 30, 5), pos);
  427. }
  428. [Fact]
  429. [AutoInitShutdown]
  430. public void TextAlignment_Right ()
  431. {
  432. var checkBox = new CheckBox
  433. {
  434. X = 1,
  435. Y = Pos.Center (),
  436. Text = "Check this out 你",
  437. TextAlignment = TextAlignment.Right,
  438. AutoSize = false,
  439. Width = 25
  440. };
  441. var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
  442. win.Add (checkBox);
  443. var top = new Toplevel ();
  444. top.Add (win);
  445. Application.Begin (top);
  446. ((FakeDriver)Application.Driver).SetBufferSize (30, 5);
  447. Assert.Equal (TextAlignment.Right, checkBox.TextAlignment);
  448. Assert.Equal (new (1, 1, 25, 1), checkBox.Frame);
  449. Assert.Equal (_size25x1, checkBox.TextFormatter.Size);
  450. Assert.False (checkBox.AutoSize);
  451. var expected = @$"
  452. ┌┤Test Demo 你├──────────────┐
  453. │ │
  454. │ Check this out 你 {CM.Glyphs.UnChecked} │
  455. │ │
  456. └────────────────────────────┘
  457. ";
  458. Rectangle pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  459. Assert.Equal (new (0, 0, 30, 5), pos);
  460. checkBox.Checked = true;
  461. Application.Refresh ();
  462. expected = @$"
  463. ┌┤Test Demo 你├──────────────┐
  464. │ │
  465. │ Check this out 你 {CM.Glyphs.Checked} │
  466. │ │
  467. └────────────────────────────┘
  468. ";
  469. pos = TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
  470. Assert.Equal (new (0, 0, 30, 5), pos);
  471. }
  472. [Fact]
  473. public void HotKey_Command_Fires_Accept ()
  474. {
  475. var cb = new CheckBox ();
  476. var accepted = false;
  477. cb.Accept += CheckBoxOnAccept;
  478. cb.InvokeCommand (Command.HotKey);
  479. Assert.True (accepted);
  480. return;
  481. void CheckBoxOnAccept (object sender, CancelEventArgs e) { accepted = true; }
  482. }
  483. [Theory]
  484. [InlineData (true)]
  485. [InlineData (false)]
  486. [InlineData (null)]
  487. public void Toggled_Cancel_Event_Prevents_Toggle (bool? initialState)
  488. {
  489. var ckb = new CheckBox () { AllowNullChecked = true };
  490. var checkedInvoked = false;
  491. ckb.Toggled += CheckBoxToggled;
  492. ckb.Checked = initialState;
  493. Assert.Equal(initialState, ckb.Checked);
  494. var ret = ckb.OnToggled ();
  495. Assert.True (ret);
  496. Assert.True (checkedInvoked);
  497. Assert.Equal (initialState, ckb.Checked);
  498. return;
  499. void CheckBoxToggled (object sender, CancelEventArgs e)
  500. {
  501. checkedInvoked = true;
  502. e.Cancel = true;
  503. }
  504. }
  505. }