Files
Terminal.Gui/UnitTests/Configuration/AppScopeTests.cs
Tig 574ed8fec7 Fixes #2469 - Revamp file structure and namespace (#2471)
* initial commit

* All tests pass

* Updated readme

* Revert "All tests pass"

This reverts commit 94ac462350.

* Revert "initial commit"

This reverts commit 36d92cc4e5.

* Moved Terminal.Gui files around

* Nuked .Graphs namespace

* Nuked .Graphs namespace

* Nuked .Trees namespace

* Nuked .Configuration namespace

* Nuked .Configuration namespace

* All tests pass

* tweaked tests

* removed unneeded usings

* re-enabled scrollview tests

* move scrollview test to ScrollViewTests

* Moved view navigation related tests to separate cs file

* Moved view scrollbarview related tests ScrollBarTestse

* Refactored View tests into smaller files

* Refactored driver tests

* Fixed a ton of BUGBUGs
2023-04-06 10:09:21 -06:00

89 lines
3.0 KiB
C#

using Xunit;
using Terminal.Gui;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.Json;
using static Terminal.Gui.ConfigurationManager;
namespace Terminal.Gui.ConfigurationTests {
public class AppScopeTests {
public static readonly JsonSerializerOptions _jsonOptions = new () {
Converters = {
//new AttributeJsonConverter (),
//new ColorJsonConverter ()
}
};
public class AppSettingsTestClass {
[SerializableConfigurationProperty (Scope = typeof (AppScope))]
public static bool? TestProperty { get; set; } = null;
}
[Fact]
public void TestNullable ()
{
AppSettingsTestClass.TestProperty = null;
Assert.Null (AppSettingsTestClass.TestProperty);
ConfigurationManager.Initialize ();
ConfigurationManager.GetHardCodedDefaults ();
ConfigurationManager.Apply ();
Assert.Null (AppSettingsTestClass.TestProperty);
AppSettingsTestClass.TestProperty = true;
ConfigurationManager.Initialize ();
ConfigurationManager.GetHardCodedDefaults ();
Assert.NotNull (AppSettingsTestClass.TestProperty);
ConfigurationManager.Apply ();
Assert.NotNull (AppSettingsTestClass.TestProperty);
}
[Fact, AutoInitShutdown]
public void Apply_ShouldApplyUpdatedProperties ()
{
ConfigurationManager.Reset ();
Assert.Null (AppSettingsTestClass.TestProperty);
Assert.NotEmpty (ConfigurationManager.AppSettings);
Assert.Null (ConfigurationManager.AppSettings ["AppSettingsTestClass.TestProperty"].PropertyValue);
AppSettingsTestClass.TestProperty = true;
ConfigurationManager.Reset ();
Assert.True (AppSettingsTestClass.TestProperty);
Assert.NotEmpty (ConfigurationManager.AppSettings);
Assert.Null (ConfigurationManager.AppSettings ["AppSettingsTestClass.TestProperty"].PropertyValue as bool?);
ConfigurationManager.AppSettings ["AppSettingsTestClass.TestProperty"].PropertyValue = false;
Assert.False (ConfigurationManager.AppSettings ["AppSettingsTestClass.TestProperty"].PropertyValue as bool?);
// ConfigurationManager.Settings should NOT apply theme settings
ConfigurationManager.Settings.Apply ();
Assert.True (AppSettingsTestClass.TestProperty);
// ConfigurationManager.Themes should NOT apply theme settings
ConfigurationManager.ThemeManager.Themes! [ThemeManager.SelectedTheme]!.Apply ();
Assert.True (AppSettingsTestClass.TestProperty);
// ConfigurationManager.AppSettings should NOT apply theme settings
ConfigurationManager.AppSettings.Apply ();
Assert.False (AppSettingsTestClass.TestProperty);
}
[Fact]
public void TestSerialize_RoundTrip ()
{
ConfigurationManager.Reset ();
var initial = ConfigurationManager.AppSettings;
var serialized = JsonSerializer.Serialize<AppScope> (ConfigurationManager.AppSettings, _jsonOptions);
var deserialized = JsonSerializer.Deserialize<AppScope> (serialized, _jsonOptions);
Assert.NotEqual (initial, deserialized);
Assert.Equal (deserialized.Count, initial.Count);
}
}
}