SettingsScopeTests.cs 2.9 KB

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