ConfigurationMangerTests.cs 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402
  1. using System.Collections.Frozen;
  2. using System.Collections.Immutable;
  3. using System.Diagnostics;
  4. using System.Reflection;
  5. using System.Text;
  6. using System.Text.Json;
  7. using Xunit.Abstractions;
  8. using static Terminal.Gui.Configuration.ConfigurationManager;
  9. using File = System.IO.File;
  10. #pragma warning disable IDE1006
  11. namespace UnitTests.ConfigurationTests;
  12. public class ConfigurationManagerTests (ITestOutputHelper output)
  13. {
  14. [Fact]
  15. public void ModuleInitializer_Was_Called ()
  16. {
  17. Assert.False (IsEnabled);
  18. Assert.True (IsInitialized ());
  19. }
  20. [Fact]
  21. public void Initialize_Throws_If_Called_Explicitly ()
  22. {
  23. Assert.False (IsEnabled);
  24. Assert.Throws<InvalidOperationException> (Initialize);
  25. }
  26. [Fact]
  27. public void HardCodedDefaultCache_Properties_Are_Copies ()
  28. {
  29. Assert.False (IsEnabled);
  30. Enable (ConfigLocations.HardCoded);
  31. Assert.Equal (Key.Esc, Application.QuitKey);
  32. ConfigProperty fromSettings = Settings! ["Application.QuitKey"];
  33. FrozenDictionary<string, ConfigProperty> initialCache = GetHardCodedConfigPropertyCache ();
  34. Assert.NotNull (initialCache);
  35. ConfigProperty fromCache = initialCache ["Application.QuitKey"];
  36. // Assert
  37. Assert.NotEqual (fromCache, fromSettings);
  38. Disable (true);
  39. }
  40. [Fact]
  41. public void GetHardCodedDefaultCache_Always_Returns_Same_Ref ()
  42. {
  43. // It's important it always returns the same cache ref, so no copies are made
  44. // Otherwise it's a big performance hit
  45. Assert.False (IsEnabled);
  46. try
  47. {
  48. FrozenDictionary<string, ConfigProperty> initialCache = GetHardCodedConfigPropertyCache ();
  49. FrozenDictionary<string, ConfigProperty> cache = GetHardCodedConfigPropertyCache ();
  50. Assert.Equal (initialCache, cache);
  51. }
  52. finally
  53. {
  54. Disable (true);
  55. }
  56. }
  57. [Fact]
  58. public void HardCodedDefaultCache_Properties_Are_Immutable ()
  59. {
  60. Assert.False (IsEnabled);
  61. try
  62. {
  63. Enable (ConfigLocations.HardCoded);
  64. Assert.Equal (Key.Esc, Application.QuitKey);
  65. FrozenDictionary<string, ConfigProperty> initialCache = GetHardCodedConfigPropertyCache ();
  66. Assert.NotNull (initialCache);
  67. Assert.Equal (Key.Esc, (Key)initialCache ["Application.QuitKey"].PropertyValue);
  68. // Act
  69. Settings! ["Application.QuitKey"].PropertyValue = Key.Q;
  70. Assert.Equal (Key.Q, (Key)Settings ["Application.QuitKey"].PropertyValue);
  71. Settings ["Application.QuitKey"].Apply ();
  72. Assert.Equal (Key.Q, Application.QuitKey);
  73. Application.QuitKey = Key.K;
  74. // Assert
  75. FrozenDictionary<string, ConfigProperty> cache = GetHardCodedConfigPropertyCache ();
  76. Assert.True (initialCache ["Application.QuitKey"].Immutable);
  77. Assert.Equal (Key.Esc, (Key)initialCache ["Application.QuitKey"].PropertyValue);
  78. }
  79. finally
  80. {
  81. Disable (true);
  82. Application.ResetState (true);
  83. }
  84. }
  85. [Fact]
  86. public void Disable_Settings_Is_NotNull ()
  87. {
  88. Assert.False (IsEnabled);
  89. Disable ();
  90. Assert.NotNull (Settings);
  91. }
  92. [Fact]
  93. public void Disable_With_ResetToHardCodedDefaults_True_Works_When_Disabled ()
  94. {
  95. Assert.False (IsEnabled);
  96. Disable (true);
  97. }
  98. [Fact]
  99. public void Enable_Settings_Is_Valid ()
  100. {
  101. Assert.False (IsEnabled);
  102. Enable (ConfigLocations.HardCoded);
  103. Assert.NotNull (Settings);
  104. Disable (true);
  105. }
  106. [Fact]
  107. public void Enable_HardCoded_Resets_Schemes_After_Runtime_Config ()
  108. {
  109. Assert.False (IsEnabled);
  110. try
  111. {
  112. // Arrange: Start from hard-coded defaults and capture baseline scheme values.
  113. Enable (ConfigLocations.HardCoded);
  114. Dictionary<string, Scheme> schemes = SchemeManager.GetSchemes ();
  115. Assert.NotNull (schemes);
  116. Assert.NotEmpty (schemes);
  117. Color baselineFg = schemes ["Base"].Normal.Foreground;
  118. Color baselineBg = schemes ["Base"].Normal.Background;
  119. // Sanity: defaults should be stable
  120. Assert.NotEqual (default (Color), baselineFg);
  121. Assert.NotEqual (default (Color), baselineBg);
  122. // Act: Override the Base scheme via runtime JSON and apply
  123. ThrowOnJsonErrors = true;
  124. RuntimeConfig = """
  125. {
  126. "Themes": [
  127. {
  128. "Default": {
  129. "Schemes": [
  130. {
  131. "Base": {
  132. "Normal": {
  133. "Foreground": "Black",
  134. "Background": "Gray"
  135. }
  136. }
  137. }
  138. ]
  139. }
  140. }
  141. ]
  142. }
  143. """;
  144. Load (ConfigLocations.Runtime);
  145. Apply ();
  146. // Verify override took effect
  147. Dictionary<string, Scheme> overridden = SchemeManager.GetSchemes ();
  148. Assert.Equal (Color.Black, overridden ["Base"].Normal.Foreground);
  149. Assert.Equal (Color.Gray, overridden ["Base"].Normal.Background);
  150. // Now simulate "CM.Enable(true)" semantics: re-enable with HardCoded to reset
  151. Disable ();
  152. Enable (ConfigLocations.HardCoded);
  153. // Assert: schemes are reset to the original hard-coded baseline
  154. Dictionary<string, Scheme> reset = SchemeManager.GetSchemes ();
  155. Assert.Equal (baselineFg, reset ["Base"].Normal.Foreground);
  156. Assert.Equal (baselineBg, reset ["Base"].Normal.Background);
  157. }
  158. finally
  159. {
  160. Disable (true);
  161. Application.ResetState (true);
  162. }
  163. }
  164. [Fact]
  165. public void Enable_HardCoded_Resets_Theme_Dictionary_And_Selection ()
  166. {
  167. Assert.False (IsEnabled);
  168. try
  169. {
  170. // Arrange: Enable defaults
  171. Enable (ConfigLocations.HardCoded);
  172. Assert.Equal (ThemeManager.DEFAULT_THEME_NAME, ThemeManager.Theme);
  173. Assert.Single (ThemeManager.Themes!);
  174. Assert.True (ThemeManager.Themes.ContainsKey (ThemeManager.DEFAULT_THEME_NAME));
  175. // Act: Load a runtime config that introduces a custom theme and selects it
  176. ThrowOnJsonErrors = true;
  177. RuntimeConfig = """
  178. {
  179. "Theme": "Custom",
  180. "Themes": [
  181. {
  182. "Custom": {
  183. "Schemes": [
  184. {
  185. "Base": {
  186. "Normal": {
  187. "Foreground": "Yellow",
  188. "Background": "Black"
  189. }
  190. }
  191. }
  192. ]
  193. }
  194. }
  195. ]
  196. }
  197. """;
  198. // Capture dynamically created hardCoded hard-coded scheme colors
  199. ImmutableSortedDictionary<string, Scheme> hardCodedSchemes = SchemeManager.GetHardCodedSchemes ()!;
  200. Color hardCodedBaseNormalFg = hardCodedSchemes ["Base"].Normal.Foreground;
  201. Assert.Equal (new Color (StandardColor.LightBlue).ToString (), hardCodedBaseNormalFg.ToString ());
  202. Load (ConfigLocations.Runtime);
  203. Apply ();
  204. // Verify the runtime selection took effect
  205. Assert.Equal ("Custom", ThemeManager.Theme);
  206. // Now simulate "CM.Enable(true)" semantics: re-enable with HardCoded to reset
  207. Disable ();
  208. Enable (ConfigLocations.HardCoded);
  209. // Assert: selection and dictionary have been reset to hard-coded defaults
  210. Assert.Equal (ThemeManager.DEFAULT_THEME_NAME, ThemeManager.Theme);
  211. Assert.Single (ThemeManager.Themes!);
  212. Assert.True (ThemeManager.Themes.ContainsKey (ThemeManager.DEFAULT_THEME_NAME));
  213. // Also assert the Base scheme is back to defaults (sanity check)
  214. Scheme baseScheme = SchemeManager.GetSchemes () ["Base"];
  215. Assert.Equal (hardCodedBaseNormalFg.ToString (), SchemeManager.GetSchemes () ["Base"]!.Normal.Foreground.ToString ());
  216. }
  217. finally
  218. {
  219. Disable (true);
  220. Application.ResetState (true);
  221. }
  222. }
  223. [Fact]
  224. public void Apply_Applies_Theme ()
  225. {
  226. Assert.False (IsEnabled);
  227. Enable (ConfigLocations.HardCoded);
  228. var theme = new ThemeScope ();
  229. theme.LoadHardCodedDefaults ();
  230. Assert.NotEmpty (theme);
  231. Assert.True (ThemeManager.Themes!.TryAdd ("testTheme", theme));
  232. Assert.Equal (2, ThemeManager.Themes.Count);
  233. Assert.Equal (LineStyle.Rounded, FrameView.DefaultBorderStyle);
  234. theme ["FrameView.DefaultBorderStyle"].PropertyValue = LineStyle.Double;
  235. ThemeManager.Theme = "testTheme";
  236. Apply ();
  237. Assert.Equal (LineStyle.Double, FrameView.DefaultBorderStyle);
  238. Disable (true);
  239. }
  240. [Fact]
  241. public void Apply_Raises_Applied ()
  242. {
  243. Assert.False (IsEnabled);
  244. Enable (ConfigLocations.HardCoded);
  245. Applied += ConfigurationManagerApplied;
  246. var fired = false;
  247. void ConfigurationManagerApplied (object sender, ConfigurationManagerEventArgs obj)
  248. {
  249. fired = true;
  250. // assert
  251. Assert.Equal (KeyCode.Q, Application.QuitKey.KeyCode);
  252. Assert.Equal (KeyCode.F, Application.NextTabGroupKey.KeyCode);
  253. Assert.Equal (KeyCode.B, Application.PrevTabGroupKey.KeyCode);
  254. }
  255. // act
  256. Settings! ["Application.QuitKey"].PropertyValue = Key.Q;
  257. Settings ["Application.NextTabGroupKey"].PropertyValue = Key.F;
  258. Settings ["Application.PrevTabGroupKey"].PropertyValue = Key.B;
  259. Apply ();
  260. // assert
  261. Assert.True (fired);
  262. Applied -= ConfigurationManagerApplied;
  263. Disable (true);
  264. Application.ResetState (true);
  265. }
  266. [Fact]
  267. public void Load_Raises_Updated ()
  268. {
  269. Assert.False (IsEnabled);
  270. var fired = false;
  271. Enable (ConfigLocations.HardCoded);
  272. ThrowOnJsonErrors = true;
  273. Assert.Equal (Key.Esc, ((Key)Settings! ["Application.QuitKey"].PropertyValue)!.KeyCode);
  274. Updated += ConfigurationManagerUpdated;
  275. // Act
  276. // Only select locations under test control
  277. Load (ConfigLocations.LibraryResources | ConfigLocations.AppResources | ConfigLocations.Runtime);
  278. // assert
  279. Assert.True (fired);
  280. // clean up
  281. Updated -= ConfigurationManagerUpdated;
  282. Disable (true);
  283. Application.ResetState (true);
  284. return;
  285. void ConfigurationManagerUpdated (object sender, ConfigurationManagerEventArgs obj) { fired = true; }
  286. }
  287. [Fact]
  288. public void Load_And_Apply_Performance_Check ()
  289. {
  290. Assert.False (IsEnabled);
  291. Enable (ConfigLocations.HardCoded);
  292. try
  293. {
  294. // Start stopwatch
  295. var stopwatch = new Stopwatch ();
  296. stopwatch.Start ();
  297. // Act
  298. Load (ConfigLocations.All);
  299. Apply ();
  300. // Stop stopwatch
  301. stopwatch.Stop ();
  302. // Assert
  303. output.WriteLine ($"Load took {stopwatch.ElapsedMilliseconds} ms");
  304. // Ensure load time is reasonable (adjust threshold as needed)
  305. Assert.True (
  306. stopwatch.ElapsedMilliseconds < 1000,
  307. $"Loading configuration took {stopwatch.ElapsedMilliseconds}ms, which exceeds reasonable threshold");
  308. }
  309. finally
  310. {
  311. Disable (true);
  312. Application.ResetState (true);
  313. }
  314. }
  315. [Fact]
  316. public void Load_Loads_Custom_Json ()
  317. {
  318. Assert.False (IsEnabled);
  319. try
  320. {
  321. Enable (ConfigLocations.HardCoded);
  322. ThrowOnJsonErrors = true;
  323. Assert.Equal (Key.Esc, (Key)Settings! ["Application.QuitKey"].PropertyValue);
  324. // act
  325. RuntimeConfig = """
  326. {
  327. "Application.QuitKey": "Ctrl-Q"
  328. }
  329. """;
  330. Load (ConfigLocations.Runtime);
  331. // assert
  332. Assert.Equal (Key.Q.WithCtrl, (Key)Settings ["Application.QuitKey"].PropertyValue);
  333. }
  334. finally
  335. {
  336. // clean up
  337. Disable (true);
  338. Application.ResetState (true);
  339. }
  340. }
  341. [Fact (Skip = "Events disabled")]
  342. public void ResetToCurrentValues_Raises_Updated ()
  343. {
  344. Assert.False (IsEnabled);
  345. var fired = false;
  346. try
  347. {
  348. Enable (ConfigLocations.HardCoded);
  349. Settings! ["Application.QuitKey"].PropertyValue = Key.Q;
  350. Updated += ConfigurationManagerUpdated;
  351. // Act
  352. UpdateToCurrentValues ();
  353. // assert
  354. Assert.True (fired);
  355. }
  356. finally
  357. {
  358. Updated -= ConfigurationManagerUpdated;
  359. Disable (true);
  360. Application.ResetState (true);
  361. }
  362. return;
  363. void ConfigurationManagerUpdated (object sender, ConfigurationManagerEventArgs obj) { fired = true; }
  364. }
  365. [Fact]
  366. public void ResetToHardCodedDefaults_and_Load_LibraryResourcesOnly_are_same ()
  367. {
  368. Assert.False (IsEnabled);
  369. try
  370. {
  371. // arrange
  372. Enable (ConfigLocations.HardCoded);
  373. Settings! ["Application.QuitKey"].PropertyValue = Key.Q;
  374. Settings ["Application.NextTabGroupKey"].PropertyValue = Key.F;
  375. Settings ["Application.PrevTabGroupKey"].PropertyValue = Key.B;
  376. Settings.Apply ();
  377. // assert apply worked
  378. Assert.Equal (KeyCode.Q, Application.QuitKey.KeyCode);
  379. Assert.Equal (KeyCode.F, Application.NextTabGroupKey.KeyCode);
  380. Assert.Equal (KeyCode.B, Application.PrevTabGroupKey.KeyCode);
  381. //act
  382. ResetToHardCodedDefaults ();
  383. // assert
  384. Assert.NotEmpty (ThemeManager.Themes!);
  385. Assert.Equal ("Default", ThemeManager.Theme);
  386. Assert.Equal (Key.Esc, Application.QuitKey);
  387. Assert.Equal (Key.F6, Application.NextTabGroupKey);
  388. Assert.Equal (Key.F6.WithShift, Application.PrevTabGroupKey);
  389. // arrange
  390. Settings ["Application.QuitKey"].PropertyValue = Key.Q;
  391. Settings ["Application.NextTabGroupKey"].PropertyValue = Key.F;
  392. Settings ["Application.PrevTabGroupKey"].PropertyValue = Key.B;
  393. Settings.Apply ();
  394. // act
  395. Load (ConfigLocations.LibraryResources);
  396. Apply ();
  397. // assert
  398. Assert.NotEmpty (ThemeManager.Themes);
  399. Assert.Equal ("Default", ThemeManager.Theme);
  400. Assert.Equal (KeyCode.Esc, Application.QuitKey.KeyCode);
  401. Assert.Equal (Key.F6, Application.NextTabGroupKey);
  402. Assert.Equal (Key.F6.WithShift, Application.PrevTabGroupKey);
  403. }
  404. finally
  405. {
  406. Disable (true);
  407. Application.ResetState (true);
  408. }
  409. }
  410. [Fact]
  411. public void ResetToHardCodedDefaults_Resets ()
  412. {
  413. Assert.False (IsEnabled);
  414. try
  415. {
  416. Enable (ConfigLocations.HardCoded);
  417. // Capture dynamically created hardCoded hard-coded scheme colors
  418. ImmutableSortedDictionary<string, Scheme> hardCodedSchemesViaSchemeManager = SchemeManager.GetHardCodedSchemes ()!;
  419. Dictionary<string, Scheme> hardCodedSchemes =
  420. GetHardCodedConfigPropertiesByScope ("ThemeScope")!.ToFrozenDictionary () ["Schemes"].PropertyValue as Dictionary<string, Scheme>;
  421. Color hardCodedBaseNormalFg = hardCodedSchemesViaSchemeManager ["Base"].Normal.Foreground;
  422. Assert.Equal (new Color (StandardColor.LightBlue).ToString (), hardCodedBaseNormalFg.ToString ());
  423. // Capture current scheme colors
  424. Dictionary<string, Scheme> currentSchemes = SchemeManager.GetSchemes ()!;
  425. Color currentBaseNormalFg = currentSchemes ["Base"].Normal.Foreground;
  426. Assert.Equal (hardCodedBaseNormalFg.ToString (), currentBaseNormalFg.ToString ());
  427. // Arrange
  428. var json = @"
  429. {
  430. ""$schema"": ""https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json"",
  431. ""Application.QuitKey"": ""Alt-Z"",
  432. ""Theme"": ""Default"",
  433. ""Themes"": [
  434. {
  435. ""Default"": {
  436. ""MessageBox.DefaultButtonAlignment"": ""End"",
  437. ""Schemes"": [
  438. {
  439. ""TopLevel"": {
  440. ""Normal"": {
  441. ""Foreground"": ""BrightGreen"",
  442. ""Background"": ""Black""
  443. },
  444. ""Focus"": {
  445. ""Foreground"": ""White"",
  446. ""Background"": ""Cyan""
  447. },
  448. ""HotNormal"": {
  449. ""Foreground"": ""Yellow"",
  450. ""Background"": ""Black""
  451. },
  452. ""HotFocus"": {
  453. ""Foreground"": ""Blue"",
  454. ""Background"": ""Cyan""
  455. },
  456. ""Disabled"": {
  457. ""Foreground"": ""DarkGray"",
  458. ""Background"": ""Black""
  459. }
  460. }
  461. },
  462. {
  463. ""Base"": {
  464. ""Normal"": {
  465. ""Foreground"": ""White"",
  466. ""Background"": ""Blue""
  467. },
  468. ""Focus"": {
  469. ""Foreground"": ""Black"",
  470. ""Background"": ""Gray""
  471. },
  472. ""HotNormal"": {
  473. ""Foreground"": ""BrightCyan"",
  474. ""Background"": ""Blue""
  475. },
  476. ""HotFocus"": {
  477. ""Foreground"": ""BrightBlue"",
  478. ""Background"": ""Gray""
  479. },
  480. ""Disabled"": {
  481. ""Foreground"": ""DarkGray"",
  482. ""Background"": ""Blue""
  483. }
  484. }
  485. },
  486. {
  487. ""Dialog"": {
  488. ""Normal"": {
  489. ""Foreground"": ""Black"",
  490. ""Background"": ""Gray""
  491. },
  492. ""Focus"": {
  493. ""Foreground"": ""White"",
  494. ""Background"": ""DarkGray""
  495. },
  496. ""HotNormal"": {
  497. ""Foreground"": ""Blue"",
  498. ""Background"": ""Gray""
  499. },
  500. ""HotFocus"": {
  501. ""Foreground"": ""BrightYellow"",
  502. ""Background"": ""DarkGray""
  503. },
  504. ""Disabled"": {
  505. ""Foreground"": ""Gray"",
  506. ""Background"": ""DarkGray""
  507. }
  508. }
  509. },
  510. {
  511. ""Menu"": {
  512. ""Normal"": {
  513. ""Foreground"": ""White"",
  514. ""Background"": ""DarkGray""
  515. },
  516. ""Focus"": {
  517. ""Foreground"": ""White"",
  518. ""Background"": ""Black""
  519. },
  520. ""HotNormal"": {
  521. ""Foreground"": ""BrightYellow"",
  522. ""Background"": ""DarkGray""
  523. },
  524. ""HotFocus"": {
  525. ""Foreground"": ""BrightYellow"",
  526. ""Background"": ""Black""
  527. },
  528. ""Disabled"": {
  529. ""Foreground"": ""Gray"",
  530. ""Background"": ""DarkGray""
  531. }
  532. }
  533. },
  534. {
  535. ""Error"": {
  536. ""Normal"": {
  537. ""Foreground"": ""Red"",
  538. ""Background"": ""White""
  539. },
  540. ""Focus"": {
  541. ""Foreground"": ""Black"",
  542. ""Background"": ""BrightRed""
  543. },
  544. ""HotNormal"": {
  545. ""Foreground"": ""Black"",
  546. ""Background"": ""White""
  547. },
  548. ""HotFocus"": {
  549. ""Foreground"": ""White"",
  550. ""Background"": ""BrightRed""
  551. },
  552. ""Disabled"": {
  553. ""Foreground"": ""DarkGray"",
  554. ""Background"": ""White""
  555. }
  556. }
  557. }
  558. ]
  559. }
  560. }
  561. ]
  562. }
  563. ";
  564. // ResetToCurrentValues ();
  565. ThrowOnJsonErrors = true;
  566. ConfigurationManager.SourcesManager?.Load (Settings, json, "UpdateFromJson", ConfigLocations.Runtime);
  567. Assert.Equal ("Default", ThemeManager.Theme);
  568. Assert.Equal (KeyCode.Esc, Application.QuitKey.KeyCode);
  569. Assert.Equal (KeyCode.Z | KeyCode.AltMask, ((Key)Settings! ["Application.QuitKey"].PropertyValue)!.KeyCode);
  570. Assert.Equal (Alignment.Center, MessageBox.DefaultButtonAlignment);
  571. // Get current scheme colors again
  572. currentSchemes = SchemeManager.GetSchemes ()!;
  573. currentBaseNormalFg = currentSchemes ["Base"].Normal.Foreground;
  574. Assert.Equal (Color.White.ToString (), currentBaseNormalFg.ToString ());
  575. // Now Apply
  576. Apply ();
  577. Assert.Equal ("Default", ThemeManager.Theme);
  578. Assert.Equal (KeyCode.Z | KeyCode.AltMask, Application.QuitKey.KeyCode);
  579. Assert.Equal (Alignment.End, MessageBox.DefaultButtonAlignment);
  580. Assert.Equal (Color.White.ToString (), currentBaseNormalFg.ToString ());
  581. // Reset
  582. ResetToHardCodedDefaults ();
  583. hardCodedSchemes =
  584. GetHardCodedConfigPropertiesByScope ("ThemeScope")!.ToFrozenDictionary () ["Schemes"].PropertyValue as Dictionary<string, Scheme>;
  585. hardCodedBaseNormalFg = hardCodedSchemes! ["Base"].Normal.Foreground;
  586. Assert.Equal (new Color (StandardColor.LightBlue).ToString (), hardCodedBaseNormalFg.ToString ());
  587. FrozenDictionary<string, ConfigProperty> hardCodedCache = GetHardCodedConfigPropertyCache ()!;
  588. Assert.Equal (hardCodedCache ["Theme"].PropertyValue, ThemeManager.Theme);
  589. Assert.Equal (hardCodedCache ["Application.QuitKey"].PropertyValue, Application.QuitKey);
  590. // Themes
  591. Assert.Equal (hardCodedCache ["MessageBox.DefaultButtonAlignment"].PropertyValue, MessageBox.DefaultButtonAlignment);
  592. Assert.Equal (GetHardCodedConfigPropertyCache ()! ["MessageBox.DefaultButtonAlignment"].PropertyValue, MessageBox.DefaultButtonAlignment);
  593. // Schemes
  594. currentSchemes = SchemeManager.GetSchemes ()!;
  595. currentBaseNormalFg = currentSchemes ["Base"].Normal.Foreground;
  596. Assert.Equal (hardCodedBaseNormalFg.ToString (), currentBaseNormalFg.ToString ());
  597. Scheme baseScheme = SchemeManager.GetScheme ("Base");
  598. Attribute attr = baseScheme.Normal;
  599. // Use ToString so Assert.Equal shows the actual vs expected values on failure
  600. Assert.Equal (hardCodedBaseNormalFg.ToString (), attr.Foreground.ToString ());
  601. }
  602. finally
  603. {
  604. output.WriteLine ("Disabling CM to clean up.");
  605. Disable (true);
  606. }
  607. }
  608. [Fact (Skip = "ResetToCurrentValues corrupts hard coded cache")]
  609. public void ResetToCurrentValues_Enabled_Resets ()
  610. {
  611. Assert.False (IsEnabled);
  612. try
  613. {
  614. // Act
  615. Enable (ConfigLocations.HardCoded);
  616. Application.QuitKey = Key.A;
  617. UpdateToCurrentValues ();
  618. Assert.Equal (Key.A, (Key)Settings! ["Application.QuitKey"].PropertyValue);
  619. Assert.NotNull (Settings);
  620. Assert.NotNull (AppSettings);
  621. Assert.NotNull (ThemeManager.Themes);
  622. // Default Theme should be "Default"
  623. Assert.Single (ThemeManager.Themes);
  624. Assert.Equal (ThemeManager.DEFAULT_THEME_NAME, ThemeManager.Theme);
  625. }
  626. finally
  627. {
  628. Disable (true);
  629. }
  630. }
  631. [Fact]
  632. public void ConfigurationManager_DefaultPrecedence_IsRespected ()
  633. {
  634. Assert.False (IsEnabled);
  635. try
  636. {
  637. // arrange
  638. Enable (ConfigLocations.HardCoded);
  639. ThrowOnJsonErrors = true;
  640. // Setup multiple configurations with the same setting
  641. // with different precedence levels
  642. RuntimeConfig = """
  643. {
  644. "Application.QuitKey": "Alt+Q"
  645. }
  646. """;
  647. var defaultConfig = """
  648. {
  649. "Application.QuitKey": "Ctrl+X"
  650. }
  651. """;
  652. // Update default config first (lower precedence)
  653. ConfigurationManager.SourcesManager?.Load (Settings, defaultConfig, "default-test", ConfigLocations.LibraryResources);
  654. // Then load runtime config, which should override default
  655. Load (ConfigLocations.Runtime);
  656. // Assert - the runtime config should win due to precedence
  657. Assert.Equal (Key.Q.WithAlt, (Key)Settings! ["Application.QuitKey"].PropertyValue);
  658. }
  659. finally
  660. {
  661. Disable (true);
  662. }
  663. }
  664. /// <summary>Save the `config.json` file; this can be used to update the file in `Terminal.Gui.Resources.config.json'.</summary>
  665. /// <remarks>
  666. /// IMPORTANT: For the file generated to be valid, this must be the ONLY test run. Config Properties are all
  667. /// static and thus can be overwritten by other tests.
  668. /// </remarks>
  669. [Fact]
  670. public void Save_HardCodedDefaults_To_config_json ()
  671. {
  672. Assert.False (IsEnabled);
  673. try
  674. {
  675. Enable (ConfigLocations.HardCoded);
  676. // Get the hard coded settings
  677. ResetToHardCodedDefaults ();
  678. // Serialize to a JSON string
  679. string json = ConfigurationManager.SourcesManager?.ToJson (Settings);
  680. // Write the JSON string to the file
  681. File.WriteAllText ("hard_coded_defaults_config.json", json);
  682. // Verify the file was created
  683. Assert.True (File.Exists ("hard_coded_defaults_config.json"), "Failed to create config.json file");
  684. }
  685. finally
  686. {
  687. Disable (true);
  688. }
  689. }
  690. /// <summary>Save the `config.json` file; this can be used to update the file in `Terminal.Gui.Resources.config.json'.</summary>
  691. /// <remarks>
  692. /// IMPORTANT: For the file generated to be valid, this must be the ONLY test run. Config Properties are all
  693. /// static and thus can be overwritten by other tests.
  694. /// </remarks>
  695. [Fact]
  696. public void Save_Library_Defaults_To_config_json ()
  697. {
  698. Assert.False (IsEnabled);
  699. try
  700. {
  701. Enable (ConfigLocations.LibraryResources);
  702. // Serialize to a JSON string
  703. string json = ConfigurationManager.SourcesManager?.ToJson (Settings);
  704. // Write the JSON string to the file
  705. File.WriteAllText ("library_defaults_config.json", json);
  706. // Verify the file was created
  707. Assert.True (File.Exists ("library_defaults_config.json"), "Failed to create config.json file");
  708. }
  709. finally
  710. {
  711. Disable (true);
  712. }
  713. }
  714. [Fact]
  715. public void TestConfigProperties ()
  716. {
  717. Assert.False (IsEnabled);
  718. try
  719. {
  720. Enable (ConfigLocations.HardCoded);
  721. Assert.NotEmpty (Settings!);
  722. // test that all ConfigProperties have our attribute
  723. Assert.All (
  724. Settings,
  725. item => Assert.Contains (
  726. item.Value.PropertyInfo!.CustomAttributes,
  727. a => a.AttributeType
  728. == typeof (ConfigurationPropertyAttribute)
  729. ));
  730. #pragma warning disable xUnit2030
  731. Assert.DoesNotContain (
  732. Settings,
  733. cp => cp.Value.PropertyInfo!.GetCustomAttribute (
  734. typeof (ConfigurationPropertyAttribute)
  735. )
  736. == null
  737. );
  738. #pragma warning restore xUnit2030
  739. // Application is a static class
  740. PropertyInfo pi = typeof (Application).GetProperty ("QuitKey");
  741. Assert.Equal (pi, Settings ["Application.QuitKey"].PropertyInfo);
  742. // FrameView is not a static class and DefaultBorderStyle is Scope.Scheme
  743. pi = typeof (FrameView).GetProperty ("DefaultBorderStyle");
  744. Assert.False (Settings.ContainsKey ("FrameView.DefaultBorderStyle"));
  745. Assert.True (ThemeManager.GetCurrentTheme ().ContainsKey ("FrameView.DefaultBorderStyle"));
  746. Assert.Equal (pi, ThemeManager.GetCurrentTheme () ["FrameView.DefaultBorderStyle"].PropertyInfo);
  747. }
  748. finally
  749. {
  750. Disable (true);
  751. }
  752. }
  753. [Fact]
  754. public void Load_And_Apply_HardCoded ()
  755. {
  756. Assert.False (IsEnabled);
  757. try
  758. {
  759. // Spot check by setting some of the config properties
  760. Application.QuitKey = Key.X.WithCtrl;
  761. FileDialog.MaxSearchResults = 1;
  762. Enable (ConfigLocations.HardCoded);
  763. Load (ConfigLocations.HardCoded);
  764. // Spot check
  765. Assert.Equal (Key.Esc, Settings ["Application.QuitKey"].PropertyValue as Key);
  766. Assert.Equal (10000, (int)Settings ["FileDialog.MaxSearchResults"].PropertyValue!);
  767. Assert.Single (ThemeManager.Themes!);
  768. Assert.Equal ("Default", ThemeManager.Theme);
  769. Assert.NotEmpty (ThemeManager.Themes [ThemeManager.Theme]);
  770. // Verify schemes are properly initialized
  771. Assert.NotNull (SchemeManager.GetSchemes ());
  772. Assert.NotEmpty (SchemeManager.GetSchemes ());
  773. // Verify "Base" has correct values
  774. //Assert.Equal (Color.White, SchemeManager.GetSchemes () ["Base"]!.Normal.Foreground);
  775. //Assert.Equal (Color.Blue, SchemeManager.GetSchemes () ["Base"].Normal.Background);
  776. Apply ();
  777. Assert.Equal (Key.Esc, Application.QuitKey);
  778. Assert.Equal (10000, FileDialog.MaxSearchResults);
  779. }
  780. finally
  781. {
  782. Disable (true);
  783. }
  784. }
  785. [Fact]
  786. public void Load_And_Apply_LibraryResources ()
  787. {
  788. Assert.False (IsEnabled);
  789. try
  790. {
  791. // Spot check by setting some of the config properties
  792. Application.QuitKey = Key.X.WithCtrl;
  793. FileDialog.MaxSearchResults = 1;
  794. Enable (ConfigLocations.HardCoded);
  795. Load (ConfigLocations.LibraryResources);
  796. // Spot check
  797. Assert.Equal (Key.Esc, Settings! ["Application.QuitKey"].PropertyValue as Key);
  798. Assert.Equal (10000, (int)Settings ["FileDialog.MaxSearchResults"].PropertyValue!);
  799. Assert.NotEmpty (ThemeManager.Themes!);
  800. Assert.Equal ("Default", ThemeManager.Theme);
  801. Assert.NotEmpty (ThemeManager.Themes [ThemeManager.Theme]);
  802. // Verify schemes are properly initialized
  803. Assert.NotNull (SchemeManager.GetSchemes ());
  804. Assert.NotEmpty (SchemeManager.GetSchemes ());
  805. // This is too fragile as the default scheme may change
  806. // Verify "Base" has correct values
  807. //Assert.Equal (Color.White, SchemeManager.Schemes ["Base"]!.Normal.Foreground);
  808. //Assert.Equal (Color.Blue, SchemeManager.Schemes ["Base"].Normal.Background);
  809. Apply ();
  810. Assert.Equal (Key.Esc, Application.QuitKey);
  811. Assert.Equal (10000, FileDialog.MaxSearchResults);
  812. }
  813. finally
  814. {
  815. Disable (true);
  816. }
  817. }
  818. [Fact]
  819. public void Load_And_Apply_RuntimeConfig ()
  820. {
  821. Assert.False (IsEnabled);
  822. try
  823. {
  824. // Spot check by setting some of the config properties
  825. Application.QuitKey = Key.X.WithCtrl;
  826. FileDialog.MaxSearchResults = 1;
  827. Glyphs.Apple = new ('z');
  828. ThrowOnJsonErrors = true;
  829. Enable (ConfigLocations.HardCoded);
  830. RuntimeConfig = """
  831. {
  832. "Application.QuitKey": "Alt-Q",
  833. "FileDialog.MaxSearchResults":9,
  834. "Themes" : [
  835. {
  836. "Default" : {
  837. "Glyphs.Apple": "a"
  838. }
  839. }
  840. ]
  841. }
  842. """;
  843. Load (ConfigLocations.Runtime);
  844. Assert.Equal (Key.Q.WithAlt, Settings! ["Application.QuitKey"].PropertyValue as Key);
  845. Assert.Equal (9, (int)Settings ["FileDialog.MaxSearchResults"].PropertyValue!);
  846. Assert.Equal (new Rune ('a'), ThemeManager.GetCurrentTheme () ["Glyphs.Apple"].PropertyValue);
  847. Apply ();
  848. Assert.Equal (Key.Q.WithAlt, Application.QuitKey);
  849. Assert.Equal (9, FileDialog.MaxSearchResults);
  850. Assert.Equal (new ('a'), Glyphs.Apple);
  851. }
  852. finally
  853. {
  854. Disable (true);
  855. }
  856. }
  857. [Fact]
  858. public void InvalidJsonLogs ()
  859. {
  860. Assert.False (IsEnabled);
  861. Enable (ConfigLocations.HardCoded);
  862. ThrowOnJsonErrors = false;
  863. // "brown" is not a color
  864. var json = @"
  865. {
  866. ""Themes"" : [
  867. {
  868. ""Default"" : {
  869. ""Schemes"": [
  870. {
  871. ""UserDefined"": {
  872. ""hotNormal"": {
  873. ""foreground"": ""brown"",
  874. ""background"": ""1234""
  875. }
  876. }
  877. }
  878. ]
  879. }
  880. }
  881. }
  882. }";
  883. ConfigurationManager.SourcesManager?.Load (Settings, json, "test", ConfigLocations.Runtime);
  884. // AbNormal is not a Scheme attribute
  885. json = @"
  886. {
  887. ""Themes"" : [
  888. {
  889. ""Default"" : {
  890. ""Schemes"": [
  891. {
  892. ""UserDefined"": {
  893. ""AbNormal"": {
  894. ""foreground"": ""green"",
  895. ""background"": ""black""
  896. }
  897. }
  898. }
  899. ]
  900. }
  901. }
  902. }
  903. }";
  904. ConfigurationManager.SourcesManager?.Load (Settings, json, "test", ConfigLocations.Runtime);
  905. // Modify hotNormal background only
  906. json = @"
  907. {
  908. ""Themes"" : [
  909. {
  910. ""Default"" : {
  911. ""Schemes"": [
  912. {
  913. ""UserDefined"": {
  914. ""hotNormal"": {
  915. ""background"": ""cyan""
  916. }
  917. }
  918. }
  919. ]
  920. }
  921. }
  922. }
  923. }";
  924. ConfigurationManager.SourcesManager?.Load (Settings, json, "test", ConfigLocations.Runtime);
  925. ConfigurationManager.SourcesManager?.Load (Settings, "{}}", "test", ConfigLocations.Runtime);
  926. Assert.NotEqual (0, _jsonErrors.Length);
  927. ThrowOnJsonErrors = false;
  928. Disable (true);
  929. }
  930. [Fact]
  931. public void InvalidJsonThrows ()
  932. {
  933. Assert.False (IsEnabled);
  934. Enable (ConfigLocations.HardCoded);
  935. ThrowOnJsonErrors = true;
  936. // "yellow" is not a color
  937. var json = @"
  938. {
  939. ""Themes"" : [
  940. {
  941. ""Default"" : {
  942. ""Schemes"": [
  943. {
  944. ""UserDefined"": {
  945. ""hotNormal"": {
  946. ""foreground"": ""brownish"",
  947. ""background"": ""1234""
  948. }
  949. }
  950. }
  951. ]
  952. }
  953. }
  954. ]
  955. }";
  956. var jsonException = Assert.Throws<JsonException> (() => ConfigurationManager.SourcesManager?.Load (Settings, json, "test", ConfigLocations.Runtime));
  957. Assert.StartsWith ("foreground: \"\"brownish\"\"", jsonException.Message);
  958. // AbNormal is not a Scheme attribute
  959. json = @"
  960. {
  961. ""Themes"" : [
  962. {
  963. ""Default"" : {
  964. ""Schemes"": [
  965. {
  966. ""UserDefined"": {
  967. ""AbNormal"": {
  968. ""foreground"": ""green"",
  969. ""background"": ""black""
  970. }
  971. }
  972. }
  973. ]
  974. }
  975. }
  976. ]
  977. }";
  978. jsonException = Assert.Throws<JsonException> (() => ConfigurationManager.SourcesManager?.Load (Settings, json, "test", ConfigLocations.Runtime));
  979. Assert.StartsWith ("AbNormal:", jsonException.Message);
  980. // Modify hotNormal background only
  981. json = @"
  982. {
  983. ""Themes"" : [
  984. {
  985. ""Default"" : {
  986. ""Schemes"": [
  987. {
  988. ""UserDefined"": {
  989. ""hotNormal"": {
  990. ""background"": ""cyan""
  991. }
  992. }
  993. }
  994. ]
  995. }
  996. }
  997. ]
  998. }";
  999. jsonException = Assert.Throws<JsonException> (() => ConfigurationManager.SourcesManager?.Load (Settings, json, "test", ConfigLocations.Runtime));
  1000. Assert.StartsWith ("background:", jsonException.Message);
  1001. // Unknown property
  1002. json = @"
  1003. {
  1004. ""Unknown"" : ""Not known""
  1005. }";
  1006. jsonException = Assert.Throws<JsonException> (() => ConfigurationManager.SourcesManager?.Load (Settings, json, "test", ConfigLocations.Runtime));
  1007. Assert.StartsWith ("Unknown:", jsonException.Message);
  1008. Assert.Equal (0, _jsonErrors.Length);
  1009. ThrowOnJsonErrors = false;
  1010. Disable (true);
  1011. }
  1012. [Fact]
  1013. public void SourcesManager_Load_FromJson_Loads ()
  1014. {
  1015. Assert.False (IsEnabled);
  1016. try
  1017. {
  1018. Enable (ConfigLocations.HardCoded);
  1019. // Arrange
  1020. var json = @"
  1021. {
  1022. ""$schema"": ""https://gui-cs.github.io/Terminal.Gui/schemas/tui-config-schema.json"",
  1023. ""Application.QuitKey"": ""Alt-Z"",
  1024. ""Theme"": ""Default"",
  1025. ""Themes"": [
  1026. {
  1027. ""Default"": {
  1028. ""MessageBox.DefaultButtonAlignment"": ""End"",
  1029. ""Schemes"": [
  1030. {
  1031. ""TopLevel"": {
  1032. ""Normal"": {
  1033. ""Foreground"": ""BrightGreen"",
  1034. ""Background"": ""Black""
  1035. },
  1036. ""Focus"": {
  1037. ""Foreground"": ""White"",
  1038. ""Background"": ""Cyan""
  1039. },
  1040. ""HotNormal"": {
  1041. ""Foreground"": ""Yellow"",
  1042. ""Background"": ""Black""
  1043. },
  1044. ""HotFocus"": {
  1045. ""Foreground"": ""Blue"",
  1046. ""Background"": ""Cyan""
  1047. },
  1048. ""Disabled"": {
  1049. ""Foreground"": ""DarkGray"",
  1050. ""Background"": ""Black""
  1051. }
  1052. }
  1053. },
  1054. {
  1055. ""Base"": {
  1056. ""Normal"": {
  1057. ""Foreground"": ""White"",
  1058. ""Background"": ""Blue""
  1059. },
  1060. ""Focus"": {
  1061. ""Foreground"": ""Black"",
  1062. ""Background"": ""Gray""
  1063. },
  1064. ""HotNormal"": {
  1065. ""Foreground"": ""BrightCyan"",
  1066. ""Background"": ""Blue""
  1067. },
  1068. ""HotFocus"": {
  1069. ""Foreground"": ""BrightBlue"",
  1070. ""Background"": ""Gray""
  1071. },
  1072. ""Disabled"": {
  1073. ""Foreground"": ""DarkGray"",
  1074. ""Background"": ""Blue""
  1075. }
  1076. }
  1077. },
  1078. {
  1079. ""Dialog"": {
  1080. ""Normal"": {
  1081. ""Foreground"": ""Black"",
  1082. ""Background"": ""Gray""
  1083. },
  1084. ""Focus"": {
  1085. ""Foreground"": ""White"",
  1086. ""Background"": ""DarkGray""
  1087. },
  1088. ""HotNormal"": {
  1089. ""Foreground"": ""Blue"",
  1090. ""Background"": ""Gray""
  1091. },
  1092. ""HotFocus"": {
  1093. ""Foreground"": ""BrightYellow"",
  1094. ""Background"": ""DarkGray""
  1095. },
  1096. ""Disabled"": {
  1097. ""Foreground"": ""Gray"",
  1098. ""Background"": ""DarkGray""
  1099. }
  1100. }
  1101. },
  1102. {
  1103. ""Menu"": {
  1104. ""Normal"": {
  1105. ""Foreground"": ""White"",
  1106. ""Background"": ""DarkGray""
  1107. },
  1108. ""Focus"": {
  1109. ""Foreground"": ""White"",
  1110. ""Background"": ""Black""
  1111. },
  1112. ""HotNormal"": {
  1113. ""Foreground"": ""BrightYellow"",
  1114. ""Background"": ""DarkGray""
  1115. },
  1116. ""HotFocus"": {
  1117. ""Foreground"": ""BrightYellow"",
  1118. ""Background"": ""Black""
  1119. },
  1120. ""Disabled"": {
  1121. ""Foreground"": ""Gray"",
  1122. ""Background"": ""DarkGray""
  1123. }
  1124. }
  1125. },
  1126. {
  1127. ""Error"": {
  1128. ""Normal"": {
  1129. ""Foreground"": ""Red"",
  1130. ""Background"": ""White""
  1131. },
  1132. ""Focus"": {
  1133. ""Foreground"": ""Black"",
  1134. ""Background"": ""BrightRed""
  1135. },
  1136. ""HotNormal"": {
  1137. ""Foreground"": ""Black"",
  1138. ""Background"": ""White""
  1139. },
  1140. ""HotFocus"": {
  1141. ""Foreground"": ""White"",
  1142. ""Background"": ""BrightRed""
  1143. },
  1144. ""Disabled"": {
  1145. ""Foreground"": ""DarkGray"",
  1146. ""Background"": ""White""
  1147. }
  1148. }
  1149. }
  1150. ]
  1151. }
  1152. }
  1153. ]
  1154. }
  1155. ";
  1156. //ResetToCurrentValues ();
  1157. ThrowOnJsonErrors = true;
  1158. ConfigurationManager.SourcesManager?.Load (Settings, json, "UpdateFromJson", ConfigLocations.Runtime);
  1159. Assert.Equal ("Default", ThemeManager.Theme);
  1160. Assert.Equal (KeyCode.Esc, Application.QuitKey.KeyCode);
  1161. Assert.Equal (KeyCode.Z | KeyCode.AltMask, ((Key)Settings! ["Application.QuitKey"].PropertyValue)!.KeyCode);
  1162. Assert.Equal (Alignment.Center, MessageBox.DefaultButtonAlignment);
  1163. // Now Apply
  1164. Apply ();
  1165. Assert.Equal ("Default", ThemeManager.Theme);
  1166. Assert.Equal (KeyCode.Z | KeyCode.AltMask, Application.QuitKey.KeyCode);
  1167. Assert.Equal (Alignment.End, MessageBox.DefaultButtonAlignment);
  1168. Assert.Equal (Color.White, SchemeManager.GetSchemes ()! ["Base"].Normal.Foreground);
  1169. Assert.Equal (Color.Blue, SchemeManager.GetSchemes ()! ["Base"].Normal.Background);
  1170. }
  1171. finally
  1172. {
  1173. output.WriteLine ("Disabling CM to clean up.");
  1174. Disable (true);
  1175. }
  1176. }
  1177. }