From 21abe095a676c64fda324e4ebc59dfb1c27b6863 Mon Sep 17 00:00:00 2001 From: Tig Date: Mon, 23 Sep 2024 10:11:10 -0600 Subject: [PATCH] Attempting to figure out unit test fails and why tests are now slow. --- UnitTests/Dialogs/MessageBoxTests.cs | 3 +- UnitTests/TestHelpers.cs | 50 ++++++++++++++++++---------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/UnitTests/Dialogs/MessageBoxTests.cs b/UnitTests/Dialogs/MessageBoxTests.cs index d538b5407..4b48fee19 100644 --- a/UnitTests/Dialogs/MessageBoxTests.cs +++ b/UnitTests/Dialogs/MessageBoxTests.cs @@ -233,6 +233,7 @@ public class MessageBoxTests }; Application.Run (top); + top.Dispose (); } [Fact] @@ -481,7 +482,7 @@ public class MessageBoxTests var top = new Toplevel (); top.BorderStyle = LineStyle.Single; Application.Run (top); - + top.Dispose (); } } diff --git a/UnitTests/TestHelpers.cs b/UnitTests/TestHelpers.cs index 70e977a29..bb76409c2 100644 --- a/UnitTests/TestHelpers.cs +++ b/UnitTests/TestHelpers.cs @@ -47,7 +47,7 @@ public class AutoInitShutdownAttribute : BeforeAfterTestAttribute bool useFakeClipboard = true, bool fakeClipboardAlwaysThrowsNotSupportedException = false, bool fakeClipboardIsSupportedAlwaysTrue = false, - ConfigurationManager.ConfigLocations configLocation = ConfigurationManager.ConfigLocations.DefaultOnly + ConfigurationManager.ConfigLocations configLocation = ConfigurationManager.ConfigLocations.None ) { AutoInit = autoInit; @@ -72,25 +72,41 @@ public class AutoInitShutdownAttribute : BeforeAfterTestAttribute if (AutoInit) { - // TODO: This Dispose call is here until all unit tests that don't correctly dispose Toplevel's they create are fixed. - Application.Top?.Dispose (); - Application.Shutdown (); + try + { + // TODO: This Dispose call is here until all unit tests that don't correctly dispose Toplevel's they create are fixed. + //Application.Top?.Dispose (); + Application.Shutdown (); #if DEBUG_IDISPOSABLE - if (Responder.Instances.Count == 0) - { - Assert.Empty (Responder.Instances); - } - else - { - Responder.Instances.Clear (); - } + if (Responder.Instances.Count == 0) + { + Assert.Empty (Responder.Instances); + } + else + { + Responder.Instances.Clear (); + } #endif - ConfigurationManager.Reset (); - - if (CM.Locations != CM.ConfigLocations.None) - { - SetCurrentConfig (_savedValues); } + catch (Exception e) + { + Assert.Fail ($"Application.Shutdown threw an exception after the test exited: {e}"); + } + finally + { +#if DEBUG_IDISPOSABLE + Responder.Instances.Clear (); + Application.ResetState (ignoreDisposed: true); +#endif + ConfigurationManager.Reset (); + + if (CM.Locations != CM.ConfigLocations.None) + { + SetCurrentConfig (_savedValues); + } + } + + } }