Files
Terminal.Gui/UnitTests/Configuration/ThemeScopeTests.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

82 lines
2.6 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 ThemeScopeTests {
public static readonly JsonSerializerOptions _jsonOptions = new() {
Converters = {
//new AttributeJsonConverter (),
//new ColorJsonConverter ()
}
};
[Fact]
public void ThemeManager_ClassMethodsWork ()
{
ConfigurationManager.Reset ();
Assert.Equal (ConfigurationManager.ThemeManager.Instance, ConfigurationManager.Themes);
Assert.NotEmpty (ConfigurationManager.ThemeManager.Themes);
ConfigurationManager.ThemeManager.SelectedTheme = "foo";
Assert.Equal ("foo", ConfigurationManager.ThemeManager.SelectedTheme);
ConfigurationManager.ThemeManager.Reset ();
Assert.Equal (string.Empty, ConfigurationManager.ThemeManager.SelectedTheme);
Assert.Empty (ConfigurationManager.ThemeManager.Themes);
}
[Fact]
public void AllThemesPresent()
{
ConfigurationManager.Reset ();
Assert.True (ConfigurationManager.Themes.ContainsKey ("Default"));
Assert.True (ConfigurationManager.Themes.ContainsKey ("Dark"));
Assert.True (ConfigurationManager.Themes.ContainsKey ("Light"));
}
[Fact]
public void GetHardCodedDefaults_ShouldSetProperties ()
{
ConfigurationManager.Reset ();
ConfigurationManager.GetHardCodedDefaults ();
Assert.NotEmpty (ConfigurationManager.Themes);
Assert.Equal ("Default", ConfigurationManager.Themes.Theme);
}
[Fact, AutoInitShutdown]
public void Apply_ShouldApplyUpdatedProperties ()
{
ConfigurationManager.Reset ();
Assert.NotEmpty (ConfigurationManager.Themes);
Assert.Equal (Dialog.ButtonAlignments.Center, Dialog.DefaultButtonAlignment);
ConfigurationManager.Themes ["Default"] ["Dialog.DefaultButtonAlignment"].PropertyValue = Dialog.ButtonAlignments.Right;
ConfigurationManager.ThemeManager.Themes! [ThemeManager.SelectedTheme]!.Apply ();
Assert.Equal (Dialog.ButtonAlignments.Right, Dialog.DefaultButtonAlignment);
}
[Fact]
public void TestSerialize_RoundTrip ()
{
ConfigurationManager.Reset ();
var initial = ConfigurationManager.ThemeManager.Themes;
var serialized = JsonSerializer.Serialize<IDictionary<string, ThemeScope>> (ConfigurationManager.Themes, _jsonOptions);
var deserialized = JsonSerializer.Deserialize<IDictionary<string, ThemeScope>> (serialized, _jsonOptions);
Assert.NotEqual (initial, deserialized);
Assert.Equal (deserialized.Count, initial.Count);
}
}
}