Fixes #2923. Ensures only clear Instances if they really was disposed. (#2924)

* Fixes #2923. Ensures only clear Instances if they really was disposed and fix unit tests.

* Add Ubuntu-20.04.

* xunit nuget package update.
This commit is contained in:
BDisp
2023-10-20 18:13:55 +01:00
committed by GitHub
parent 56a31f1a92
commit 8ea6b105fc
8 changed files with 54 additions and 45 deletions

View File

@@ -62,10 +62,13 @@ public class AutoInitShutdownAttribute : Xunit.Sdk.BeforeAfterTestAttribute {
{
Debug.WriteLine ($"Before: {methodUnderTest.Name}");
if (AutoInit) {
#if DEBUG_IDISPOSABLE && FORCE_RESPONDER_DISPOSE
#if DEBUG_IDISPOSABLE
// Clear out any lingering Responder instances from previous tests
Responder.Instances.Clear ();
Assert.Equal (0, Responder.Instances.Count);
if (Responder.Instances.Count == 0) {
Assert.Empty (Responder.Instances);
} else {
Responder.Instances.Clear ();
}
#endif
Application.Init ((ConsoleDriver)Activator.CreateInstance (_driverType));
}
@@ -76,8 +79,12 @@ public class AutoInitShutdownAttribute : Xunit.Sdk.BeforeAfterTestAttribute {
Debug.WriteLine ($"After: {methodUnderTest.Name}");
if (AutoInit) {
Application.Shutdown ();
#if DEBUG_IDISPOSABLE && FORCE_RESPONDER_DISPOSE
Assert.Equal (0, Responder.Instances.Count);
#if DEBUG_IDISPOSABLE
if (Responder.Instances.Count == 0) {
Assert.Empty (Responder.Instances);
} else {
Responder.Instances.Clear ();
}
#endif
}
}
@@ -104,9 +111,7 @@ public class TestRespondersDisposed : Xunit.Sdk.BeforeAfterTestAttribute {
{
Debug.WriteLine ($"After: {methodUnderTest.Name}");
#if DEBUG_IDISPOSABLE
#pragma warning disable xUnit2013 // Do not use equality check to check for collection size.
Assert.Equal (0, Responder.Instances.Count);
#pragma warning restore xUnit2013 // Do not use equality check to check for collection size.
Assert.Empty (Responder.Instances);
#endif
}
}