mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Fixed unit tests
This commit is contained in:
@@ -166,7 +166,7 @@ public class ConfigurationManagerTests
|
||||
fired = true;
|
||||
|
||||
// assert
|
||||
Assert.Equal (KeyCode.Q | KeyCode.CtrlMask, ((Key)Settings ["Application.QuitKey"].PropertyValue).KeyCode);
|
||||
Assert.Equal (Key.Esc, ((Key)Settings ["Application.QuitKey"].PropertyValue).KeyCode);
|
||||
|
||||
Assert.Equal (
|
||||
KeyCode.PageDown | KeyCode.CtrlMask,
|
||||
@@ -250,7 +250,7 @@ public class ConfigurationManagerTests
|
||||
// assert
|
||||
Assert.NotEmpty (Themes);
|
||||
Assert.Equal ("Default", Themes.Theme);
|
||||
Assert.Equal (KeyCode.Q | KeyCode.CtrlMask, Application.QuitKey.KeyCode);
|
||||
Assert.Equal (Key.Esc, Application.QuitKey);
|
||||
Assert.Equal (KeyCode.PageDown | KeyCode.CtrlMask, Application.AlternateForwardKey.KeyCode);
|
||||
Assert.Equal (KeyCode.PageUp | KeyCode.CtrlMask, Application.AlternateBackwardKey.KeyCode);
|
||||
Assert.False (Application.IsMouseDisabled);
|
||||
@@ -271,7 +271,7 @@ public class ConfigurationManagerTests
|
||||
// assert
|
||||
Assert.NotEmpty (Themes);
|
||||
Assert.Equal ("Default", Themes.Theme);
|
||||
Assert.Equal (KeyCode.Q | KeyCode.CtrlMask, Application.QuitKey.KeyCode);
|
||||
Assert.Equal (KeyCode.Esc, Application.QuitKey.KeyCode);
|
||||
Assert.Equal (KeyCode.PageDown | KeyCode.CtrlMask, Application.AlternateForwardKey.KeyCode);
|
||||
Assert.Equal (KeyCode.PageUp | KeyCode.CtrlMask, Application.AlternateBackwardKey.KeyCode);
|
||||
Assert.False (Application.IsMouseDisabled);
|
||||
@@ -436,9 +436,6 @@ public class ConfigurationManagerTests
|
||||
public void TestConfigurationManagerInitDriver ()
|
||||
{
|
||||
Assert.Equal ("Default", Themes.Theme);
|
||||
Assert.True (Themes.ContainsKey ("Default"));
|
||||
|
||||
Assert.Equal (KeyCode.Q | KeyCode.CtrlMask, Application.QuitKey.KeyCode);
|
||||
|
||||
Assert.Equal (new Color (Color.White), Colors.ColorSchemes ["Base"].Normal.Foreground);
|
||||
Assert.Equal (new Color (Color.Blue), Colors.ColorSchemes ["Base"].Normal.Background);
|
||||
@@ -804,7 +801,7 @@ public class ConfigurationManagerTests
|
||||
|
||||
Settings.Update (json, "TestConfigurationManagerUpdateFromJson");
|
||||
|
||||
Assert.Equal (KeyCode.Q | KeyCode.CtrlMask, Application.QuitKey.KeyCode);
|
||||
Assert.Equal (KeyCode.Esc, Application.QuitKey.KeyCode);
|
||||
Assert.Equal (KeyCode.Z | KeyCode.AltMask, ((Key)Settings ["Application.QuitKey"].PropertyValue).KeyCode);
|
||||
|
||||
Assert.Equal ("Default", Themes.Theme);
|
||||
|
||||
@@ -9,7 +9,7 @@ public class SettingsScopeTests
|
||||
public void Apply_ShouldApplyProperties ()
|
||||
{
|
||||
// arrange
|
||||
Assert.Equal (KeyCode.Q | KeyCode.CtrlMask, ((Key)Settings ["Application.QuitKey"].PropertyValue).KeyCode);
|
||||
Assert.Equal (Key.Esc, (Key)Settings ["Application.QuitKey"].PropertyValue);
|
||||
|
||||
Assert.Equal (
|
||||
KeyCode.PageDown | KeyCode.CtrlMask,
|
||||
|
||||
@@ -7,8 +7,6 @@ namespace UICatalog.Tests;
|
||||
|
||||
public class ScenarioTests : TestsAllViews
|
||||
{
|
||||
private readonly ITestOutputHelper _output;
|
||||
|
||||
public ScenarioTests (ITestOutputHelper output)
|
||||
{
|
||||
#if DEBUG_IDISPOSABLE
|
||||
@@ -17,11 +15,7 @@ public class ScenarioTests : TestsAllViews
|
||||
_output = output;
|
||||
}
|
||||
|
||||
public static IEnumerable<object []> AllScenarioTypes =>
|
||||
typeof (Scenario).Assembly
|
||||
.GetTypes ()
|
||||
.Where (type => type.IsClass && !type.IsAbstract && type.IsSubclassOf (typeof (Scenario)))
|
||||
.Select (type => new object [] { type });
|
||||
private readonly ITestOutputHelper _output;
|
||||
|
||||
private object _timeoutLock;
|
||||
|
||||
@@ -34,17 +28,17 @@ public class ScenarioTests : TestsAllViews
|
||||
public void All_Scenarios_Quit_And_Init_Shutdown_Properly (Type scenarioType)
|
||||
{
|
||||
Assert.Null (_timeoutLock);
|
||||
_timeoutLock = new object ();
|
||||
_timeoutLock = new ();
|
||||
|
||||
// If a previous test failed, this will ensure that the Application is in a clean state
|
||||
Application.ResetState (true);
|
||||
|
||||
_output.WriteLine ($"Running Scenario '{scenarioType}'");
|
||||
Scenario scenario = (Scenario)Activator.CreateInstance (scenarioType);
|
||||
var scenario = (Scenario)Activator.CreateInstance (scenarioType);
|
||||
|
||||
uint abortTime = 1500;
|
||||
bool initialized = false;
|
||||
bool shutdown = false;
|
||||
var initialized = false;
|
||||
var shutdown = false;
|
||||
object timeout = null;
|
||||
|
||||
Application.InitializedChanged += OnApplicationOnInitializedChanged;
|
||||
@@ -65,7 +59,6 @@ public class ScenarioTests : TestsAllViews
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Assert.True (initialized);
|
||||
Assert.True (shutdown);
|
||||
|
||||
@@ -80,24 +73,19 @@ public class ScenarioTests : TestsAllViews
|
||||
|
||||
return;
|
||||
|
||||
|
||||
void OnApplicationOnInitializedChanged (object s, StateEventArgs<bool> a)
|
||||
{
|
||||
if (a.NewValue)
|
||||
{
|
||||
Assert.Equal (Key.Q.WithCtrl, Application.QuitKey);
|
||||
|
||||
Application.Iteration += OnApplicationOnIteration;
|
||||
initialized = true;
|
||||
|
||||
lock (_timeoutLock)
|
||||
{
|
||||
timeout = Application.AddTimeout (TimeSpan.FromMilliseconds (abortTime), ForceCloseCallback);
|
||||
}
|
||||
|
||||
_output.WriteLine ($"Initialized '{Application.Driver}'");
|
||||
//Dictionary<Key, List<View>> bindings = Application.GetKeyBindings ();
|
||||
//Assert.NotEmpty (bindings);
|
||||
//_output.WriteLine ($"bindings: {string.Join (",", bindings.Keys)}");
|
||||
//Assert.True (bindings.ContainsKey (Application.QuitKey));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -116,10 +104,12 @@ public class ScenarioTests : TestsAllViews
|
||||
timeout = null;
|
||||
}
|
||||
}
|
||||
|
||||
Assert.Fail (
|
||||
$"'{scenario.GetName ()}' failed to Quit with {Application.QuitKey} after {abortTime}ms. Force quit.");
|
||||
|
||||
Application.ResetState (true);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -134,6 +124,12 @@ public class ScenarioTests : TestsAllViews
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<object []> AllScenarioTypes =>
|
||||
typeof (Scenario).Assembly
|
||||
.GetTypes ()
|
||||
.Where (type => type.IsClass && !type.IsAbstract && type.IsSubclassOf (typeof (Scenario)))
|
||||
.Select (type => new object [] { type });
|
||||
|
||||
[Fact]
|
||||
public void Run_All_Views_Tester_Scenario ()
|
||||
{
|
||||
@@ -563,7 +559,7 @@ public class ScenarioTests : TestsAllViews
|
||||
&& view.GetType ().GetProperty ("Source") != null
|
||||
&& view.GetType ().GetProperty ("Source").PropertyType == typeof (IListDataSource))
|
||||
{
|
||||
var source = new ListWrapper<string> (["Test Text #1", "Test Text #2", "Test Text #3"]);
|
||||
ListWrapper<string> source = new (["Test Text #1", "Test Text #2", "Test Text #3"]);
|
||||
view?.GetType ().GetProperty ("Source")?.GetSetMethod ()?.Invoke (view, new [] { source });
|
||||
}
|
||||
|
||||
@@ -637,8 +633,7 @@ public class ScenarioTests : TestsAllViews
|
||||
|
||||
Application.KeyDown += (sender, args) =>
|
||||
{
|
||||
// See #2474 for why this is commented out
|
||||
Assert.Equal (KeyCode.CtrlMask | KeyCode.Q, args.KeyCode);
|
||||
Assert.Equal (Application.QuitKey, args.KeyCode);
|
||||
};
|
||||
|
||||
generic.Main ();
|
||||
|
||||
@@ -797,6 +797,8 @@ public class ToplevelTests (ITestOutputHelper output)
|
||||
Key alternateBackwardKey = KeyCode.Null;
|
||||
Key quitKey = KeyCode.Null;
|
||||
|
||||
Key previousQuitKey = Application.QuitKey;
|
||||
|
||||
Toplevel top = new ();
|
||||
var view = new View ();
|
||||
view.Initialized += View_Initialized;
|
||||
@@ -819,7 +821,7 @@ public class ToplevelTests (ITestOutputHelper output)
|
||||
|
||||
Assert.Equal (KeyCode.PageDown | KeyCode.CtrlMask, Application.AlternateForwardKey);
|
||||
Assert.Equal (KeyCode.PageUp | KeyCode.CtrlMask, Application.AlternateBackwardKey);
|
||||
Assert.Equal (KeyCode.Q | KeyCode.CtrlMask, Application.QuitKey);
|
||||
Assert.Equal (Key.Esc, Application.QuitKey);
|
||||
|
||||
Application.AlternateForwardKey = KeyCode.A;
|
||||
Application.AlternateBackwardKey = KeyCode.B;
|
||||
@@ -827,7 +829,7 @@ public class ToplevelTests (ITestOutputHelper output)
|
||||
|
||||
Assert.Equal (KeyCode.PageDown | KeyCode.CtrlMask, alternateForwardKey);
|
||||
Assert.Equal (KeyCode.PageUp | KeyCode.CtrlMask, alternateBackwardKey);
|
||||
Assert.Equal (KeyCode.Q | KeyCode.CtrlMask, quitKey);
|
||||
Assert.Equal (previousQuitKey, quitKey);
|
||||
|
||||
Assert.Equal (KeyCode.A, Application.AlternateForwardKey);
|
||||
Assert.Equal (KeyCode.B, Application.AlternateBackwardKey);
|
||||
@@ -836,11 +838,11 @@ public class ToplevelTests (ITestOutputHelper output)
|
||||
// Replacing the defaults keys to avoid errors on others unit tests that are using it.
|
||||
Application.AlternateForwardKey = Key.PageDown.WithCtrl;
|
||||
Application.AlternateBackwardKey = Key.PageUp.WithCtrl;
|
||||
Application.QuitKey = Key.Q.WithCtrl;
|
||||
Application.QuitKey = previousQuitKey;
|
||||
|
||||
Assert.Equal (KeyCode.PageDown | KeyCode.CtrlMask, Application.AlternateForwardKey);
|
||||
Assert.Equal (KeyCode.PageUp | KeyCode.CtrlMask, Application.AlternateBackwardKey);
|
||||
Assert.Equal (KeyCode.Q | KeyCode.CtrlMask, Application.QuitKey);
|
||||
Assert.Equal (previousQuitKey, Application.QuitKey);
|
||||
top.Dispose ();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user