SettingsScopeTests.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 (KeyCode.Q | KeyCode.CtrlMask, ((Key)Settings ["Application.QuitKey"].PropertyValue).KeyCode);
  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. Assert.False ((bool)Settings ["Application.IsMouseDisabled"].PropertyValue);
  20. // act
  21. Settings ["Application.QuitKey"].PropertyValue = Key.Q;
  22. Settings ["Application.AlternateForwardKey"].PropertyValue = Key.F;
  23. Settings ["Application.AlternateBackwardKey"].PropertyValue = Key.B;
  24. Settings ["Application.IsMouseDisabled"].PropertyValue = true;
  25. Settings.Apply ();
  26. // assert
  27. Assert.Equal (KeyCode.Q, Application.QuitKey.KeyCode);
  28. Assert.Equal (KeyCode.F, Application.AlternateForwardKey.KeyCode);
  29. Assert.Equal (KeyCode.B, Application.AlternateBackwardKey.KeyCode);
  30. Assert.True (Application.IsMouseDisabled);
  31. }
  32. [Fact]
  33. [AutoInitShutdown]
  34. public void CopyUpdatedPropertiesFrom_ShouldCopyChangedPropertiesOnly ()
  35. {
  36. Settings ["Application.QuitKey"].PropertyValue = Key.End;
  37. ;
  38. var updatedSettings = new SettingsScope ();
  39. ///Don't set Quitkey
  40. updatedSettings ["Application.AlternateForwardKey"].PropertyValue = Key.F;
  41. updatedSettings ["Application.AlternateBackwardKey"].PropertyValue = Key.B;
  42. updatedSettings ["Application.IsMouseDisabled"].PropertyValue = true;
  43. Settings.Update (updatedSettings);
  44. Assert.Equal (KeyCode.End, ((Key)Settings ["Application.QuitKey"].PropertyValue).KeyCode);
  45. Assert.Equal (KeyCode.F, ((Key)updatedSettings ["Application.AlternateForwardKey"].PropertyValue).KeyCode);
  46. Assert.Equal (KeyCode.B, ((Key)updatedSettings ["Application.AlternateBackwardKey"].PropertyValue).KeyCode);
  47. Assert.True ((bool)updatedSettings ["Application.IsMouseDisabled"].PropertyValue);
  48. }
  49. [Fact]
  50. public void GetHardCodedDefaults_ShouldSetProperties ()
  51. {
  52. Reset ();
  53. Assert.Equal (3, ((Dictionary<string, ThemeScope>)Settings ["Themes"].PropertyValue).Count);
  54. GetHardCodedDefaults ();
  55. Assert.NotEmpty (Themes);
  56. Assert.Equal ("Default", Themes.Theme);
  57. Assert.True (Settings ["Application.QuitKey"].PropertyValue is Key);
  58. Assert.True (Settings ["Application.AlternateForwardKey"].PropertyValue is Key);
  59. Assert.True (Settings ["Application.AlternateBackwardKey"].PropertyValue is Key);
  60. Assert.True (Settings ["Application.IsMouseDisabled"].PropertyValue is bool);
  61. Assert.True (Settings ["Theme"].PropertyValue is string);
  62. Assert.Equal ("Default", Settings ["Theme"].PropertyValue as string);
  63. Assert.True (Settings ["Themes"].PropertyValue is Dictionary<string, ThemeScope>);
  64. Assert.Single ((Dictionary<string, ThemeScope>)Settings ["Themes"].PropertyValue);
  65. }
  66. }