1
0

AutoCompleteBoxTests.cs 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  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. var window = new Window {Content = control};
  924. window.ApplyTemplate();
  925. window.Presenter.ApplyTemplate();
  926. Dispatcher.UIThread.RunJobs();
  927. test.Invoke(control, textBox);
  928. }
  929. }
  930. private static TestServices Services => TestServices.StyledWindow;
  931. /*private static TestServices Services => TestServices.MockThreadingInterface.With(
  932. standardCursorFactory: Mock.Of<IStandardCursorFactory>(),
  933. windowingPlatform: new MockWindowingPlatform());*/
  934. private AutoCompleteBox CreateControl()
  935. {
  936. var datePicker =
  937. new AutoCompleteBox
  938. {
  939. Template = CreateTemplate()
  940. };
  941. datePicker.ApplyTemplate();
  942. return datePicker;
  943. }
  944. private TextBox GetTextBox(AutoCompleteBox control)
  945. {
  946. return control.GetTemplateChildren()
  947. .OfType<TextBox>()
  948. .First();
  949. }
  950. private IControlTemplate CreateTemplate()
  951. {
  952. return new FuncControlTemplate<AutoCompleteBox>((control, scope) =>
  953. {
  954. var textBox =
  955. new TextBox
  956. {
  957. Name = "PART_TextBox"
  958. }.RegisterInNameScope(scope);
  959. var listbox =
  960. new ListBox
  961. {
  962. Name = "PART_SelectingItemsControl"
  963. }.RegisterInNameScope(scope);
  964. var popup =
  965. new Popup
  966. {
  967. Name = "PART_Popup",
  968. PlacementTarget = control
  969. }.RegisterInNameScope(scope);
  970. var panel = new Panel();
  971. panel.Children.Add(textBox);
  972. panel.Children.Add(popup);
  973. panel.Children.Add(listbox);
  974. return panel;
  975. });
  976. }
  977. }
  978. }