SettingsScopeTests.cs 3.2 KB

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