Files
Terminal.Gui/Tests/UnitTests/Application/ApplicationImplTests.cs
Copilot e6a0ec64ca Fixes #4361 - Consolidate FakeDriver into library and refactor driver architecture (#4362)
* Initial plan

* Add ScreenChanged event, SetScreenSize method, and fix FakeDriver buffer initialization

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Add comprehensive tests for ScreenChanged event and buffer integrity

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Replace obsolete SizeChanged usage with ScreenChanged in core and tests

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Refactor terminal size event handling

Replaced `ScreenChanged` with `SizeChanged` across the codebase to standardize naming and improve clarity. Updated event handling logic, including subscriptions, unsubscriptions, and raising methods. Removed deprecated `ScreenChanged` event and backward compatibility code.

Refactored driver initialization to handle legacy `IConsoleDriver` types separately. Updated tests and mock implementations to align with the new `SizeChanged` event. Improved documentation and comments to reflect these changes.

These updates enhance maintainability, consistency, and modernize the architecture.

* Refactor & Code Cleanup: Replace IWindowSizeMonitor with IConsoleSizeMonitor

Renamed `IWindowSizeMonitor` to `IConsoleSizeMonitor` across the codebase, updating all references, method signatures, and event handlers. Replaced the `WindowSizeMonitor` class with the new `ConsoleSizeMonitor` implementation, which includes improved terminal size change handling via the `Poll` method.

Enabled nullable reference types in several files to enhance code safety. Updated test cases to reflect the new `IConsoleSizeMonitor` interface. Removed redundant code, simplified null checks, and corrected minor typos in comments. Streamlined the codebase by removing the obsolete `WindowSizeMonitor` class and its interface.

* Code cleanup - Refactor and enhance ShadowView and FakeDriverTests

Updated ShadowView.cs to use null-conditional operators and added null checks for safer access to `ScreenContents`. Refined XML documentation in View.Layout.cs for clarity and consistency.

Refactored FakeDriverTests.cs to leverage modern C# features, including shorthand object instantiation, inline lambdas, and tuple-like syntax for `Size` and `Rectangle`. Removed redundant tests and improved test readability and reliability.

Enhanced error handling with null checks and ensured backward compatibility for deprecated events. Improved test coverage for resizing, clipboard operations, and invalid coordinates. Verified buffer integrity and screen updates after resizing.

General improvements include replacing explicit type declarations with `var`, removing unused imports, and aligning code formatting for better readability.

Refactor and improve code quality and test coverage

Updated `ShadowView` for null safety using null-conditional operators. Simplified object initializations and modernized syntax across the codebase, including shorthand initializations and inline lambdas. Enhanced event handling logic and ensured compatibility with obsolete members.

Refactored `FakeDriverTests` by removing redundant code, standardizing formatting, and improving test setup. Suppressed obsolete warnings where necessary. Improved XML documentation in `View.Layout.cs` for clarity and removed outdated references.

Performed general cleanup, including removing unused namespaces, redundant comments, and ensuring consistent formatting. These changes enhance readability, maintainability, and runtime safety.

* Code cleanup

Refactor TimedEventsTests for readability and consistency

Improved code readability and maintainability:
- Enabled nullable reference types with `#nullable enable`.
- Removed unused `using System.Diagnostics;`.
- Updated namespace to `UnitTests.ApplicationTests`.
- Replaced `Terminal.Gui.App.TimedEvents` with `TimedEvents`.
- Reformatted XML documentation comments for alignment.
- Used `var` and target-typed new expressions for consistency.
- Reformatted `Parallel.For` loops and lambdas for clarity.
- Added `Thread.Sleep(10)` to prevent excessive CPU usage in tests.
- Improved assertions and event handler formatting in tests.

Aligned with modern C# coding practices.

* Code Cleanup - No more driver warnings.

Refactor codebase and introduce FakeClipboard

- Adjusted `.editorconfig` to change severity levels for CS0612, CS0618, and CS0672 diagnostics.
- Replaced `FakeDriver.FakeClipboard` with a new `FakeClipboard` class for testing purposes, supporting exception handling and clipboard data manipulation.
- Removed redundant methods (`MakeColor`, `MapKey`) and unused classes (`MockConsoleDriver`) to streamline the codebase.
- Refactored `ConsoleDriverFacade` and `FakeDriver` to simplify logic and improve maintainability.
- Updated tests to use `CreateFakeDriver` and removed or commented out obsolete tests.
- Reformatted and cleaned up code for readability across multiple files.

