SettingsScopeTests.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using static Terminal.Gui.ConfigurationManager;
  2. namespace Terminal.Gui.ConfigurationTests;
  3. public class SettingsScopeTests
  4. {
  5. [Fact]
  6. [AutoInitShutdown (configLocation: ConfigLocations.DefaultOnly)]
  7. public void Apply_ShouldApplyProperties ()
  8. {
  9. // arrange
  10. Assert.Equal (Key.Esc, (Key)Settings ["Application.QuitKey"].PropertyValue);
  11. Assert.Equal (
  12. Key.F6,
  13. (Key)Settings ["Application.NextTabGroupKey"].PropertyValue
  14. );
  15. Assert.Equal (
  16. Key.F6.WithShift,
  17. (Key)Settings["Application.PrevTabGroupKey"].PropertyValue
  18. );
  19. // act
  20. Settings ["Application.QuitKey"].PropertyValue = Key.Q;
  21. Settings ["Application.NextTabGroupKey"].PropertyValue = Key.F;
  22. Settings ["Application.PrevTabGroupKey"].PropertyValue = Key.B;
  23. Settings.Apply ();
  24. // assert
  25. Assert.Equal (Key.Q, Application.QuitKey);
  26. Assert.Equal (Key.F, Application.NextTabGroupKey);
  27. Assert.Equal (Key.B, Application.PrevTabGroupKey);
  28. }
  29. [Fact]
  30. [AutoInitShutdown]
  31. public void CopyUpdatedPropertiesFrom_ShouldCopyChangedPropertiesOnly ()
  32. {
  33. Settings ["Application.QuitKey"].PropertyValue = Key.End;
  34. var updatedSettings = new SettingsScope ();
  35. ///Don't set Quitkey
  36. updatedSettings ["Application.NextTabGroupKey"].PropertyValue = Key.F;
  37. updatedSettings ["Application.PrevTabGroupKey"].PropertyValue = Key.B;
  38. Settings.Update (updatedSettings);
  39. Assert.Equal (KeyCode.End, ((Key)Settings ["Application.QuitKey"].PropertyValue).KeyCode);
  40. Assert.Equal (KeyCode.F, ((Key)updatedSettings ["Application.NextTabGroupKey"].PropertyValue).KeyCode);
  41. Assert.Equal (KeyCode.B, ((Key)updatedSettings ["Application.PrevTabGroupKey"].PropertyValue).KeyCode);
  42. }
  43. [Fact]
  44. public void GetHardCodedDefaults_ShouldSetProperties ()
  45. {
  46. ConfigLocations savedLocations = Locations;
  47. Locations = ConfigLocations.DefaultOnly;
  48. Reset ();
  49. Assert.Equal (5, ((Dictionary<string, ThemeScope>)Settings ["Themes"].PropertyValue).Count);
  50. GetHardCodedDefaults ();
  51. Assert.NotEmpty (Themes);
  52. Assert.Equal ("Default", Themes.Theme);
  53. Assert.True (Settings ["Application.QuitKey"].PropertyValue is Key);
  54. Assert.True (Settings ["Application.NextTabGroupKey"].PropertyValue is Key);
  55. Assert.True (Settings ["Application.PrevTabGroupKey"].PropertyValue is Key);
  56. Assert.True (Settings ["Theme"].PropertyValue is string);
  57. Assert.Equal ("Default", Settings ["Theme"].PropertyValue as string);
  58. Assert.True (Settings ["Themes"].PropertyValue is Dictionary<string, ThemeScope>);
  59. Assert.Single ((Dictionary<string, ThemeScope>)Settings ["Themes"].PropertyValue);
  60. Locations = savedLocations;
  61. }
  62. }