< Summary

Information
Class: MyNet.UI.ViewModels.Shell.Drawers.ShellNotificationsHost
Assembly: MyNet.UI
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/ViewModels/Shell/Drawers/ShellNotificationsHost.cs
Tag: 323_28699572109
Line coverage
93%
Covered lines: 14
Uncovered lines: 1
Coverable lines: 15
Total lines: 74
Line coverage: 93.3%
Branch coverage
50%
Covered branches: 7
Total branches: 14
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)50%88100%
CreateToggleCommand(...)100%11100%
SetDrawer(...)75%44100%
Close()100%11100%
CanToggle()0%620%
Dispose()100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/ViewModels/Shell/Drawers/ShellNotificationsHost.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="ShellNotificationsHost.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Windows.Input;
 9using MyNet.UI.Commands;
 10using MyNet.UI.ViewModels.Shell.Notifications;
 11
 12namespace MyNet.UI.ViewModels.Shell.Drawers;
 13
 14/// <summary>
 15/// Coordinates notifications drawer state and toggle command availability for the shell host.
 16/// </summary>
 17public sealed class ShellNotificationsHost : IDisposable
 18{
 19    private readonly IShellNotificationsDrawerHost _drawer;
 20    private readonly ShellNotificationsViewModel _notifications;
 21    private readonly ShellNotificationsDrawerCoordinator _coordinator;
 22    private readonly Func<bool> _canUseShellChrome;
 23    private readonly Action? _onDrawerOpening;
 24
 25    /// <summary>
 26    /// Initializes a new instance of the <see cref="ShellNotificationsHost"/> class.
 27    /// </summary>
 28    public ShellNotificationsHost(
 29        IShellNotificationsDrawerHost drawer,
 30        ShellNotificationsViewModel notifications,
 31        ShellNotificationsDrawerCoordinator coordinator,
 32        Func<bool> canUseShellChrome,
 33        Action? onDrawerOpening = null)
 34    {
 2435        _drawer = drawer ?? throw new ArgumentNullException(nameof(drawer));
 2436        _notifications = notifications ?? throw new ArgumentNullException(nameof(notifications));
 2437        _coordinator = coordinator ?? throw new ArgumentNullException(nameof(coordinator));
 2438        _canUseShellChrome = canUseShellChrome ?? throw new ArgumentNullException(nameof(canUseShellChrome));
 2439        _onDrawerOpening = onDrawerOpening;
 40
 2441        _coordinator.Bind(drawer, notifications);
 2442    }
 43
 44    /// <summary>
 45    /// Creates the toggle notifications command.
 46    /// </summary>
 47    public ICommand CreateToggleCommand(ICommandFactory commands)
 2448        => commands.Create(() => SetDrawer(ShellDrawerAction.Toggle), CanToggle);
 49
 50    /// <summary>
 51    /// Applies an action to the notifications drawer.
 52    /// </summary>
 53    public void SetDrawer(ShellDrawerAction action)
 54    {
 955        if (action.WillOpen(_drawer.IsNotificationsOpen))
 656            _onDrawerOpening?.Invoke();
 57
 958        _drawer.IsNotificationsOpen = action.ApplyToOpenState(_drawer.IsNotificationsOpen);
 959    }
 60
 61    /// <summary>
 62    /// Closes the notifications drawer.
 63    /// </summary>
 1264    public void Close() => _drawer.IsNotificationsOpen = false;
 65
 66    /// <summary>
 67    /// Returns whether the toggle command can execute.
 68    /// </summary>
 069    public bool CanToggle() => _canUseShellChrome() && _notifications.HasNotifications;
 70
 71    /// <inheritdoc />
 372    public void Dispose() => _coordinator.Unbind();
 73}
 74