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

This commit is contained in:
Tig
2024-09-23 10:11:10 -06:00
parent 05ae84382d
commit 21abe095a6
2 changed files with 35 additions and 18 deletions

View File

@@ -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 ();
}
}

View File

@@ -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);
}
}
}
}