* Refactor FakeDriver - Code Cleanup

Standardized console size management by replacing `WindowSizeMonitor` with `ConsoleSizeMonitor` across the codebase. Updated methods `GetWindowSize` and `SetWindowSize` to `GetSize` and `SetSize` for consistency.

Refactored `FakeDriver` to use `SetScreenSize` and removed redundant methods. Simplified driver initialization by removing legacy `InternalInit` logic.

Standardized ANSI escape sequences by replacing `CSI_ReportTerminalSizeInChars` with `CSI_ReportWindowSizeInChars`.

Updated test cases to align with the new `ConsoleSizeMonitor` and `SetScreenSize` methods. Removed obsolete test utilities like `FakeSizeMonitor` and `FakeWindowSizeMonitor`.

Performed general code cleanup, including removing unused classes, redundant code, and improving formatting. Fixed resizing logic issues and improved exception handling in driver methods.

* Update Terminal.Gui/Drivers/OutputBuffer.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update Terminal.Gui/Drivers/MouseButtonStateEx.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update Terminal.Gui/App/MainLoop/IApplicationMainLoop.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update Tests/UnitTests/Views/ToplevelTests.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update Terminal.Gui/ViewBase/View.Layout.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Moved all Drawing tests to Paralleizable - proving Fakedriver works

Enhanced `Ruler` and `Thickness` classes by adding an optional `IConsoleDriver? driver` parameter to decouple rendering from the default `Application.Driver`, improving flexibility and testability. Updated `DriverAssert` to support nullable drivers and added defensive checks.

Refactored and expanded test cases for `Ruler`, `Thickness`, `LineCanvas`, and `StraightLineExtensions` to ensure comprehensive coverage, including zero-length intersections, line rendering, and exclusion logic. Migrated rendering-dependent tests to a parallelizable namespace.

Removed redundant tests, improved naming conventions, and updated documentation for better maintainability and clarity.

* Fixed Run<T> startup hang.

Refactor: Simplify driver logic and update SetSize methods

Removed FakeDriver safeguard in unit tests to simplify
CreateDriver logic. Updated SetSize methods in NetOutput,
UnixOutput, and WindowsOutput to do nothing instead of
throwing NotImplementedException. Modified SizeChanged
event in ConsoleDriverFacade to call SetScreenSize directly.
Commented out unnecessary debug validation in DimAuto.
These changes improve maintainability and reduce complexity.

* Fixed intermittent unit test bug.

Refactored `_cachedRunStateToplevel` to `CachedRunStateToplevel` as an internal static property, delegating its management to `ApplicationImpl` for improved encapsulation. Updated all references to use the new property and centralized its handling in `ApplicationImpl`.

Removed the `MouseGrabHandler` property from `ApplicationImpl` and simplified driver-related assignments by replacing `Application.ForceDriver` and `Application.Screen` with direct references.

Reset `CachedRunStateToplevel` during cleanup to ensure proper state management. Updated the `Invoke` method to use `Top` directly, aligning with the refactored design. Improved debug assertions and performed general cleanup to enhance code readability and maintainability.

* Fixed intermittent bug an massive code cleanup of warnings.

Refactor and enhance codebase for maintainability

- Applied null-conditional operator (`!`) to improve null-safety.
- Refactored tests for clarity, added new cases, and removed redundancies.
- Introduced `FakeApplicationFactory` and `FakeSizeMonitor` for testing.
- Removed unused code, including legacy `DecodeEscSeq` logic.
- Reformatted code for readability and consistency.
- Updated assertions for more accurate validation in tests.
- Fixed potential null reference issues across multiple files.
- Improved event handling with proper null checks.
- Enhanced documentation for new classes and methods.
- Modernized code with C# features like `record struct` and `nullable enable`.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Co-authored-by: Tig <tig@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-10-27 23:34:14 -06:00

635 lines
21 KiB
C#

