Skip to content

Commit

Permalink
Fixes gui-cs#3356. SetupFakeDriver isn't disposing Application.Top if…
Browse files Browse the repository at this point in the history
… Application.Begin was called.
  • Loading branch information
BDisp committed Mar 28, 2024
1 parent 6070e80 commit 85e1e6c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
44 changes: 44 additions & 0 deletions UnitTests/Application/ApplicationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,4 +1088,48 @@ public void Shutdown_Resets_SyncContext ()
}

#endregion

[Fact]
[AutoInitShutdown]
public void AutoInitShutdown_Dispose_Application_Top ()
{
// This unit test is for test the SetupFakeDriver_Also_Dispose_Application_Top
// unit test. Right-click ApplicationTests on the TestExplorer and Run or Debug
// Commenting Application.Top?.Dispose (); on the SetupFakeDriverAttribute some
// of ApplicationTests unit tests will fail
var view = new View ();
var top = new Toplevel ();
top.Add (view);
Application.Begin (top);

Assert.NotNull (Application.Top);
#if DEBUG_IDISPOSABLE
Assert.False (Application.Top.WasDisposed);
#endif
}

[Fact]
[SetupFakeDriver]
public void SetupFakeDriver_Also_Dispose_Application_Top ()
{
// This unit test is for test the SetupFakeDriver_Also_Dispose_Application_Top
// unit test. Right-click ApplicationTests on the TestExplorer and Run or Debug
// Commenting Application.Top?.Dispose (); on the SetupFakeDriverAttribute some
// of ApplicationTests unit tests will fail
var exception = Record.Exception (
() =>
{
var view = new View ();
var top = new Toplevel ();
top.Add (view);
Application.Begin (top);

Assert.NotNull (Application.Top);
#if DEBUG_IDISPOSABLE
Assert.False (Application.Top.WasDisposed);
#endif
});

Assert.Null (exception);
}
}
3 changes: 3 additions & 0 deletions UnitTests/TestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ public override void After (MethodInfo methodUnderTest)
// Turn off diagnostic flags in case some test left them on
View.Diagnostics = ViewDiagnosticFlags.Off;

// Dispose Application.Top if Application.Begin was called
Application.Top?.Dispose ();

Application.Driver = null;
}

Expand Down

0 comments on commit 85e1e6c

Please sign in to comment.