ConfigurationMangerTests.cs 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418
  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. ""Runnable"": {
  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. ""Runnable"": {
  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. [ConfigurationProperty (Scope = typeof (CMTestsScope))]
  1178. public static bool? TestProperty { get; set; }
  1179. private class CMTestsScope : Scope<CMTestsScope>
  1180. {
  1181. }
  1182. [Fact]
  1183. public void GetConfigPropertiesByScope_Gets ()
  1184. {
  1185. var props = GetUninitializedConfigPropertiesByScope ("CMTestsScope");
  1186. Assert.NotNull (props);
  1187. Assert.NotEmpty (props);
  1188. }
  1189. }