mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* Move all public nested classes out into own files * Move more nested classes out * Tidy up and treat CA1034 as an error. Fix remaining nested classes. * Remove partial keyword from ThemeManager as it is no longer needed * Rename Bar to BarSeriesBar to more clearly indicate it is part of GraphView subsystem * Fix xmldoc references * Revert nesting changes to ConsoleDrivers * Change to file scoped namespaces and revert renames - LineCanvasCell back to just Cell - ApplicationRunState back to just RunState * Switch to file scoped namespaces
81 lines
2.4 KiB
C#
81 lines
2.4 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 (ThemeManager.Instance, ConfigurationManager.Themes);
|
|
Assert.NotEmpty (ThemeManager.Themes);
|
|
|
|
ThemeManager.SelectedTheme = "foo";
|
|
Assert.Equal ("foo", ThemeManager.SelectedTheme);
|
|
ThemeManager.Reset ();
|
|
Assert.Equal (string.Empty, ThemeManager.SelectedTheme);
|
|
|
|
Assert.Empty (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;
|
|
|
|
ThemeManager.Themes! [ThemeManager.SelectedTheme]!.Apply ();
|
|
Assert.Equal (Dialog.ButtonAlignments.Right, Dialog.DefaultButtonAlignment);
|
|
}
|
|
|
|
|
|
[Fact]
|
|
public void TestSerialize_RoundTrip ()
|
|
{
|
|
ConfigurationManager.Reset ();
|
|
|
|
var initial = 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);
|
|
}
|
|
}
|
|
} |