#nullable enable
using System.Collections.Concurrent;
using System.Runtime.CompilerServices;
using Microsoft.Extensions.Logging;
using Moq;
using TerminalGuiFluentTesting;
namespace UnitTests.ApplicationTests;
public class ApplicationImplTests
{
public ApplicationImplTests ()
{
ConsoleDriver.RunningUnitTests = true;
}
private ApplicationImpl NewApplicationImpl (TestDriver driver = TestDriver.DotNet)
{
if (driver == TestDriver.DotNet)
{
var netInput = new Mock<INetInput> ();
SetupRunInputMockMethodToBlock (netInput);
var m = new Mock<IComponentFactory<ConsoleKeyInfo>> ();
m.Setup (f => f.CreateInput ()).Returns (netInput.Object);
m.Setup (f => f.CreateInputProcessor (It.IsAny<ConcurrentQueue<ConsoleKeyInfo>> ())).Returns (Mock.Of <IInputProcessor> ());
m.Setup (f => f.CreateOutput ()).Returns (Mock.Of<IConsoleOutput> ());
m.Setup (f => f.CreateConsoleSizeMonitor (It.IsAny<IConsoleOutput> (),It.IsAny<IOutputBuffer> ())).Returns (Mock.Of<IConsoleSizeMonitor> ());
return new (m.Object);
}
else
{
var winInput = new Mock<IConsoleInput<WindowsConsole.InputRecord>> ();
SetupRunInputMockMethodToBlock (winInput);
var m = new Mock<IComponentFactory<WindowsConsole.InputRecord>> ();
m.Setup (f => f.CreateInput ()).Returns (winInput.Object);
m.Setup (f => f.CreateInputProcessor (It.IsAny<ConcurrentQueue<WindowsConsole.InputRecord>> ())).Returns (Mock.Of<IInputProcessor> ());
m.Setup (f => f.CreateOutput ()).Returns (Mock.Of<IConsoleOutput> ());
m.Setup (f => f.CreateConsoleSizeMonitor (It.IsAny<IConsoleOutput> (), It.IsAny<IOutputBuffer> ())).Returns (Mock.Of<IConsoleSizeMonitor> ());
return new (m.Object);
}
}
[Fact]
public void Init_CreatesKeybindings ()
{
var orig = ApplicationImpl.Instance;
var v2 = NewApplicationImpl ();
ApplicationImpl.ChangeInstance (v2);
Application.KeyBindings.Clear ();
Assert.Empty (Application.KeyBindings.GetBindings ());
v2.Init ();
Assert.NotEmpty (Application.KeyBindings.GetBindings ());
v2.Shutdown ();
ApplicationImpl.ChangeInstance (orig);
}
[Fact]
public void Init_DriverIsFacade ()
{
var orig = ApplicationImpl.Instance;
var v2 = NewApplicationImpl ();
ApplicationImpl.ChangeInstance (v2);
Assert.Null (Application.Driver);
v2.Init ();
Assert.NotNull (Application.Driver);
var type = Application.Driver.GetType ();
Assert.True (type.IsGenericType);
Assert.True (type.GetGenericTypeDefinition () == typeof (ConsoleDriverFacade<>));
v2.Shutdown ();
Assert.Null (Application.Driver);
ApplicationImpl.ChangeInstance (orig);
}
/*
[Fact]
public void Init_ExplicitlyRequestWin ()
{
var orig = ApplicationImpl.Instance;
Assert.Null (Application.Driver);
var netInput = new Mock<INetInput> (MockBehavior.Strict);
var netOutput = new Mock<IConsoleOutput> (MockBehavior.Strict);
var winInput = new Mock<IWindowsInput> (MockBehavior.Strict);
var winOutput = new Mock<IConsoleOutput> (MockBehavior.Strict);
winInput.Setup (i => i.Initialize (It.IsAny<ConcurrentQueue<WindowsConsole.InputRecord>> ()))
.Verifiable (Times.Once);
SetupRunInputMockMethodToBlock (winInput);
winInput.Setup (i => i.Dispose ())
.Verifiable (Times.Once);
winOutput.Setup (i => i.Dispose ())
.Verifiable (Times.Once);
var v2 = new ApplicationV2 (
() => netInput.Object,
() => netOutput.Object,
() => winInput.Object,
() => winOutput.Object);
ApplicationImpl.ChangeInstance (v2);
Assert.Null (Application.Driver);
v2.Init (null, "v2win");
Assert.NotNull (Application.Driver);
var type = Application.Driver.GetType ();
Assert.True (type.IsGenericType);
Assert.True (type.GetGenericTypeDefinition () == typeof (ConsoleDriverFacade<>));
v2.Shutdown ();
Assert.Null (Application.Driver);
winInput.VerifyAll ();
ApplicationImpl.ChangeInstance (orig);
}
[Fact]
public void Init_ExplicitlyRequestNet ()
{
var orig = ApplicationImpl.Instance;
var netInput = new Mock<INetInput> (MockBehavior.Strict);
var netOutput = new Mock<IConsoleOutput> (MockBehavior.Strict);
var winInput = new Mock<IWindowsInput> (MockBehavior.Strict);
var winOutput = new Mock<IConsoleOutput> (MockBehavior.Strict);
netInput.Setup (i => i.Initialize (It.IsAny<ConcurrentQueue<ConsoleKeyInfo>> ()))
.Verifiable (Times.Once);
SetupRunInputMockMethodToBlock (netInput);
netInput.Setup (i => i.Dispose ())
.Verifiable (Times.Once);
netOutput.Setup (i => i.Dispose ())
.Verifiable (Times.Once);
var v2 = new ApplicationV2 (
() => netInput.Object,
() => netOutput.Object,
() => winInput.Object,
() => winOutput.Object);
ApplicationImpl.ChangeInstance (v2);
Assert.Null (Application.Driver);
v2.Init (null, "v2net");
Assert.NotNull (Application.Driver);
var type = Application.Driver.GetType ();
Assert.True (type.IsGenericType);
Assert.True (type.GetGenericTypeDefinition () == typeof (ConsoleDriverFacade<>));
v2.Shutdown ();
Assert.Null (Application.Driver);
netInput.VerifyAll ();
ApplicationImpl.ChangeInstance (orig);
}
*/
private void SetupRunInputMockMethodToBlock (Mock<IConsoleInput<WindowsConsole.InputRecord>> winInput)
{
winInput.Setup (r => r.Run (It.IsAny<CancellationToken> ()))
.Callback<CancellationToken> (token =>
{
// Simulate an infinite loop that checks for cancellation
while (!token.IsCancellationRequested)
{
// Perform the action that should repeat in the loop
// This could be some mock behavior or just an empty loop depending on the context
}
})
.Verifiable (Times.Once);
}
private void SetupRunInputMockMethodToBlock (Mock<INetInput> netInput)
{
netInput.Setup (r => r.Run (It.IsAny<CancellationToken> ()))
.Callback<CancellationToken> (token =>
{
// Simulate an infinite loop that checks for cancellation
while (!token.IsCancellationRequested)
{
// Perform the action that should repeat in the loop
// This could be some mock behavior or just an empty loop depending on the context
}
})
.Verifiable (Times.Once);
}
[Fact]
public void NoInitThrowOnRun ()
{
var orig = ApplicationImpl.Instance;
Assert.Null (Application.Driver);
var app = NewApplicationImpl ();
ApplicationImpl.ChangeInstance (app);
var ex = Assert.Throws<NotInitializedException> (() => app.Run (new Window ()));
Assert.Equal ("Run cannot be accessed before Initialization", ex.Message);
app.Shutdown();
ApplicationImpl.ChangeInstance (orig);
}
[Fact]
public void InitRunShutdown_Top_Set_To_Null_After_Shutdown ()
{
var orig = ApplicationImpl.Instance;
var v2 = NewApplicationImpl ();
ApplicationImpl.ChangeInstance (v2);
v2.Init ();
var timeoutToken = v2.AddTimeout (TimeSpan.FromMilliseconds (150),
() =>
{
if (Application.Top != null)
{
Application.RequestStop ();
return false;
}
return false;
}
);
Assert.Null (Application.Top);
// Blocks until the timeout call is hit
v2.Run (new Window ());
// We returned false above, so we should not have to remove the timeout
Assert.False(v2.RemoveTimeout (timeoutToken));
Assert.NotNull (Application.Top);
Application.Top?.Dispose ();
v2.Shutdown ();
Assert.Null (Application.Top);
ApplicationImpl.ChangeInstance (orig);
}
[Fact]
public void InitRunShutdown_Running_Set_To_False ()
{
var orig = ApplicationImpl.Instance;
var v2 = NewApplicationImpl ();
ApplicationImpl.ChangeInstance (v2);
v2.Init ();
Toplevel top = new Window ()
{
Title = "InitRunShutdown_Running_Set_To_False"
};
var timeoutToken = v2.AddTimeout (TimeSpan.FromMilliseconds (150),
() =>
{
Assert.True (top!.Running);
if (Application.Top != null)
{
Application.RequestStop ();
return false;
}
return false;
}
);
Assert.False (top!.Running);
// Blocks until the timeout call is hit
v2.Run (top);
// We returned false above, so we should not have to remove the timeout
Assert.False (v2.RemoveTimeout (timeoutToken));
Assert.False (top!.Running);
// BUGBUG: Shutdown sets Top to null, not End.
//Assert.Null (Application.Top);
Application.Top?.Dispose ();
v2.Shutdown ();
ApplicationImpl.ChangeInstance (orig);
}
[Fact]
public void InitRunShutdown_End_Is_Called ()
{
var orig = ApplicationImpl.Instance;
var v2 = NewApplicationImpl ();
ApplicationImpl.ChangeInstance (v2);
Assert.Null (Application.Top);
Assert.Null (Application.Driver);
v2.Init ();
Toplevel top = new Window ();
// BUGBUG: Both Closed and Unloaded are called from End; what's the difference?
int closedCount = 0;
top.Closed
+= (_, a) =>
{
closedCount++;
};
int unloadedCount = 0;
top.Unloaded
+= (_, a) =>
{
unloadedCount++;
};
var timeoutToken = v2.AddTimeout (TimeSpan.FromMilliseconds (150),
() =>
{
Assert.True (top!.Running);
if (Application.Top != null)
{
Application.RequestStop ();
return false;
}
return false;
}
);
Assert.Equal (0, closedCount);
Assert.Equal (0, unloadedCount);
// Blocks until the timeout call is hit
v2.Run (top);
Assert.Equal (1, closedCount);
Assert.Equal (1, unloadedCount);
// We returned false above, so we should not have to remove the timeout
Assert.False (v2.RemoveTimeout (timeoutToken));
Application.Top?.Dispose ();
v2.Shutdown ();
Assert.Equal (1, closedCount);
Assert.Equal (1, unloadedCount);
ApplicationImpl.ChangeInstance (orig);
}
[Fact]
public void InitRunShutdown_QuitKey_Quits ()
{
var orig = ApplicationImpl.Instance;
var v2 = NewApplicationImpl ();
ApplicationImpl.ChangeInstance (v2);
v2.Init ();
Toplevel top = new Window ()
{
Title = "InitRunShutdown_QuitKey_Quits"
};
var timeoutToken = v2.AddTimeout (TimeSpan.FromMilliseconds (150),
() =>
{
Assert.True (top!.Running);
if (Application.Top != null)
{
Application.RaiseKeyDownEvent (Application.QuitKey);
}
return false;
}
);
Assert.False (top!.Running);
// Blocks until the timeout call is hit
v2.Run (top);
// We returned false above, so we should not have to remove the timeout
Assert.False (v2.RemoveTimeout (timeoutToken));
Assert.False (top!.Running);
Assert.NotNull (Application.Top);
top.Dispose ();
v2.Shutdown ();
Assert.Null (Application.Top);
ApplicationImpl.ChangeInstance (orig);
}
[Fact]
public void InitRunShutdown_Generic_IdleForExit ()
{
var orig = ApplicationImpl.Instance;
var v2 = NewApplicationImpl ();
ApplicationImpl.ChangeInstance (v2);
v2.Init ();
v2.AddTimeout (TimeSpan.Zero, IdleExit);
Assert.Null (Application.Top);
// Blocks until the timeout call is hit
v2.Run<Window> ();
Assert.NotNull (Application.Top);
Application.Top?.Dispose ();
v2.Shutdown ();
Assert.Null (Application.Top);
ApplicationImpl.ChangeInstance (orig);
}
[Fact]
public void Shutdown_Closing_Closed_Raised ()
{
var orig = ApplicationImpl.Instance;
var v2 = NewApplicationImpl ();
ApplicationImpl.ChangeInstance (v2);
v2.Init ();
int closing = 0;
int closed = 0;
var t = new Toplevel ();
t.Closing
+= (_, a) =>
{
// Cancel the first time
if (closing == 0)
{
a.Cancel = true;
}
closing++;
Assert.Same (t, a.RequestingTop);
};
t.Closed
+= (_, a) =>
{
closed++;
Assert.Same (t, a.Toplevel);
};
v2.AddTimeout(TimeSpan.Zero, IdleExit);
// Blocks until the timeout call is hit
v2.Run (t);
Application.Top?.Dispose ();
v2.Shutdown ();
ApplicationImpl.ChangeInstance (orig);
Assert.Equal (2, closing);
Assert.Equal (1, closed);
}
private bool IdleExit ()
{
if (Application.Top != null)
{
Application.RequestStop ();
return true;
}
return true;
}
/*
[Fact]
public void Shutdown_Called_Repeatedly_DoNotDuplicateDisposeOutput ()
{
var orig = ApplicationImpl.Instance;
var netInput = new Mock<INetInput> ();
SetupRunInputMockMethodToBlock (netInput);
Mock<IConsoleOutput>? outputMock = null;
var v2 = new ApplicationV2 (
() => netInput.Object,
() => (outputMock = new Mock<IConsoleOutput> ()).Object,
Mock.Of<IWindowsInput>,
Mock.Of<IConsoleOutput>);
ApplicationImpl.ChangeInstance (v2);
v2.Init (null, "v2net");
v2.Shutdown ();
outputMock!.Verify (o => o.Dispose (), Times.Once);
ApplicationImpl.ChangeInstance (orig);
}
*/
[Fact]
public void Open_Calls_ContinueWith_On_UIThread ()
{
var orig = ApplicationImpl.Instance;
var v2 = NewApplicationImpl ();
ApplicationImpl.ChangeInstance (v2);
v2.Init ();
var b = new Button ();
bool result = false;
b.Accepting +=
(_, _) =>
{
Task.Run (() =>
{
Task.Delay (300).Wait ();
}).ContinueWith (
(t, _) =>
{
// no longer loading
Application.Invoke (() =>
{
result = true;
Application.RequestStop ();
});
},
TaskScheduler.FromCurrentSynchronizationContext ());
};
v2.AddTimeout (TimeSpan.FromMilliseconds (150),
() =>
{
// Run asynchronous logic inside Task.Run
if (Application.Top != null)
{
b.NewKeyDownEvent (Key.Enter);
b.NewKeyUpEvent (Key.Enter);
}
return false;
});
Assert.Null (Application.Top);
var w = new Window ()
{
Title = "Open_CallsContinueWithOnUIThread"
};
w.Add (b);
// Blocks until the timeout call is hit
v2.Run (w);
Assert.NotNull (Application.Top);
Application.Top?.Dispose ();
v2.Shutdown ();
Assert.Null (Application.Top);
ApplicationImpl.ChangeInstance (orig);
Assert.True (result);
}
[Fact]
public void ApplicationImpl_UsesInstanceFields_NotStaticReferences()
{
// This test verifies that ApplicationImpl uses instance fields instead of static Application references
var orig = ApplicationImpl.Instance;
var v2 = NewApplicationImpl();
ApplicationImpl.ChangeInstance(v2);
// Before Init, all fields should be null/default
Assert.Null(v2.Driver);
Assert.False(v2.Initialized);
Assert.Null(v2.Popover);
Assert.Null(v2.Navigation);
Assert.Null(v2.Top);
Assert.Empty(v2.TopLevels);
// Init should populate instance fields
v2.Init();
// After Init, Driver, Navigation, and Popover should be populated
Assert.NotNull(v2.Driver);
Assert.True(v2.Initialized);
Assert.NotNull(v2.Popover);
Assert.NotNull(v2.Navigation);
Assert.Null(v2.Top); // Top is still null until Run
// Verify that static Application properties delegate to instance
Assert.Equal(v2.Driver, Application.Driver);
Assert.Equal(v2.Initialized, Application.Initialized);
Assert.Equal(v2.Popover, Application.Popover);
Assert.Equal(v2.Navigation, Application.Navigation);
Assert.Equal(v2.Top, Application.Top);
Assert.Same(v2.TopLevels, Application.TopLevels);
// Shutdown should clean up instance fields
v2.Shutdown();
Assert.Null(v2.Driver);
Assert.False(v2.Initialized);
Assert.Null(v2.Popover);
Assert.Null(v2.Navigation);
Assert.Null(v2.Top);
Assert.Empty(v2.TopLevels);
ApplicationImpl.ChangeInstance(orig);
}
}