RunicTestNotifications class

Namespace Runic.Application.Testing in Runic.Application.Testing 0.23.0

public sealed class RunicTestNotifications : IDesktopNotifications, IAsyncDisposable, IDesktopServiceStatus

Inherits or implements IDesktopNotifications, IAsyncDisposable, IDesktopServiceStatus.

Recording IDesktopNotifications for tests: shown and removed notifications are kept, and RunicTestNotifications.Activate raises RunicTestNotifications.Activated as a click on a notification or one of its actions would.

Remarks

Notifications belong to the application, not to a window, so AddRunicTestPlatform registers one instance for the service provider. Set RunicTestNotifications.UnavailableReason or RunicTestNotifications.PermissionResult to test an application without notifications. The type is safe to use from any thread.

Constructors

RunicTestNotifications

public RunicTestNotifications()

No documentation.

Properties

Current

public IReadOnlyList<DesktopNotification> Current { get; }

The notifications shown and not removed, one per id.

PermissionRequests

public int PermissionRequests { get; }

How often the application requested permission.

PermissionResult

public PlatformResult<PlatformUnit> PermissionResult { get; set; }

What RunicTestNotifications.RequestPermissionAsync reports when the notifications are available; success by default.

Removed

public IReadOnlyList<string> Removed { get; }

The ids the application removed, oldest first.

Shown

public IReadOnlyList<DesktopNotification> Shown { get; }

Every notification shown, oldest first, including ones that replaced another with the same id.

Status

public CapabilityStatus Status { get; }

Unavailable when every operation reports Unavailable with that reason, for example a service an Unavailable(…) factory created because no provider supports this platform or host; otherwise Available.

Remarks

Available means the service was created for a native backend, not that each request succeeds: a request still reports the backend's outcome, including Unavailable when a desktop service turns out to be missing. Use it to decide whether to offer a feature, and the request's result to report what happened.

Documentation from IDesktopServiceStatus.Status.

UnavailableReason

public PlatformUnavailableReason? UnavailableReason { get; set; }

When set, every call reports Unavailable with this reason.

Methods

Activate

public DesktopNotificationActivation Activate(string notificationId, string? actionId = null, bool trusted = true)

Raises RunicTestNotifications.Activated as the user clicking a notification or one of its actions would.

Parameters

notificationId

The notification's id.

actionId

The action's id, or null for a click on the notification itself.

trusted

The activation's DesktopNotificationActivation.IsTrusted; true by default.

Returns

The activation raised.

Remarks

The action id of a click on the notification itself is empty. A trusted activation names a notification shown and not removed, and one of its actions, and carries its DesktopNotification.ActivationUri; pass trusted false for an activation the provider could not match.

DisposeAsync

public ValueTask DisposeAsync()

Inherits documentation from IAsyncDisposable.DisposeAsync.

RemoveAsync

public ValueTask<PlatformResult<PlatformUnit>> RemoveAsync(string id, CancellationToken cancellationToken = default)

Removes a notification with an application-owned identifier.

Documentation from IDesktopNotifications.RemoveAsync.

RequestPermissionAsync

public ValueTask<PlatformResult<PlatformUnit>> RequestPermissionAsync(CancellationToken cancellationToken = default)

Requests or checks OS authorization; Windows and Linux do not show a separate consent prompt.

Remarks

Windows may not have settings for a newly registered app. Success permits an attempt; submission still enforces native registration and policy and never guarantees visibility.

Documentation from IDesktopNotifications.RequestPermissionAsync.

ShowAsync

public ValueTask<PlatformResult<PlatformUnit>> ShowAsync(DesktopNotification notification, CancellationToken cancellationToken = default)

Submits or replaces a notification; success acknowledges submission, not visibility.

Documentation from IDesktopNotifications.ShowAsync.

Events

Activated

public event EventHandler<DesktopNotificationActivation>? Activated

Raised by RunicTestNotifications.Activate, on the calling thread.