< Summary

Information
Class: MyNet.UI.ViewModels.Shell.Notifications.ShellNotificationsDrawerCoordinator
Assembly: MyNet.UI
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/ViewModels/Shell/Notifications/ShellNotificationsDrawerCoordinator.cs
Tag: 323_28699572109
Line coverage
94%
Covered lines: 18
Uncovered lines: 1
Coverable lines: 19
Total lines: 59
Line coverage: 94.7%
Branch coverage
70%
Covered branches: 7
Total branches: 10
Branch coverage: 70%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Bind(...)100%11100%
Unbind()100%22100%
OnNotificationsChanged(...)62.5%8885.71%

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="ShellNotificationsDrawerCoordinator.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using MyNet.UI.Commands;
 9
 10namespace MyNet.UI.ViewModels.Shell.Notifications;
 11
 12/// <summary>
 13/// Closes the notifications drawer when the panel becomes empty and refreshes toggle command availability.
 14/// </summary>
 15public sealed class ShellNotificationsDrawerCoordinator
 16{
 17    private IShellNotificationsDrawerHost? _host;
 18    private ShellNotificationsViewModel? _notifications;
 19
 20    /// <summary>
 21    /// Subscribes to <paramref name="notifications"/> and drives <paramref name="host"/> drawer state.
 22    /// </summary>
 23    public void Bind(IShellNotificationsDrawerHost host, ShellNotificationsViewModel notifications)
 24    {
 3025        ArgumentNullException.ThrowIfNull(host);
 3026        ArgumentNullException.ThrowIfNull(notifications);
 27
 3028        Unbind();
 29
 3030        _host = host;
 3031        _notifications = notifications;
 3032        _notifications.NotificationsChanged += OnNotificationsChanged;
 3033        OnNotificationsChanged(notifications, EventArgs.Empty);
 3034    }
 35
 36    /// <summary>
 37    /// Removes subscriptions created by <see cref="Bind"/>.
 38    /// </summary>
 39    public void Unbind()
 40    {
 3641        _notifications?.NotificationsChanged -= OnNotificationsChanged;
 42
 3643        _host = null;
 3644        _notifications = null;
 3645    }
 46
 47    private void OnNotificationsChanged(object? sender, EventArgs e)
 48    {
 3049        if (_host is null || _notifications is null)
 050            return;
 51
 3052        if (!_notifications.HasNotifications)
 3053            _host.IsNotificationsOpen = false;
 54
 3055        if (_host.ToggleNotificationsCommand is IRaiseCanExecuteChanged raise)
 656            raise.RaiseCanExecuteChanged();
 3057    }
 58}
 59