public sealed class RunicTestWindowPresentation : IRunicWindowPresentation, INotifyPropertyChanged A recording IRunicWindowPresentation for ViewModel tests: it records every request, behaves like a window that obeys them, and lets the test set the activity, for example to check that a ViewModel pauses polling while its Window is inactive.
Remarks
Register it for the window's scope with RunicTestWindowPresentationServiceCollectionExtensions.AddRunicTestWindowPresentation. The scope's IRunicWindowPresentation is then the same per-Window presentation an application gets, with this fake as its host: changes reach the ViewModel in a turn of the window's model context after the request that caused them completed, a handler that throws is logged (event 1130) without stopping the others, and once the scope is disposed requests report PlatformUnavailableReason.OwnerClosed. RunicWindowTestHost.Presentation returns the fake, RunicWindowTestHost.SetWindowActivityAsync changes its activity and waits until the ViewModel received it, and RunicWindowTestHost.FlushWindowPresentationAsync waits for the changes a command's requests caused: await using var services = new ServiceCollection().AddRunicViews().AddScoped<InboxViewModel>()
.AddRunicTestWindowPresentation().BuildServiceProvider();
await using var scope = services.CreateAsyncScope();
using var host = RunicWindowTestHost.Create<InboxViewModel>(scope.ServiceProvider);
(await host.Root.ExecuteAsync(vm => vm.HideToTrayCommand)).ThrowIfFailed();
Assert.False(host.Presentation!.IsVisible);
await host.SetWindowActivityAsync(RunicWindowActivity.Assumed);
It behaves as a desktop window does: a successful RunicTestWindowPresentation.PresentAsync shows, restores and activates it, RunicTestWindowPresentation.MinimizeAsync minimizes it, RunicTestWindowPresentation.SetVisibleAsync with false hides it, and with true shows it again without restoring it, so a minimized window stays minimized, as Win32's SW_SHOW leaves it. A request whose feature is not in RunicTestWindowPresentation.Features reports PlatformUnavailableReason.BackendUnavailable without changing anything; RunicTestWindowPresentation.Respond chooses another result.
Used directly, as a ViewModel built by hand takes it or as AddRunicTestWindowPresentation(immediate: true) registers it, the fake raises its changes on the calling thread at once, inside the request, and keeps answering after the scope ends. A change that a handler causes is raised after that handler returns, not inside it.
It also decides a side panel (RunicTestWindowPresentation.OpenSidePanelAsync) as a Runic Desktop window on Windows does: an 860-wide window at RunicTestWindowPresentation.WindowX 530 on a 1920-wide work area that grows on the panel's edge and shrinks back when it closes. RunicTestWindowPresentation.IsMaximized, RunicTestWindowPresentation.IsSnapped, the activity, RunicTestWindowPresentation.IsFullScreen and the room produce the refusals; RunicTestWindowPresentation.SetSidePanelRefusal chooses one, and RunicTestWindowPresentation.CloseSidePanel closes the panel as its page or a crash would.
It keeps a placement as a desktop window does (RunicTestWindowPresentation.Placement, at 100, 100 with 800 by 600 at first): RunicTestWindowPresentation.MaximizeAsync maximizes it and RunicTestWindowPresentation.RestoreAsync returns it to normal, both leaving full screen and restoring a minimized window; RunicTestWindowPresentation.SetPlacementAsync takes the placement's bounds and state as a desktop that fits them on its monitors would, here unchanged; and RunicTestWindowPresentation.SetPlacement moves the window as its user would, without recording a request.
Constructors
RunicTestWindowPresentation
public RunicTestWindowPresentation() Creates a window that is active and visible, with every feature.
RunicTestWindowPresentation
public RunicTestWindowPresentation(RunicWindowPresentationFeatures features, RunicWindowActivity activity) Creates a window with features and activity.
Parameters
featuresWhat the window can do, such as
RunicWindowPresentationFeatures.Presentalone for a CS-WebUI window.activityThe activity it starts with.
Fields
AllFeatures
public const RunicWindowPresentationFeatures AllFeatures = 4095 Every feature a desktop window can have.
Properties
Activity
public RunicWindowActivity Activity { get; } Gets whether the Window is active, minimized and visible, as last reported.
Documentation from IRunicWindowPresentation.Activity.
ColorScheme
public DesktopColorScheme ColorScheme { get; } Gets the light or dark appearance the Window shows now, as Runic set it: its own scheme, the application's, or the last one set for every Window that shares it (RunicWindowPresentationFeatures.PerWindowColorScheme); DesktopColorScheme.NoPreference when it follows the system.
Remarks
INotifyPropertyChanged.PropertyChanged reports a change, also one that another Window or the application made.
Documentation from IRunicWindowPresentation.ColorScheme.
Features
public RunicWindowPresentationFeatures Features { get; set; } Gets or sets what the window can do; the default is RunicTestWindowPresentation.AllFeatures.
IsActive
public bool IsActive { get; } Gets whether the Window has the desktop's keyboard focus: RunicWindowActivity.IsActive of IRunicWindowPresentation.Activity.
Documentation from IRunicWindowPresentation.IsActive.
IsDocumentEdited
public bool IsDocumentEdited { get; } Gets whether the window's document is marked edited after the requests so far.
IsFullScreen
public bool IsFullScreen { get; } Gets whether the window is full-screen after the requests so far.
IsMaximized
public bool IsMaximized { get; set; } Gets or sets whether the window is maximized, which refuses a side panel with RunicSidePanelRefusal.Maximized.
Remarks
RunicTestWindowPresentation.MaximizeAsync, RunicTestWindowPresentation.RestoreAsync and RunicTestWindowPresentation.SetPlacementAsync change it too, and RunicTestWindowPresentation.Placement reports it.
IsMinimized
public bool IsMinimized { get; } Gets whether the Window is minimized: RunicWindowActivity.IsMinimized of IRunicWindowPresentation.Activity.
Documentation from IRunicWindowPresentation.IsMinimized.
IsRightToLeft
public bool IsRightToLeft { get; set; } Gets or sets whether the window lays out right to left, so RunicSidePanelEdge.End is its left edge.
IsSnapped
public bool IsSnapped { get; set; } Gets or sets whether the desktop arranged the window, which refuses a side panel with RunicSidePanelRefusal.Snapped.
IsVisible
public bool IsVisible { get; } Gets whether the Window is shown: RunicWindowActivity.IsVisible of IRunicWindowPresentation.Activity.
Documentation from IRunicWindowPresentation.IsVisible.
Placement
public RunicWindowPlacement? Placement { get; } Gets the Window's placement as last reported: the bounds it restores to and whether it is maximized or full-screen; null where the host reports none (IRunicWindowPresentation.Features without RunicWindowPresentationFeatures.Placement).
Remarks
null without RunicWindowPresentationFeatures.Placement in RunicTestWindowPresentation.Features.
Documentation from IRunicWindowPresentation.Placement.
PresentCount
public int PresentCount { get; } Gets how many times the window was asked to present itself.
Requests
public IReadOnlyList<RunicWindowPresentationRequest> Requests { get; } Gets every request in the order it arrived, including those that did not succeed.
Respond
public Func<RunicWindowPresentationRequest, PlatformResult<PlatformUnit>?>? Respond { get; set; } Gets or sets the result of each request whose feature is in RunicTestWindowPresentation.Features, or null for success. A request that does not succeed changes nothing.
Remarks
For example, a desktop that keeps another application in front: request => request.Kind == RunicWindowPresentationRequestKind.Present ? new PlatformResult<PlatformUnit>.Failed(PlatformFailureCode.PermissionDenied) : null.
SidePanel
public IRunicSidePanel? SidePanel { get; } Gets the Window's open side panel, or null.
Remarks
Set when IRunicWindowPresentation.OpenSidePanelAsync returns the panel; null again in the turn of the Window's model context that raises the panel's IRunicSidePanel.Closed, and INotifyPropertyChanged.PropertyChanged reports both changes. The default implementation returns null.
Documentation from IRunicWindowPresentation.SidePanel.
WindowWidth
public int WindowWidth { get; set; } Gets or sets the width of the window's frame, panel included; 860 by default. An open panel adds its width, closing it subtracts it.
WindowX
public int WindowX { get; set; } Gets or sets the left edge of the window's frame on the work area, panel included; 530 by default, centred.
WorkAreaWidth
public int WorkAreaWidth { get; set; } Gets or sets the width of the monitor's work area; 1920 by default.
Methods
CloseSidePanel
public void CloseSidePanel(RunicSidePanelCloseReason reason) Closes the open side panel as its page or the desktop would: RunicSidePanelCloseReason.Closed for window.close() in the panel's page, RunicSidePanelCloseReason.Crashed for a crashed page, or RunicSidePanelCloseReason.WindowClosed. Does nothing without one. Not recorded as a request.
Parameters
reasonWhy the panel closed.
MaximizeAsync
public ValueTask<PlatformResult<PlatformUnit>> MaximizeAsync(CancellationToken cancellationToken = default) Maximizes the Window (zooms it on macOS); a Window that already is stays maximized.
Parameters
cancellationTokenCancels before the request reaches the window.
Returns
Success once the window was asked to maximize; IRunicWindowPresentation.Placement then reports it. PlatformUnavailableReason.BackendUnavailable where IRunicWindowPresentation.Features lacks RunicWindowPresentationFeatures.Maximize, PlatformFailureCode.PermissionDenied when a host application's policy refused it, and PlatformFailureCode.Conflict for a kiosk window, which stays full-screen.
Remarks
Recorded as RunicWindowPresentationRequestKind.Maximize. It leaves full screen and restores a minimized window maximized, which activates it, as on Windows; a hidden window stays hidden.
Documentation from IRunicWindowPresentation.MaximizeAsync.
MinimizeAsync
public ValueTask<PlatformResult<PlatformUnit>> MinimizeAsync(CancellationToken cancellationToken = default) Minimizes the Window to the taskbar or Dock.
Parameters
cancellationTokenCancels before the request reaches the window.
Returns
Success once the window was asked to minimize.
Documentation from IRunicWindowPresentation.MinimizeAsync.
OpenSidePanelAsync
public ValueTask<RunicSidePanelResult> OpenSidePanelAsync(RunicSidePanelOptions options, CancellationToken cancellationToken = default) Opens a page of the Window beside its page, growing the Window by the panel's width on one edge, so its page keeps its size and its place on the screen.
Parameters
optionsThe edge, width and page of the panel.
cancellationTokenCancels waiting for the panel's page; a cancelled open leaves the Window unchanged.
Returns
Opened with the panel, also IRunicWindowPresentation.SidePanel from then on, or Refused with the reason, after which the Window is unchanged and the ViewModel shows the content another way, such as an overlay of its page.
Exceptions
ArgumentNullExceptionoptionsisnull.ArgumentOutOfRangeExceptionThe width is smaller than
RunicSidePanelOptions.MinimumWidth, the edge is not defined, or the load timeout is not positive.ArgumentExceptionThe path is empty, absolute, or leaves the Window's page.
OperationCanceledExceptioncancellationTokenwas cancelled.
Remarks
The request is recorded; an open panel grows RunicTestWindowPresentation.WindowWidth, and on the left edge moves RunicTestWindowPresentation.WindowX.
Documentation from IRunicWindowPresentation.OpenSidePanelAsync.
PresentAsync
public ValueTask<PlatformResult<PlatformUnit>> PresentAsync(DesktopActivationContext? activation = null, CancellationToken cancellationToken = default) Brings the Window to the front and gives it the keyboard focus: shows it when it is hidden and restores it when it is minimized.
Parameters
activationThe activation token or startup ID that lets the desktop grant focus, such as
ApplicationLaunch.PlatformContextof a launch that a second instance forwarded, ornull. Use it once, promptly.cancellationTokenCancels before the request reaches the window.
Returns
Success when the desktop presented the Window. A desktop may refuse to take the focus from the application the user works in: Windows then flashes the taskbar button and reports PlatformFailureCode.PermissionDenied, and a Wayland compositor without an activation token only asks for attention.
Documentation from IRunicWindowPresentation.PresentAsync.
RestoreAsync
public ValueTask<PlatformResult<PlatformUnit>> RestoreAsync(CancellationToken cancellationToken = default) Returns the Window to its normal bounds: leaves full screen, un-maximizes and un-minimizes it; a normal Window stays as it is.
Parameters
cancellationTokenCancels before the request reaches the window.
Returns
Success once the window was asked to restore, with the results of IRunicWindowPresentation.MaximizeAsync otherwise.
Remarks
Recorded as RunicWindowPresentationRequestKind.Restore. It leaves full screen and maximized and restores a minimized window to normal, which activates it, as on Windows; a hidden window stays hidden.
Documentation from IRunicWindowPresentation.RestoreAsync.
SetActive
public void SetActive(bool active) Makes the window active and visible, or inactive and still visible, as switching to another window does.
Parameters
activeWhether the window has the keyboard focus.
SetActivity
public void SetActivity(RunicWindowActivity activity) Changes the activity as the desktop would, and raises RunicTestWindowPresentation.ActivityChanged and RunicTestWindowPresentation.PropertyChanged on the calling thread when it changed.
Parameters
activityThe new activity.
SetColorSchemeAsync
public ValueTask<PlatformResult<PlatformUnit>> SetColorSchemeAsync(DesktopColorScheme colorScheme, CancellationToken cancellationToken = default) Switches the Window between light and dark while it is open.
Parameters
colorSchemeDesktopColorScheme.LightorDesktopColorScheme.Dark, orDesktopColorScheme.NoPreferenceto follow the application's scheme, which by default follows the system.cancellationTokenCancels before the request reaches the window.
Returns
Success once the window and its page show the scheme.
Exceptions
ArgumentOutOfRangeExceptioncolorSchemeis not a defined value.
Remarks
The page's prefers-color-scheme follows. Where IRunicWindowPresentation.Features lacks RunicWindowPresentationFeatures.PerWindowColorScheme, the scheme is not this Window's alone: on Linux the GTK windows share one scheme for the whole process, and on Windows the windows that share a WebView2 profile share its scheme, so the call changes all of them and IRunicWindowPresentation.ColorScheme of each reports it.
On Runic Desktop, DesktopHost.SetColorSchemeAsync switches the whole application; on such a shared scheme it wins over the Windows' own, whatever order they were set in.
Documentation from IRunicWindowPresentation.SetColorSchemeAsync.
SetDocumentEditedAsync
public ValueTask<PlatformResult<PlatformUnit>> SetDocumentEditedAsync(bool edited, CancellationToken cancellationToken = default) Marks whether the Window's document has unsaved changes, where the platform shows it: the dot in the macOS close button.
Parameters
editedtruewhile the document has unsaved changes.cancellationTokenCancels before the request reaches the window.
Returns
Success once the window shows it; PlatformUnavailableReason.BackendUnavailable on Windows, Linux and in WPF, which have no such convention. Show unsaved changes in the page or title there.
Documentation from IRunicWindowPresentation.SetDocumentEditedAsync.
SetFullScreenAsync
public ValueTask<PlatformResult<PlatformUnit>> SetFullScreenAsync(bool fullScreen, CancellationToken cancellationToken = default) Enters or leaves full screen.
Parameters
fullScreentrueto fill the Window's monitor;falseto return to its bounds.cancellationTokenCancels before the request reaches the window.
Returns
Success once the window was asked to change.
Documentation from IRunicWindowPresentation.SetFullScreenAsync.
SetPlacement
public void SetPlacement(RunicWindowPlacement placement) Moves, resizes, maximizes or restores the window as its user would, and raises RunicTestWindowPresentation.PropertyChanged for RunicTestWindowPresentation.Placement on the calling thread when it changed. Not recorded as a request.
Parameters
placementThe window's new placement;
nullRunicWindowPlacement.XandRunicWindowPlacement.Ykeep its position, and a width or height of zero or less keeps that dimension.
SetPlacementAsync
public ValueTask<PlatformResult<PlatformUnit>> SetPlacementAsync(RunicWindowPlacement placement, CancellationToken cancellationToken = default) Gives the open Window a placement: the bounds it restores to and whether it is maximized or full-screen, as a placement saved from IRunicWindowPresentation.Placement gives it.
Parameters
placementThe placement, in the units of
IRunicWindowPresentation.Placement(seeRunicWindowPlacement).RunicWindowPlacement.XandRunicWindowPlacement.Ybothnullkeep the position; aRunicWindowPlacement.WidthorRunicWindowPlacement.Heightof zero or less keeps that dimension.cancellationTokenCancels before the request reaches the window.
Returns
Success once the window was asked to take the placement, with the results of IRunicWindowPresentation.MaximizeAsync otherwise. Where the platform cannot position a window (Wayland), a placement with a position reports PlatformUnavailableReason.BackendUnavailable and changes nothing: pass one without RunicWindowPlacement.X and RunicWindowPlacement.Y, as IRunicWindowPresentation.Placement reports there.
Exceptions
ArgumentNullExceptionplacementisnull.ArgumentExceptionOnly one of
RunicWindowPlacement.XandRunicWindowPlacement.Yis set.
Remarks
Recorded as RunicWindowPresentationRequestKind.SetPlacement with the placement as passed. The window takes its bounds and state; a minimized or hidden window stays so.
Documentation from IRunicWindowPresentation.SetPlacementAsync.
SetSidePanelRefusal
public void SetSidePanelRefusal(RunicSidePanelRefusal? reason) Makes every side panel request refuse with reason, after RunicSidePanelRefusal.Unsupported and RunicSidePanelRefusal.AlreadyOpen, until it is set to null: for example RunicSidePanelRefusal.PositionUnavailable as on Wayland, or RunicSidePanelRefusal.LoadFailed.
Parameters
reasonThe refusal, or
nullto decide from the window's state and room again.
Remarks
Without it the window refuses as a desktop window does: RunicSidePanelRefusal.Unsupported without RunicWindowPresentationFeatures.SidePanel in RunicTestWindowPresentation.Features, then RunicSidePanelRefusal.AlreadyOpen, RunicSidePanelRefusal.Minimized (also hidden), RunicSidePanelRefusal.FullScreen, RunicSidePanelRefusal.Maximized, RunicSidePanelRefusal.Snapped and RunicSidePanelRefusal.NoRoom: the window, grown by the panel on its edge, would leave the work area, or the panel is wider than half of it.
SetVisibleAsync
public ValueTask<PlatformResult<PlatformUnit>> SetVisibleAsync(bool visible, CancellationToken cancellationToken = default) Hides the Window without closing it, for example to a status icon, or shows it again.
Parameters
visibletrueto show the Window;falseto hide it.cancellationTokenCancels before the request reaches the window.
Returns
Success once the window was shown or hidden.
Remarks
A hidden Window stays open: its page keeps running and its Bridge stays connected. Only the application can show it again, so keep a way back, such as a status icon whose command calls IRunicWindowPresentation.PresentAsync.
Documentation from IRunicWindowPresentation.SetVisibleAsync.
Events
ActivityChanged
public event EventHandler<RunicWindowActivityChangedEventArgs>? ActivityChanged Occurs after IRunicWindowPresentation.Activity has changed, in a turn of the Window's model context.
Documentation from IRunicWindowPresentation.ActivityChanged.
PropertyChanged
public event PropertyChangedEventHandler? PropertyChanged Inherits documentation from INotifyPropertyChanged.PropertyChanged.