|
@@ -30,63 +30,75 @@ public class ScenarioTests : TestsAllViews
|
|
|
/// </summary>
|
|
|
[Theory]
|
|
|
[MemberData (nameof (AllScenarioTypes))]
|
|
|
- public void Run_All_Scenarios (Type scenarioType)
|
|
|
+ public void All_Scenarios_Quit_And_Init_Shutdown_Properly (Type scenarioType)
|
|
|
{
|
|
|
+ Application.ResetState (true);
|
|
|
+
|
|
|
_output.WriteLine ($"Running Scenario '{scenarioType}'");
|
|
|
|
|
|
Scenario scenario = (Scenario)Activator.CreateInstance (scenarioType);
|
|
|
|
|
|
- // BUGBUG: Scenario.Main is supposed to call Init. This is a workaround for now.
|
|
|
- // BUGBUG: To be able to test Scenarios we need Application to have an event like "Application.Started"
|
|
|
- // BUGBUG: That tests like this could subscribe to.
|
|
|
- Application.Init (new FakeDriver ());
|
|
|
+ uint abortTime = 500;
|
|
|
|
|
|
- // Press QuitKey
|
|
|
- Assert.Empty (FakeConsole.MockKeyPresses);
|
|
|
+ bool initialized = false;
|
|
|
+ bool shutdown = false;
|
|
|
|
|
|
- FakeConsole.PushMockKeyPress ((KeyCode)Application.QuitKey);
|
|
|
+ object timeout = null;
|
|
|
|
|
|
- uint abortTime = 500;
|
|
|
+ Application.InitializedChanged += (s, a) =>
|
|
|
+ {
|
|
|
+ if (a.NewValue)
|
|
|
+ {
|
|
|
+ //output.WriteLine ($" Add timeout to force quit after {abortTime}ms");
|
|
|
+ timeout = Application.AddTimeout (TimeSpan.FromMilliseconds (abortTime), ForceCloseCallback);
|
|
|
+
|
|
|
+ Application.Iteration += OnApplicationOnIteration;
|
|
|
+ initialized = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (timeout is { })
|
|
|
+ {
|
|
|
+ Application.RemoveTimeout (timeout);
|
|
|
+ timeout = null;
|
|
|
+ }
|
|
|
+ Application.Iteration -= OnApplicationOnIteration;
|
|
|
+ shutdown = true;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ scenario.Main ();
|
|
|
+ scenario.Dispose ();
|
|
|
+
|
|
|
+ Assert.True (initialized);
|
|
|
+ Assert.True (shutdown);
|
|
|
+
|
|
|
+#if DEBUG_IDISPOSABLE
|
|
|
+ Assert.Empty (Responder.Instances);
|
|
|
+#endif
|
|
|
+
|
|
|
+ return;
|
|
|
|
|
|
// If the scenario doesn't close within 500ms, this will force it to quit
|
|
|
bool ForceCloseCallback ()
|
|
|
{
|
|
|
- if (Application.Top.Running && FakeConsole.MockKeyPresses.Count == 0)
|
|
|
+ if (timeout is { })
|
|
|
{
|
|
|
- Application.RequestStop ();
|
|
|
-
|
|
|
- // See #2474 for why this is commented out
|
|
|
- Assert.Fail (
|
|
|
- $"'{scenario.GetName ()}' failed to Quit with {Application.QuitKey} after {abortTime}ms. Force quit.");
|
|
|
+ Application.RemoveTimeout (timeout);
|
|
|
+ timeout = null;
|
|
|
}
|
|
|
+ Application.ResetState (true);
|
|
|
+ Assert.Fail (
|
|
|
+ $"'{scenario.GetName ()}' failed to Quit with {Application.QuitKey} after {abortTime}ms. Force quit.");
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- //output.WriteLine ($" Add timeout to force quit after {abortTime}ms");
|
|
|
- _ = Application.AddTimeout (TimeSpan.FromMilliseconds (abortTime), ForceCloseCallback);
|
|
|
-
|
|
|
- Application.Iteration += (s, a) =>
|
|
|
- {
|
|
|
- // Press QuitKey
|
|
|
- Assert.Empty (FakeConsole.MockKeyPresses);
|
|
|
- FakeConsole.PushMockKeyPress ((KeyCode)Application.QuitKey);
|
|
|
-
|
|
|
- //output.WriteLine ($" iteration {++iterations}");
|
|
|
- if (Application.Top.Running && FakeConsole.MockKeyPresses.Count == 0)
|
|
|
- {
|
|
|
- Application.RequestStop ();
|
|
|
- Assert.Fail ($"'{scenario.GetName ()}' failed to Quit with {Application.QuitKey}. Force quit.");
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- scenario.Main ();
|
|
|
- scenario.Dispose ();
|
|
|
-
|
|
|
- Application.Shutdown ();
|
|
|
-#if DEBUG_IDISPOSABLE
|
|
|
- Assert.Empty (Responder.Instances);
|
|
|
-#endif
|
|
|
+ void OnApplicationOnIteration (object s, IterationEventArgs a)
|
|
|
+ {
|
|
|
+ // Press QuitKey
|
|
|
+ Application.OnKeyDown (Application.QuitKey);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
[Fact]
|