AutoCompleteBoxTests.cs 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Linq;
  6. using Avalonia.Controls.Primitives;
  7. using Avalonia.Controls.Presenters;
  8. using Avalonia.Controls.Templates;
  9. using Avalonia.Data;
  10. using Avalonia.Markup.Data;
  11. using Avalonia.Platform;
  12. using Avalonia.Threading;
  13. using Avalonia.UnitTests;
  14. using Moq;
  15. using Xunit;
  16. using System.Collections.ObjectModel;
  17. using System.Reactive.Linq;
  18. using System.Reactive.Subjects;
  19. namespace Avalonia.Controls.UnitTests
  20. {
  21. public class AutoCompleteBoxTests
  22. {
  23. [Fact]
  24. public void Search_Filters()
  25. {
  26. Assert.True(GetFilter(AutoCompleteFilterMode.Contains)("am", "name"));
  27. Assert.True(GetFilter(AutoCompleteFilterMode.Contains)("AME", "name"));
  28. Assert.False(GetFilter(AutoCompleteFilterMode.Contains)("hello", "name"));
  29. Assert.True(GetFilter(AutoCompleteFilterMode.ContainsCaseSensitive)("na", "name"));
  30. Assert.False(GetFilter(AutoCompleteFilterMode.ContainsCaseSensitive)("AME", "name"));
  31. Assert.False(GetFilter(AutoCompleteFilterMode.ContainsCaseSensitive)("hello", "name"));
  32. Assert.Null(GetFilter(AutoCompleteFilterMode.Custom));
  33. Assert.Null(GetFilter(AutoCompleteFilterMode.None));
  34. Assert.True(GetFilter(AutoCompleteFilterMode.Equals)("na", "na"));
  35. Assert.True(GetFilter(AutoCompleteFilterMode.Equals)("na", "NA"));
  36. Assert.False(GetFilter(AutoCompleteFilterMode.Equals)("hello", "name"));
  37. Assert.True(GetFilter(AutoCompleteFilterMode.EqualsCaseSensitive)("na", "na"));
  38. Assert.False(GetFilter(AutoCompleteFilterMode.EqualsCaseSensitive)("na", "NA"));
  39. Assert.False(GetFilter(AutoCompleteFilterMode.EqualsCaseSensitive)("hello", "name"));
  40. Assert.True(GetFilter(AutoCompleteFilterMode.StartsWith)("na", "name"));
  41. Assert.True(GetFilter(AutoCompleteFilterMode.StartsWith)("NAM", "name"));
  42. Assert.False(GetFilter(AutoCompleteFilterMode.StartsWith)("hello", "name"));
  43. Assert.True(GetFilter(AutoCompleteFilterMode.StartsWithCaseSensitive)("na", "name"));
  44. Assert.False(GetFilter(AutoCompleteFilterMode.StartsWithCaseSensitive)("NAM", "name"));
  45. Assert.False(GetFilter(AutoCompleteFilterMode.StartsWithCaseSensitive)("hello", "name"));
  46. }
  47. [Fact]
  48. public void Ordinal_Search_Filters()
  49. {
  50. Assert.True(GetFilter(AutoCompleteFilterMode.ContainsOrdinal)("am", "name"));
  51. Assert.True(GetFilter(AutoCompleteFilterMode.ContainsOrdinal)("AME", "name"));
  52. Assert.False(GetFilter(AutoCompleteFilterMode.ContainsOrdinal)("hello", "name"));
  53. Assert.True(GetFilter(AutoCompleteFilterMode.ContainsOrdinalCaseSensitive)("na", "name"));
  54. Assert.False(GetFilter(AutoCompleteFilterMode.ContainsOrdinalCaseSensitive)("AME", "name"));
  55. Assert.False(GetFilter(AutoCompleteFilterMode.ContainsOrdinalCaseSensitive)("hello", "name"));
  56. Assert.True(GetFilter(AutoCompleteFilterMode.EqualsOrdinal)("na", "na"));
  57. Assert.True(GetFilter(AutoCompleteFilterMode.EqualsOrdinal)("na", "NA"));
  58. Assert.False(GetFilter(AutoCompleteFilterMode.EqualsOrdinal)("hello", "name"));
  59. Assert.True(GetFilter(AutoCompleteFilterMode.EqualsOrdinalCaseSensitive)("na", "na"));
  60. Assert.False(GetFilter(AutoCompleteFilterMode.EqualsOrdinalCaseSensitive)("na", "NA"));
  61. Assert.False(GetFilter(AutoCompleteFilterMode.EqualsOrdinalCaseSensitive)("hello", "name"));
  62. Assert.True(GetFilter(AutoCompleteFilterMode.StartsWithOrdinal)("na", "name"));
  63. Assert.True(GetFilter(AutoCompleteFilterMode.StartsWithOrdinal)("NAM", "name"));
  64. Assert.False(GetFilter(AutoCompleteFilterMode.StartsWithOrdinal)("hello", "name"));
  65. Assert.True(GetFilter(AutoCompleteFilterMode.StartsWithOrdinalCaseSensitive)("na", "name"));
  66. Assert.False(GetFilter(AutoCompleteFilterMode.StartsWithOrdinalCaseSensitive)("NAM", "name"));
  67. Assert.False(GetFilter(AutoCompleteFilterMode.StartsWithOrdinalCaseSensitive)("hello", "name"));
  68. }
  69. [Fact]
  70. public void Fires_DropDown_Events()
  71. {
  72. RunTest((control, textbox) =>
  73. {
  74. bool openEvent = false;
  75. bool closeEvent = false;
  76. control.DropDownOpened += (s, e) => openEvent = true;
  77. control.DropDownClosed += (s, e) => closeEvent = true;
  78. control.Items = CreateSimpleStringArray();
  79. textbox.Text = "a";
  80. Dispatcher.UIThread.RunJobs();
  81. Assert.True(control.SearchText == "a");
  82. Assert.True(control.IsDropDownOpen);
  83. Assert.True(openEvent);
  84. textbox.Text = String.Empty;
  85. Dispatcher.UIThread.RunJobs();
  86. Assert.True(control.SearchText == String.Empty);
  87. Assert.False(control.IsDropDownOpen);
  88. Assert.True(closeEvent);
  89. });
  90. }
  91. [Fact]
  92. public void Custom_FilterMode_Without_ItemFilter_Setting_Throws_Exception()
  93. {
  94. RunTest((control, textbox) =>
  95. {
  96. control.FilterMode = AutoCompleteFilterMode.Custom;
  97. Assert.Throws<Exception>(() => { control.Text = "a"; });
  98. });
  99. }
  100. [Fact]
  101. public void Text_Completion_Via_Text_Property()
  102. {
  103. RunTest((control, textbox) =>
  104. {
  105. control.IsTextCompletionEnabled = true;
  106. Assert.Equal(String.Empty, control.Text);
  107. control.Text = "close";
  108. Assert.NotNull(control.SelectedItem);
  109. });
  110. }
  111. [Fact]
  112. public void Text_Completion_Selects_Text()
  113. {
  114. RunTest((control, textbox) =>
  115. {
  116. control.IsTextCompletionEnabled = true;
  117. textbox.Text = "ac";
  118. textbox.SelectionEnd = textbox.SelectionStart = 2;
  119. Dispatcher.UIThread.RunJobs();
  120. Assert.True(control.IsDropDownOpen);
  121. Assert.True(Math.Abs(textbox.SelectionEnd - textbox.SelectionStart) > 2);
  122. });
  123. }
  124. [Fact]
  125. public void TextChanged_Event_Fires()
  126. {
  127. RunTest((control, textbox) =>
  128. {
  129. bool textChanged = false;
  130. control.TextChanged += (s, e) => textChanged = true;
  131. textbox.Text = "a";
  132. Dispatcher.UIThread.RunJobs();
  133. Assert.True(textChanged);
  134. textChanged = false;
  135. control.Text = "conversati";
  136. Dispatcher.UIThread.RunJobs();
  137. Assert.True(textChanged);
  138. textChanged = false;
  139. control.Text = null;
  140. Dispatcher.UIThread.RunJobs();
  141. Assert.True(textChanged);
  142. });
  143. }
  144. [Fact]
  145. public void MinimumPrefixLength_Works()
  146. {
  147. RunTest((control, textbox) =>
  148. {
  149. textbox.Text = "a";
  150. Dispatcher.UIThread.RunJobs();
  151. Assert.True(control.IsDropDownOpen);
  152. textbox.Text = String.Empty;
  153. Dispatcher.UIThread.RunJobs();
  154. Assert.False(control.IsDropDownOpen);
  155. control.MinimumPrefixLength = 3;
  156. textbox.Text = "a";
  157. Dispatcher.UIThread.RunJobs();
  158. Assert.False(control.IsDropDownOpen);
  159. textbox.Text = "acc";
  160. Dispatcher.UIThread.RunJobs();
  161. Assert.True(control.IsDropDownOpen);
  162. });
  163. }
  164. [Fact]
  165. public void Can_Cancel_DropDown_Opening()
  166. {
  167. RunTest((control, textbox) =>
  168. {
  169. control.DropDownOpening += (s, e) => e.Cancel = true;
  170. textbox.Text = "a";
  171. Dispatcher.UIThread.RunJobs();
  172. Assert.False(control.IsDropDownOpen);
  173. });
  174. }
  175. [Fact]
  176. public void Can_Cancel_DropDown_Closing()
  177. {
  178. RunTest((control, textbox) =>
  179. {
  180. control.DropDownClosing += (s, e) => e.Cancel = true;
  181. textbox.Text = "a";
  182. Dispatcher.UIThread.RunJobs();
  183. Assert.True(control.IsDropDownOpen);
  184. control.IsDropDownOpen = false;
  185. Assert.True(control.IsDropDownOpen);
  186. });
  187. }
  188. [Fact]
  189. public void Can_Cancel_Population()
  190. {
  191. RunTest((control, textbox) =>
  192. {
  193. bool populating = false;
  194. bool populated = false;
  195. control.FilterMode = AutoCompleteFilterMode.None;
  196. control.Populating += (s, e) =>
  197. {
  198. e.Cancel = true;
  199. populating = true;
  200. };
  201. control.Populated += (s, e) => populated = true;
  202. textbox.Text = "accounti";
  203. Dispatcher.UIThread.RunJobs();
  204. Assert.True(populating);
  205. Assert.False(populated);
  206. });
  207. }
  208. [Fact]
  209. public void Custom_Population_Supported()
  210. {
  211. RunTest((control, textbox) =>
  212. {
  213. string custom = "Custom!";
  214. string search = "accounti";
  215. bool populated = false;
  216. bool populatedOk = false;
  217. control.FilterMode = AutoCompleteFilterMode.None;
  218. control.Populating += (s, e) =>
  219. {
  220. control.Items = new string[] { custom };
  221. Assert.Equal(search, e.Parameter);
  222. };
  223. control.Populated += (s, e) =>
  224. {
  225. populated = true;
  226. ReadOnlyCollection<object> collection = e.Data as ReadOnlyCollection<object>;
  227. populatedOk = collection != null && collection.Count == 1;
  228. };
  229. textbox.Text = search;
  230. Dispatcher.UIThread.RunJobs();
  231. Assert.True(populated);
  232. Assert.True(populatedOk);
  233. });
  234. }
  235. [Fact]
  236. public void Text_Completion()
  237. {
  238. RunTest((control, textbox) =>
  239. {
  240. control.IsTextCompletionEnabled = true;
  241. textbox.Text = "accounti";
  242. textbox.SelectionStart = textbox.SelectionEnd = textbox.Text.Length;
  243. Dispatcher.UIThread.RunJobs();
  244. Assert.Equal("accounti", control.SearchText);
  245. Assert.Equal("accounting", textbox.Text);
  246. });
  247. }
  248. [Fact]
  249. public void String_Search()
  250. {
  251. RunTest((control, textbox) =>
  252. {
  253. textbox.Text = "a";
  254. Dispatcher.UIThread.RunJobs();
  255. Assert.Equal(textbox.Text, control.Text);
  256. textbox.Text = "acc";
  257. Dispatcher.UIThread.RunJobs();
  258. Assert.Equal(textbox.Text, control.Text);
  259. textbox.Text = "a";
  260. Dispatcher.UIThread.RunJobs();
  261. Assert.Equal(textbox.Text, control.Text);
  262. textbox.Text = "";
  263. Dispatcher.UIThread.RunJobs();
  264. Assert.Equal(textbox.Text, control.Text);
  265. textbox.Text = "cook";
  266. Dispatcher.UIThread.RunJobs();
  267. Assert.Equal(textbox.Text, control.Text);
  268. textbox.Text = "accept";
  269. Dispatcher.UIThread.RunJobs();
  270. Assert.Equal(textbox.Text, control.Text);
  271. textbox.Text = "cook";
  272. Dispatcher.UIThread.RunJobs();
  273. Assert.Equal(textbox.Text, control.Text);
  274. });
  275. }
  276. [Fact]
  277. public void Item_Search()
  278. {
  279. RunTest((control, textbox) =>
  280. {
  281. control.FilterMode = AutoCompleteFilterMode.Custom;
  282. control.ItemFilter = (search, item) =>
  283. {
  284. string s = item as string;
  285. return s == null ? false : true;
  286. };
  287. // Just set to null briefly to exercise that code path
  288. AutoCompleteFilterPredicate<object> filter = control.ItemFilter;
  289. Assert.NotNull(filter);
  290. control.ItemFilter = null;
  291. Assert.Null(control.ItemFilter);
  292. control.ItemFilter = filter;
  293. Assert.NotNull(control.ItemFilter);
  294. textbox.Text = "a";
  295. Dispatcher.UIThread.RunJobs();
  296. Assert.Equal(textbox.Text, control.Text);
  297. textbox.Text = "acc";
  298. Dispatcher.UIThread.RunJobs();
  299. Assert.Equal(textbox.Text, control.Text);
  300. textbox.Text = "a";
  301. Dispatcher.UIThread.RunJobs();
  302. Assert.Equal(textbox.Text, control.Text);
  303. textbox.Text = "";
  304. Dispatcher.UIThread.RunJobs();
  305. Assert.Equal(textbox.Text, control.Text);
  306. textbox.Text = "cook";
  307. Dispatcher.UIThread.RunJobs();
  308. Assert.Equal(textbox.Text, control.Text);
  309. textbox.Text = "accept";
  310. Dispatcher.UIThread.RunJobs();
  311. Assert.Equal(textbox.Text, control.Text);
  312. textbox.Text = "cook";
  313. Dispatcher.UIThread.RunJobs();
  314. Assert.Equal(textbox.Text, control.Text);
  315. });
  316. }
  317. [Fact]
  318. public void Custom_TextSelector()
  319. {
  320. RunTest((control, textbox) =>
  321. {
  322. object selectedItem = control.Items.Cast<object>().First();
  323. string input = "42";
  324. control.TextSelector = (text, item) => text + item;
  325. Assert.Equal(control.TextSelector("4", "2"), "42");
  326. control.Text = input;
  327. control.SelectedItem = selectedItem;
  328. Assert.Equal(control.Text, control.TextSelector(input, selectedItem.ToString()));
  329. });
  330. }
  331. [Fact]
  332. public void Custom_ItemSelector()
  333. {
  334. RunTest((control, textbox) =>
  335. {
  336. object selectedItem = control.Items.Cast<object>().First();
  337. string input = "42";
  338. control.ItemSelector = (text, item) => text + item;
  339. Assert.Equal(control.ItemSelector("4", 2), "42");
  340. control.Text = input;
  341. control.SelectedItem = selectedItem;
  342. Assert.Equal(control.Text, control.ItemSelector(input, selectedItem));
  343. });
  344. }
  345. [Fact]
  346. public void Text_Validation()
  347. {
  348. RunTest((control, textbox) =>
  349. {
  350. var exception = new InvalidCastException("failed validation");
  351. var textObservable = new BehaviorSubject<BindingNotification>(new BindingNotification(exception, BindingErrorType.DataValidationError));
  352. control.Bind(AutoCompleteBox.TextProperty, textObservable);
  353. Dispatcher.UIThread.RunJobs();
  354. Assert.Equal(DataValidationErrors.GetHasErrors(control), true);
  355. Assert.Equal(DataValidationErrors.GetErrors(control).SequenceEqual(new[] { exception }), true);
  356. });
  357. }
  358. [Fact]
  359. public void SelectedItem_Validation()
  360. {
  361. RunTest((control, textbox) =>
  362. {
  363. var exception = new InvalidCastException("failed validation");
  364. var itemObservable = new BehaviorSubject<BindingNotification>(new BindingNotification(exception, BindingErrorType.DataValidationError));
  365. control.Bind(AutoCompleteBox.SelectedItemProperty, itemObservable);
  366. Dispatcher.UIThread.RunJobs();
  367. Assert.Equal(DataValidationErrors.GetHasErrors(control), true);
  368. Assert.Equal(DataValidationErrors.GetErrors(control).SequenceEqual(new[] { exception }), true);
  369. });
  370. }
  371. /// <summary>
  372. /// Retrieves a defined predicate filter through a new AutoCompleteBox
  373. /// control instance.
  374. /// </summary>
  375. /// <param name="mode">The FilterMode of interest.</param>
  376. /// <returns>Returns the predicate instance.</returns>
  377. private static AutoCompleteFilterPredicate<string> GetFilter(AutoCompleteFilterMode mode)
  378. {
  379. return new AutoCompleteBox { FilterMode = mode }
  380. .TextFilter;
  381. }
  382. /// <summary>
  383. /// Creates a large list of strings for AutoCompleteBox testing.
  384. /// </summary>
  385. /// <returns>Returns a new List of string values.</returns>
  386. private static IList<string> CreateSimpleStringArray()
  387. {
  388. return new List<string>
  389. {
  390. "a",
  391. "abide",
  392. "able",
  393. "about",
  394. "above",
  395. "absence",
  396. "absurd",
  397. "accept",
  398. "acceptance",
  399. "accepted",
  400. "accepting",
  401. "access",
  402. "accessed",
  403. "accessible",
  404. "accident",
  405. "accidentally",
  406. "accordance",
  407. "account",
  408. "accounting",
  409. "accounts",
  410. "accusation",
  411. "accustomed",
  412. "ache",
  413. "across",
  414. "act",
  415. "active",
  416. "actual",
  417. "actually",
  418. "ada",
  419. "added",
  420. "adding",
  421. "addition",
  422. "additional",
  423. "additions",
  424. "address",
  425. "addressed",
  426. "addresses",
  427. "addressing",
  428. "adjourn",
  429. "adoption",
  430. "advance",
  431. "advantage",
  432. "adventures",
  433. "advice",
  434. "advisable",
  435. "advise",
  436. "affair",
  437. "affectionately",
  438. "afford",
  439. "afore",
  440. "afraid",
  441. "after",
  442. "afterwards",
  443. "again",
  444. "against",
  445. "age",
  446. "aged",
  447. "agent",
  448. "ago",
  449. "agony",
  450. "agree",
  451. "agreed",
  452. "agreement",
  453. "ah",
  454. "ahem",
  455. "air",
  456. "airs",
  457. "ak",
  458. "alarm",
  459. "alarmed",
  460. "alas",
  461. "alice",
  462. "alive",
  463. "all",
  464. "allow",
  465. "almost",
  466. "alone",
  467. "along",
  468. "aloud",
  469. "already",
  470. "also",
  471. "alteration",
  472. "altered",
  473. "alternate",
  474. "alternately",
  475. "altogether",
  476. "always",
  477. "am",
  478. "ambition",
  479. "among",
  480. "an",
  481. "ancient",
  482. "and",
  483. "anger",
  484. "angrily",
  485. "angry",
  486. "animal",
  487. "animals",
  488. "ann",
  489. "annoy",
  490. "annoyed",
  491. "another",
  492. "answer",
  493. "answered",
  494. "answers",
  495. "antipathies",
  496. "anxious",
  497. "anxiously",
  498. "any",
  499. "anyone",
  500. "anything",
  501. "anywhere",
  502. "appealed",
  503. "appear",
  504. "appearance",
  505. "appeared",
  506. "appearing",
  507. "appears",
  508. "applause",
  509. "apple",
  510. "apples",
  511. "applicable",
  512. "apply",
  513. "approach",
  514. "arch",
  515. "archbishop",
  516. "arches",
  517. "archive",
  518. "are",
  519. "argue",
  520. "argued",
  521. "argument",
  522. "arguments",
  523. "arise",
  524. "arithmetic",
  525. "arm",
  526. "arms",
  527. "around",
  528. "arranged",
  529. "array",
  530. "arrived",
  531. "arrow",
  532. "arrum",
  533. "as",
  534. "ascii",
  535. "ashamed",
  536. "ask",
  537. "askance",
  538. "asked",
  539. "asking",
  540. "asleep",
  541. "assembled",
  542. "assistance",
  543. "associated",
  544. "at",
  545. "ate",
  546. "atheling",
  547. "atom",
  548. "attached",
  549. "attempt",
  550. "attempted",
  551. "attempts",
  552. "attended",
  553. "attending",
  554. "attends",
  555. "audibly",
  556. "australia",
  557. "author",
  558. "authority",
  559. "available",
  560. "avoid",
  561. "away",
  562. "awfully",
  563. "axes",
  564. "axis",
  565. "b",
  566. "baby",
  567. "back",
  568. "backs",
  569. "bad",
  570. "bag",
  571. "baked",
  572. "balanced",
  573. "bank",
  574. "banks",
  575. "banquet",
  576. "bark",
  577. "barking",
  578. "barley",
  579. "barrowful",
  580. "based",
  581. "bat",
  582. "bathing",
  583. "bats",
  584. "bawled",
  585. "be",
  586. "beak",
  587. "bear",
  588. "beast",
  589. "beasts",
  590. "beat",
  591. "beating",
  592. "beau",
  593. "beauti",
  594. "beautiful",
  595. "beautifully",
  596. "beautify",
  597. "became",
  598. "because",
  599. "become",
  600. "becoming",
  601. "bed",
  602. "beds",
  603. "bee",
  604. "been",
  605. "before",
  606. "beg",
  607. "began",
  608. "begged",
  609. "begin",
  610. "beginning",
  611. "begins",
  612. "begun",
  613. "behead",
  614. "beheaded",
  615. "beheading",
  616. "behind",
  617. "being",
  618. "believe",
  619. "believed",
  620. "bells",
  621. "belong",
  622. "belongs",
  623. "beloved",
  624. "below",
  625. "belt",
  626. "bend",
  627. "bent",
  628. "besides",
  629. "best",
  630. "better",
  631. "between",
  632. "bill",
  633. "binary",
  634. "bird",
  635. "birds",
  636. "birthday",
  637. "bit",
  638. "bite",
  639. "bitter",
  640. "blacking",
  641. "blades",
  642. "blame",
  643. "blasts",
  644. "bleeds",
  645. "blew",
  646. "blow",
  647. "blown",
  648. "blows",
  649. "body",
  650. "boldly",
  651. "bone",
  652. "bones",
  653. "book",
  654. "books",
  655. "boon",
  656. "boots",
  657. "bore",
  658. "both",
  659. "bother",
  660. "bottle",
  661. "bottom",
  662. "bough",
  663. "bound",
  664. "bowed",
  665. "bowing",
  666. "box",
  667. "boxed",
  668. "boy",
  669. "brain",
  670. "branch",
  671. "branches",
  672. "brandy",
  673. "brass",
  674. "brave",
  675. "breach",
  676. "bread",
  677. "break",
  678. "breath",
  679. "breathe",
  680. "breeze",
  681. "bright",
  682. "brightened",
  683. "bring",
  684. "bringing",
  685. "bristling",
  686. "broke",
  687. "broken",
  688. "brother",
  689. "brought",
  690. "brown",
  691. "brush",
  692. "brushing",
  693. "burn",
  694. "burning",
  695. "burnt",
  696. "burst",
  697. "bursting",
  698. "busily",
  699. "business",
  700. "business@pglaf",
  701. "busy",
  702. "but",
  703. "butter",
  704. "buttercup",
  705. "buttered",
  706. "butterfly",
  707. "buttons",
  708. "by",
  709. "bye",
  710. "c",
  711. "cackled",
  712. "cake",
  713. "cakes",
  714. "calculate",
  715. "calculated",
  716. "call",
  717. "called",
  718. "calling",
  719. "calmly",
  720. "came",
  721. "camomile",
  722. "can",
  723. "canary",
  724. "candle",
  725. "cannot",
  726. "canterbury",
  727. "canvas",
  728. "capering",
  729. "capital",
  730. "card",
  731. "cardboard",
  732. "cards",
  733. "care",
  734. "carefully",
  735. "cares",
  736. "carried",
  737. "carrier",
  738. "carroll",
  739. "carry",
  740. "carrying",
  741. "cart",
  742. "cartwheels",
  743. "case",
  744. "cat",
  745. "catch",
  746. "catching",
  747. "caterpillar",
  748. "cats",
  749. "cattle",
  750. "caucus",
  751. "caught",
  752. "cauldron",
  753. "cause",
  754. "caused",
  755. "cautiously",
  756. "cease",
  757. "ceiling",
  758. "centre",
  759. "certain",
  760. "certainly",
  761. "chain",
  762. "chains",
  763. "chair",
  764. "chance",
  765. "chanced",
  766. "change",
  767. "changed",
  768. "changes",
  769. "changing",
  770. "chapter",
  771. "character",
  772. "charge",
  773. "charges",
  774. "charitable",
  775. "charities",
  776. "chatte",
  777. "cheap",
  778. "cheated",
  779. "check",
  780. "checked",
  781. "checks",
  782. "cheeks",
  783. "cheered",
  784. "cheerfully",
  785. "cherry",
  786. "cheshire",
  787. "chief",
  788. "child",
  789. "childhood",
  790. "children",
  791. "chimney",
  792. "chimneys",
  793. "chin",
  794. "choice",
  795. "choke",
  796. "choked",
  797. "choking",
  798. "choose",
  799. "choosing",
  800. "chop",
  801. "chorus",
  802. "chose",
  803. "christmas",
  804. "chrysalis",
  805. "chuckled",
  806. "circle",
  807. "circumstances",
  808. "city",
  809. "civil",
  810. "claim",
  811. "clamour",
  812. "clapping",
  813. "clasped",
  814. "classics",
  815. "claws",
  816. "clean",
  817. "clear",
  818. "cleared",
  819. "clearer",
  820. "clearly",
  821. "clever",
  822. "climb",
  823. "clinging",
  824. "clock",
  825. "close",
  826. "closed",
  827. "closely",
  828. "closer",
  829. "clubs",
  830. "coast",
  831. "coaxing",
  832. "codes",
  833. "coils",
  834. "cold",
  835. "collar",
  836. "collected",
  837. "collection",
  838. "come",
  839. "comes",
  840. "comfits",
  841. "comfort",
  842. "comfortable",
  843. "comfortably",
  844. "coming",
  845. "commercial",
  846. "committed",
  847. "common",
  848. "commotion",
  849. "company",
  850. "compilation",
  851. "complained",
  852. "complaining",
  853. "completely",
  854. "compliance",
  855. "comply",
  856. "complying",
  857. "compressed",
  858. "computer",
  859. "computers",
  860. "concept",
  861. "concerning",
  862. "concert",
  863. "concluded",
  864. "conclusion",
  865. "condemn",
  866. "conduct",
  867. "confirmation",
  868. "confirmed",
  869. "confused",
  870. "confusing",
  871. "confusion",
  872. "conger",
  873. "conqueror",
  874. "conquest",
  875. "consented",
  876. "consequential",
  877. "consider",
  878. "considerable",
  879. "considered",
  880. "considering",
  881. "constant",
  882. "consultation",
  883. "contact",
  884. "contain",
  885. "containing",
  886. "contempt",
  887. "contemptuous",
  888. "contemptuously",
  889. "content",
  890. "continued",
  891. "contract",
  892. "contradicted",
  893. "contributions",
  894. "conversation",
  895. "conversations",
  896. "convert",
  897. "cook",
  898. "cool",
  899. "copied",
  900. "copies",
  901. "copy",
  902. "copying",
  903. "copyright",
  904. "corner",
  905. "corners",
  906. "corporation",
  907. "corrupt",
  908. "cost",
  909. "costs",
  910. "could",
  911. "couldn",
  912. "counting",
  913. "countries",
  914. "country",
  915. "couple",
  916. "couples",
  917. "courage",
  918. "course",
  919. "court",
  920. "courtiers",
  921. "coward",
  922. "crab",
  923. "crash",
  924. "crashed",
  925. "crawled",
  926. "crawling",
  927. "crazy",
  928. "created",
  929. "creating",
  930. "creation",
  931. "creature",
  932. "creatures",
  933. "credit",
  934. "creep",
  935. "crept",
  936. "cried",
  937. "cries",
  938. "crimson",
  939. "critical",
  940. "crocodile",
  941. "croquet",
  942. "croqueted",
  943. "croqueting",
  944. "cross",
  945. "crossed",
  946. "crossly",
  947. "crouched",
  948. "crowd",
  949. "crowded",
  950. "crown",
  951. "crumbs",
  952. "crust",
  953. "cry",
  954. "crying",
  955. "cucumber",
  956. "cunning",
  957. "cup",
  958. "cupboards",
  959. "cur",
  960. "curiosity",
  961. "curious",
  962. "curiouser",
  963. "curled",
  964. "curls",
  965. "curly",
  966. "currants",
  967. "current",
  968. "curtain",
  969. "curtsey",
  970. "curtseying",
  971. "curving",
  972. "cushion",
  973. "custard",
  974. "custody",
  975. "cut",
  976. "cutting",
  977. };
  978. }
  979. private void RunTest(Action<AutoCompleteBox, TextBox> test)
  980. {
  981. using (UnitTestApplication.Start(Services))
  982. {
  983. AutoCompleteBox control = CreateControl();
  984. control.Items = CreateSimpleStringArray();
  985. TextBox textBox = GetTextBox(control);
  986. var window = new Window {Content = control};
  987. window.ApplyStyling();
  988. window.ApplyTemplate();
  989. window.Presenter.ApplyTemplate();
  990. Dispatcher.UIThread.RunJobs();
  991. test.Invoke(control, textBox);
  992. }
  993. }
  994. private static TestServices Services => TestServices.StyledWindow;
  995. /*private static TestServices Services => TestServices.MockThreadingInterface.With(
  996. standardCursorFactory: Mock.Of<IStandardCursorFactory>(),
  997. windowingPlatform: new MockWindowingPlatform());*/
  998. private AutoCompleteBox CreateControl()
  999. {
  1000. var datePicker =
  1001. new AutoCompleteBox
  1002. {
  1003. Template = CreateTemplate()
  1004. };
  1005. datePicker.ApplyTemplate();
  1006. return datePicker;
  1007. }
  1008. private TextBox GetTextBox(AutoCompleteBox control)
  1009. {
  1010. return control.GetTemplateChildren()
  1011. .OfType<TextBox>()
  1012. .First();
  1013. }
  1014. private IControlTemplate CreateTemplate()
  1015. {
  1016. return new FuncControlTemplate<AutoCompleteBox>((control, scope) =>
  1017. {
  1018. var textBox =
  1019. new TextBox
  1020. {
  1021. Name = "PART_TextBox"
  1022. }.RegisterInNameScope(scope);
  1023. var listbox =
  1024. new ListBox
  1025. {
  1026. Name = "PART_SelectingItemsControl"
  1027. }.RegisterInNameScope(scope);
  1028. var popup =
  1029. new Popup
  1030. {
  1031. Name = "PART_Popup",
  1032. PlacementTarget = control
  1033. }.RegisterInNameScope(scope);
  1034. var panel = new Panel();
  1035. panel.Children.Add(textBox);
  1036. panel.Children.Add(popup);
  1037. panel.Children.Add(listbox);
  1038. return panel;
  1039. });
  1040. }
  1041. }
  1042. }