Browse Source

Attempting to figure out unit test fails and why tests are now slow.

Tig 10 months ago
parent
commit
21abe095a6
2 changed files with 30 additions and 13 deletions
  1. 2 1
      UnitTests/Dialogs/MessageBoxTests.cs
  2. 28 12
      UnitTests/TestHelpers.cs

+ 2 - 1
UnitTests/Dialogs/MessageBoxTests.cs

@@ -233,6 +233,7 @@ public class MessageBoxTests
                                  };
                                  };
 
 
         Application.Run (top);
         Application.Run (top);
+        top.Dispose ();
     }
     }
 
 
     [Fact]
     [Fact]
@@ -481,7 +482,7 @@ public class MessageBoxTests
         var top = new Toplevel ();
         var top = new Toplevel ();
         top.BorderStyle = LineStyle.Single;
         top.BorderStyle = LineStyle.Single;
         Application.Run (top);
         Application.Run (top);
-
+        top.Dispose ();
     }
     }
 }
 }
 
 

+ 28 - 12
UnitTests/TestHelpers.cs

@@ -47,7 +47,7 @@ public class AutoInitShutdownAttribute : BeforeAfterTestAttribute
         bool useFakeClipboard = true,
         bool useFakeClipboard = true,
         bool fakeClipboardAlwaysThrowsNotSupportedException = false,
         bool fakeClipboardAlwaysThrowsNotSupportedException = false,
         bool fakeClipboardIsSupportedAlwaysTrue = false,
         bool fakeClipboardIsSupportedAlwaysTrue = false,
-        ConfigurationManager.ConfigLocations configLocation = ConfigurationManager.ConfigLocations.DefaultOnly
+        ConfigurationManager.ConfigLocations configLocation = ConfigurationManager.ConfigLocations.None
     )
     )
     {
     {
         AutoInit = autoInit;
         AutoInit = autoInit;
@@ -72,25 +72,41 @@ public class AutoInitShutdownAttribute : BeforeAfterTestAttribute
 
 
         if (AutoInit)
         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 DEBUG_IDISPOSABLE
-            if (Responder.Instances.Count == 0)
+                if (Responder.Instances.Count == 0)
+                {
+                    Assert.Empty (Responder.Instances);
+                }
+                else
+                {
+                    Responder.Instances.Clear ();
+                }
+#endif
+            }
+            catch (Exception e)
             {
             {
-                Assert.Empty (Responder.Instances);
+                Assert.Fail ($"Application.Shutdown threw an exception after the test exited: {e}");
             }
             }
-            else
+            finally
             {
             {
+#if DEBUG_IDISPOSABLE
                 Responder.Instances.Clear ();
                 Responder.Instances.Clear ();
-            }
+                Application.ResetState (ignoreDisposed: true);
 #endif
 #endif
-            ConfigurationManager.Reset ();
+                ConfigurationManager.Reset ();
 
 
-            if (CM.Locations != CM.ConfigLocations.None)
-            {
-                SetCurrentConfig (_savedValues);
+                if (CM.Locations != CM.ConfigLocations.None)
+                {
+                    SetCurrentConfig (_savedValues);
+                }
             }
             }
+
+
         }
         }
     }
     }