< Summary

Information
Class: MyNet.UI.Dialogs.ContentDialogs.PresenterDialogStrategy
Assembly: MyNet.UI
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/Dialogs/ContentDialogs/PresenterDialogStrategy.cs
Tag: 323_28699572109
Line coverage
71%
Covered lines: 10
Uncovered lines: 4
Coverable lines: 14
Total lines: 56
Line coverage: 71.4%
Branch coverage
25%
Covered branches: 1
Total branches: 4
Branch coverage: 25%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Priority()100%11100%
CanHandle(...)100%11100%
ShowAsync(...)50%22100%
CloseAsync(...)0%620%
SelectPresenter(...)100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/Dialogs/ContentDialogs/PresenterDialogStrategy.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="PresenterDialogStrategy.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Collections.Generic;
 9using System.Linq;
 10using System.Threading;
 11using System.Threading.Tasks;
 12
 13namespace MyNet.UI.Dialogs.ContentDialogs;
 14
 15/// <summary>
 16/// Routes dialog display to the highest-priority registered <see cref="IDialogPresenter"/>.
 17/// </summary>
 18/// <param name="presenters">Presenters registered in the service collection.</param>
 19public sealed class PresenterDialogStrategy(IEnumerable<IDialogPresenter> presenters) : IDialogStrategy
 20{
 21    /// <summary>Default priority for presenter-based strategies (above <see cref="HeadlessDialogStrategy"/>).</summary>
 22    public const int DefaultPriority = 0;
 23
 24    /// <inheritdoc />
 325    public int Priority => DefaultPriority;
 26
 27    /// <inheritdoc />
 1228    public bool CanHandle(IDialog dialog, DialogOptions? options) => SelectPresenter(dialog, options) is not null;
 29
 30    /// <inheritdoc />
 31    public Task<DialogResult<bool>> ShowAsync(IDialog dialog, DialogOptions options, CancellationToken ct = default)
 32    {
 633        var presenter = SelectPresenter(dialog, options)
 634                        ?? throw new InvalidOperationException(
 635                            $"No {nameof(IDialogPresenter)} found for '{dialog.GetType().Name}'.");
 36
 637        return presenter.PresentAsync(dialog, options, ct);
 38    }
 39
 40    /// <inheritdoc />
 41    public Task CloseAsync(IDialog dialog)
 42    {
 043        var presenter = SelectPresenter(dialog, null)
 044                        ?? throw new InvalidOperationException(
 045                            $"No {nameof(IDialogPresenter)} found for '{dialog.GetType().Name}'.");
 46
 047        return presenter.CloseAsync(dialog);
 48    }
 49
 50    private IDialogPresenter? SelectPresenter(IDialog dialog, DialogOptions? options)
 1851        => presenters
 1852            .Where(p => p.CanPresent(dialog, options))
 1853            .OrderByDescending(p => p.Priority)
 1854            .FirstOrDefault();
 55}
 56