浏览代码

Trying to fix init issue in ConfigManager that was causing intermittent unit test fails

Tigger Kindel 2 年之前
父节点
当前提交
2cf7757691

+ 2 - 2
Terminal.Gui/Configuration/ConfigurationManager.cs

@@ -223,13 +223,13 @@ namespace Terminal.Gui.Configuration {
 		public static ThemeManager? Themes => ThemeManager.Instance;
 		public static ThemeManager? Themes => ThemeManager.Instance;
 
 
 		/// <summary>
 		/// <summary>
-		/// Aplication-specific configuration settings scope.
+		/// Application-specific configuration settings scope.
 		/// </summary>
 		/// </summary>
 		[SerializableConfigurationProperty (Scope = typeof (SettingsScope), OmitClassName = true), JsonPropertyName ("AppSettings")]
 		[SerializableConfigurationProperty (Scope = typeof (SettingsScope), OmitClassName = true), JsonPropertyName ("AppSettings")]
 		public static AppScope? AppSettings { get; set; }
 		public static AppScope? AppSettings { get; set; }
 
 
 		/// <summary>
 		/// <summary>
-		/// Initializes the internal state of ConfiguraitonManager. Nominally called once as part of application
+		/// Initializes the internal state of ConfigurationManager. Nominally called once as part of application
 		/// startup to initialize global state. Also called from some Unit Tests to ensure correctness (e.g. Reset()).
 		/// startup to initialize global state. Also called from some Unit Tests to ensure correctness (e.g. Reset()).
 		/// </summary>
 		/// </summary>
 		internal static void Initialize ()
 		internal static void Initialize ()

+ 7 - 7
Terminal.Gui/Configuration/ThemeScope.cs

@@ -120,21 +120,21 @@ namespace Terminal.Gui.Configuration {
 			/// </summary>
 			/// </summary>
 			public static ThemeManager Instance { get { return _instance; } }
 			public static ThemeManager Instance { get { return _instance; } }
 
 
-			private static string theme = string.Empty;
+			private static string _theme = string.Empty;
 
 
 			/// <summary>
 			/// <summary>
 			/// The currently selected theme. This is the internal version; see <see cref="Theme"/>.
 			/// The currently selected theme. This is the internal version; see <see cref="Theme"/>.
 			/// </summary>
 			/// </summary>
 			[JsonInclude, SerializableConfigurationProperty (Scope = typeof (SettingsScope), OmitClassName = true), JsonPropertyName ("Theme")]
 			[JsonInclude, SerializableConfigurationProperty (Scope = typeof (SettingsScope), OmitClassName = true), JsonPropertyName ("Theme")]
 			internal static string SelectedTheme {
 			internal static string SelectedTheme {
-				get => theme;
+				get => _theme;
 				set {
 				set {
-					var oldTheme = theme;
-					theme = value;
-					if (oldTheme != theme &&
+					var oldTheme = _theme;
+					_theme = value;
+					if (oldTheme != _theme &&
 						ConfigurationManager.Settings! ["Themes"]?.PropertyValue is Dictionary<string, ThemeScope> themes &&
 						ConfigurationManager.Settings! ["Themes"]?.PropertyValue is Dictionary<string, ThemeScope> themes &&
-						themes.ContainsKey (theme)) {
-						ConfigurationManager.Settings! ["Theme"].PropertyValue = theme;
+						themes.ContainsKey (_theme)) {
+						ConfigurationManager.Settings! ["Theme"].PropertyValue = _theme;
 						Instance.OnThemeChanged (oldTheme);
 						Instance.OnThemeChanged (oldTheme);
 					}
 					}
 				}
 				}

+ 4 - 4
UnitTests/Configuration/ConfigurationMangerTests.cs

@@ -182,12 +182,13 @@ namespace Terminal.Gui.ConfigurationTests {
 		/// Save the `config.json` file; this can be used to update the file in `Terminal.Gui.Resources.config.json'.
 		/// Save the `config.json` file; this can be used to update the file in `Terminal.Gui.Resources.config.json'.
 		/// </summary>
 		/// </summary>
 		/// <remarks>
 		/// <remarks>
-		/// IMPORTANT: For the file generated to be valid, this must be the ONLY test run. Conifg Properties
-		/// are all satic and thus can be overwritten by other tests.</remarks>
+		/// IMPORTANT: For the file generated to be valid, this must be the ONLY test run. Config Properties
+		/// are all static and thus can be overwritten by other tests.</remarks>
 		[Fact]
 		[Fact]
 		public void SaveDefaults ()
 		public void SaveDefaults ()
 		{
 		{
 			ConfigurationManager.Initialize ();
 			ConfigurationManager.Initialize ();
+			ConfigurationManager.Reset ();
 
 
 			// Get the hard coded settings
 			// Get the hard coded settings
 			ConfigurationManager.GetHardCodedDefaults ();
 			ConfigurationManager.GetHardCodedDefaults ();
@@ -316,12 +317,11 @@ namespace Terminal.Gui.ConfigurationTests {
 		[Fact, AutoInitShutdown]
 		[Fact, AutoInitShutdown]
 		public void TestConfigurationManagerToJson ()
 		public void TestConfigurationManagerToJson ()
 		{
 		{
+			ConfigurationManager.Reset ();
 			ConfigurationManager.GetHardCodedDefaults ();
 			ConfigurationManager.GetHardCodedDefaults ();
 			var stream = ConfigurationManager.ToStream ();
 			var stream = ConfigurationManager.ToStream ();
-
 			
 			
 			ConfigurationManager.Settings.Update (stream, "TestConfigurationManagerToJson");
 			ConfigurationManager.Settings.Update (stream, "TestConfigurationManagerToJson");
-
 		}
 		}
 
 
 		[Fact, AutoInitShutdown (configLocation: ConfigLocations.None)]
 		[Fact, AutoInitShutdown (configLocation: ConfigLocations.None)]