public sealed class RunicTestMessageBoxes : IDesktopMessageBoxes Scripted IDesktopMessageBoxes for tests: each box takes the next queued answer and is recorded.
Remarks
Queue the button the user chooses, by its id, with RunicTestMessageBoxes.EnqueueAnswer before the action that shows the box. A box shown with an empty queue is answered as the user pressing Esc would: with its DesktopMessageBoxButtonRole.Cancel button, or null when it has none. A scripted id the box does not have throws InvalidOperationException from RunicTestMessageBoxes.ShowAsync.
Boxes are checked with the rules of the real ones. When the test window closes, they report PlatformUnavailableReason.OwnerClosed. The type is safe to use from any thread.
Properties
Calls
public IReadOnlyList<RunicMessageBoxCall> Calls { get; } The boxes shown so far, oldest first.
Pending
public int Pending { get; } The number of answers still queued.
Methods
EnqueueAnswer
public void EnqueueAnswer(string? buttonId) Queues the button the user chooses in the next box.
Parameters
buttonIdThe
DesktopMessageBoxButton.Id, ornullfor a box closed without a button.
EnqueueFailed
public void EnqueueFailed(PlatformFailureCode code) Queues a failure for the next box.
Parameters
codeThe failure it reports.
EnqueueUnavailable
public void EnqueueUnavailable(PlatformUnavailableReason reason) Queues unavailability for the next box.
Parameters
reasonThe reason it reports.
ShowAsync
public ValueTask<PlatformResult<DesktopMessageBoxButton?>> ShowAsync(DesktopMessageBox messageBox, CancellationToken cancellationToken = default) Shows a message box modal to the window and returns the button the user chose.
Parameters
messageBoxThe box; see
DesktopMessageBoxfor its rules.cancellationTokenCloses the box, which then throws
OperationCanceledException.
Returns
Success with the chosen button, one of DesktopMessageBox.Buttons, or with null when the box had no buttons of the application or GTK closed it without a button, such as when the user pressed Esc in a box without a cancel button. Unavailable: PlatformUnavailableReason.OwnerUnavailable before the window opens or on a host without a native owner, PlatformUnavailableReason.OwnerClosed once it closed, also while the box is shown, and PlatformUnavailableReason.BackendUnavailable when the platform cannot show the box, such as GTK before 4.10.
Exceptions
ArgumentExceptionmessageBoxbreaks a rule.ArgumentNullExceptionmessageBoxisnull.OperationCanceledExceptioncancellationTokenwas cancelled.
Documentation from IDesktopMessageBoxes.ShowAsync.