< Summary

Information
Class: MyNet.UI.ViewModels.Shell.Services.ShellService
Assembly: MyNet.UI
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/ViewModels/Shell/Services/ShellService.cs
Tag: 323_28699572109
Line coverage
72%
Covered lines: 16
Uncovered lines: 6
Coverable lines: 22
Total lines: 74
Line coverage: 72.7%
Branch coverage
83%
Covered branches: 10
Total branches: 12
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)50%22100%
get_IsAvailable()100%11100%
get_IsFileMenuAvailable()100%210%
CloseDrawers()100%11100%
SetNotificationsDrawer(...)100%210%
SetFileMenuDrawer(...)100%210%
OpenFileMenuContent()100%11100%
OpenFileMenuContent(...)100%210%
CloseFileMenuContent()100%210%
SetFileMenuContentVisibility(...)100%11100%
SetFileMenuContentVisibility(...)100%210%
RequireHost()50%22100%
RequireFileMenuHost()100%22100%
TryGetFileMenuHost(...)100%66100%

File(s)

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

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="ShellService.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using MyNet.UI.ViewModels.Workspace;
 9
 10namespace MyNet.UI.ViewModels.Shell.Services;
 11
 12/// <inheritdoc />
 13public sealed class ShellService(IShellHostProvider hostProvider) : IShellService
 14{
 1515    private readonly IShellHostProvider _hostProvider = hostProvider ?? throw new ArgumentNullException(nameof(hostProvi
 16
 17    /// <inheritdoc />
 318    public bool IsAvailable => _hostProvider.Current is not null;
 19
 20    /// <inheritdoc />
 021    public bool IsFileMenuAvailable => TryGetFileMenuHost(out _);
 22
 23    /// <inheritdoc />
 324    public void CloseDrawers() => RequireHost().CloseDrawers();
 25
 26    /// <inheritdoc />
 027    public void SetNotificationsDrawer(ShellDrawerAction action) => RequireHost().SetNotificationsDrawer(action);
 28
 29    /// <inheritdoc />
 030    public void SetFileMenuDrawer(ShellDrawerAction action) => RequireHost().SetFileMenuDrawer(action);
 31
 32    /// <inheritdoc />
 33    public void OpenFileMenuContent<T>()
 34        where T : class, IWorkspaceViewModel
 335        => RequireFileMenuHost().OpenFileMenuContent<T>();
 36
 37    /// <inheritdoc />
 038    public void OpenFileMenuContent(Type contentType) => RequireFileMenuHost().OpenFileMenuContent(contentType);
 39
 40    /// <inheritdoc />
 041    public void CloseFileMenuContent() => RequireFileMenuHost().CloseFileMenuContent();
 42
 43    /// <inheritdoc />
 44    public void SetFileMenuContentVisibility<T>(ShellDrawerAction action)
 45        where T : class, IWorkspaceViewModel
 346        => RequireFileMenuHost().SetFileMenuContentVisibility<T>(action);
 47
 48    /// <inheritdoc />
 49    public void SetFileMenuContentVisibility(Type contentType, ShellDrawerAction action)
 050        => RequireFileMenuHost().SetFileMenuContentVisibility(contentType, action);
 51
 52    private IShellHost RequireHost()
 353        => _hostProvider.Current
 354           ?? throw new InvalidOperationException("No shell host is attached. Register ShellHostViewModel with IShellHos
 55
 56    private IShellHostWithFileMenu RequireFileMenuHost()
 657        => TryGetFileMenuHost(out var host)
 658            ? host
 659            : throw new InvalidOperationException(
 660                "The attached shell host does not have a file menu. Pass FileMenuViewModel to ShellHostViewModel.");
 61
 62    private bool TryGetFileMenuHost(out IShellHostWithFileMenu host)
 63    {
 664        if (_hostProvider.Current is IShellHostWithFileMenu fileMenuHost and IShellCapabilities { HasFileMenu: true })
 65        {
 366            host = fileMenuHost;
 367            return true;
 68        }
 69
 370        host = null!;
 371        return false;
 72    }
 73}
 74