ThemeScopeTests.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System.Text.Json;
  2. using static Terminal.Gui.ConfigurationManager;
  3. namespace Terminal.Gui.ConfigurationTests;
  4. public class ThemeScopeTests
  5. {
  6. public static readonly JsonSerializerOptions _jsonOptions = new ()
  7. {
  8. Converters =
  9. {
  10. //new AttributeJsonConverter (),
  11. //new ColorJsonConverter ()
  12. }
  13. };
  14. [Fact]
  15. public void AllThemesPresent ()
  16. {
  17. Reset ();
  18. Assert.True (Themes.ContainsKey ("Default"));
  19. Assert.True (Themes.ContainsKey ("Dark"));
  20. Assert.True (Themes.ContainsKey ("Light"));
  21. }
  22. [Fact]
  23. [AutoInitShutdown]
  24. public void Apply_ShouldApplyUpdatedProperties ()
  25. {
  26. Reset ();
  27. Assert.NotEmpty (Themes);
  28. Assert.Equal (Dialog.ButtonAlignments.Center, Dialog.DefaultButtonAlignment);
  29. Themes ["Default"] ["Dialog.DefaultButtonAlignment"].PropertyValue = Dialog.ButtonAlignments.Right;
  30. ThemeManager.Themes! [ThemeManager.SelectedTheme]!.Apply ();
  31. Assert.Equal (Dialog.ButtonAlignments.Right, Dialog.DefaultButtonAlignment);
  32. }
  33. [Fact]
  34. public void GetHardCodedDefaults_ShouldSetProperties ()
  35. {
  36. Reset ();
  37. GetHardCodedDefaults ();
  38. Assert.NotEmpty (Themes);
  39. Assert.Equal ("Default", Themes.Theme);
  40. }
  41. [Fact]
  42. public void TestSerialize_RoundTrip ()
  43. {
  44. Reset ();
  45. Dictionary<string, ThemeScope> initial = ThemeManager.Themes;
  46. string serialized = JsonSerializer.Serialize<IDictionary<string, ThemeScope>> (Themes, _jsonOptions);
  47. IDictionary<string, ThemeScope> deserialized =
  48. JsonSerializer.Deserialize<IDictionary<string, ThemeScope>> (serialized, _jsonOptions);
  49. Assert.NotEqual (initial, deserialized);
  50. Assert.Equal (deserialized.Count, initial.Count);
  51. }
  52. [Fact]
  53. public void ThemeManager_ClassMethodsWork ()
  54. {
  55. Reset ();
  56. Assert.Equal (ThemeManager.Instance, Themes);
  57. Assert.NotEmpty (ThemeManager.Themes);
  58. ThemeManager.SelectedTheme = "foo";
  59. Assert.Equal ("foo", ThemeManager.SelectedTheme);
  60. ThemeManager.Reset ();
  61. Assert.Equal (string.Empty, ThemeManager.SelectedTheme);
  62. Assert.Empty (ThemeManager.Themes);
  63. }
  64. }