ColorSchemeJsonConverterTests.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System.Text.Json;
  2. using UnitTests;
  3. namespace Terminal.Gui.ConfigurationTests;
  4. public class ColorSchemeJsonConverterTests
  5. {
  6. //string json = @"
  7. // {
  8. // ""ColorSchemes"": {
  9. // ""Base"": {
  10. // ""normal"": {
  11. // ""foreground"": ""White"",
  12. // ""background"": ""Blue""
  13. // },
  14. // ""focus"": {
  15. // ""foreground"": ""Black"",
  16. // ""background"": ""Gray""
  17. // },
  18. // ""hotNormal"": {
  19. // ""foreground"": ""BrightCyan"",
  20. // ""background"": ""Blue""
  21. // },
  22. // ""hotFocus"": {
  23. // ""foreground"": ""BrightBlue"",
  24. // ""background"": ""Gray""
  25. // },
  26. // ""disabled"": {
  27. // ""foreground"": ""DarkGray"",
  28. // ""background"": ""Blue""
  29. // }
  30. // }
  31. // }
  32. // }";
  33. [Fact]
  34. [AutoInitShutdown]
  35. public void TestColorSchemesSerialization ()
  36. {
  37. // Arrange
  38. var expectedColorScheme = new ColorScheme
  39. {
  40. Normal = new Attribute (Color.White, Color.Blue),
  41. Focus = new Attribute (Color.Black, Color.Gray),
  42. HotNormal = new Attribute (Color.BrightCyan, Color.Blue),
  43. HotFocus = new Attribute (Color.BrightBlue, Color.Gray),
  44. Disabled = new Attribute (Color.DarkGray, Color.Blue)
  45. };
  46. string serializedColorScheme =
  47. JsonSerializer.Serialize (expectedColorScheme, ConfigurationManagerTests._jsonOptions);
  48. // Act
  49. var actualColorScheme =
  50. JsonSerializer.Deserialize<ColorScheme> (serializedColorScheme, ConfigurationManagerTests._jsonOptions);
  51. // Assert
  52. Assert.Equal (expectedColorScheme, actualColorScheme);
  53. }
  54. }