AutoCompleteBoxTests.cs 29 KB

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