< Summary

Information
Class: MyNet.UI.ViewModels.Preferences.PreferencesViewModel
Assembly: MyNet.UI
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/ViewModels/Preferences/PreferencesViewModel.cs
Tag: 323_28699572109
Line coverage
92%
Covered lines: 25
Uncovered lines: 2
Coverable lines: 27
Total lines: 117
Line coverage: 92.5%
Branch coverage
83%
Covered branches: 5
Total branches: 6
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_Workspaces()100%11100%
get_SelectedWorkspace()100%11100%
get_SelectedIndex()100%11100%
get_GoToTabCommand()100%11100%
get_GoToNextTabCommand()100%11100%
get_GoToPreviousTabCommand()100%11100%
Select(...)100%210%
Select(...)100%210%
CreateTitle(...)100%11100%
SaveCore()100%11100%
OnResetAsync()100%22100%
OnRefreshAsync()100%22100%
DisposeManagedResources()100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/ViewModels/Preferences/PreferencesViewModel.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="PreferencesViewModel.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.Collections.ObjectModel;
 10using System.Diagnostics.CodeAnalysis;
 11using System.Globalization;
 12using System.Threading;
 13using System.Threading.Tasks;
 14using System.Windows.Input;
 15using FluentValidation;
 16using MyNet.Globalization.Culture;
 17using MyNet.UI.Commands;
 18using MyNet.UI.Dialogs;
 19using MyNet.UI.Notifications;
 20using MyNet.UI.Resources;
 21using MyNet.UI.Services;
 22using MyNet.UI.ViewModels.Crud;
 23using MyNet.UI.ViewModels.Workspace;
 24
 25namespace MyNet.UI.ViewModels.Preferences;
 26
 27/// <summary>
 28/// Preferences dialog with tabbed pages and persistent settings save/reset/reload.
 29/// </summary>
 30[SuppressMessage("Usage", "CA2213:Disposable fields should be disposed", Justification = "Disposed in DisposeManagedReso
 31public sealed class PreferencesViewModel : EditionViewModel, ITabWorkspaceViewModel
 32{
 33    private readonly IPersistentPreferencesService _preferencesService;
 34    private readonly PreferencesTabWorkspace _tabs;
 35
 36    /// <summary>
 37    /// Initializes a new instance of the <see cref="PreferencesViewModel"/> class.
 38    /// </summary>
 39    public PreferencesViewModel(
 40        IPersistentPreferencesService preferencesService,
 41        IEnumerable<IWorkspaceViewModel> pages,
 42        IDialogService dialogService,
 43        INotificationPublisher notificationPublisher,
 44        ICommandFactory? commandFactory = null,
 45        IValidator? validator = null,
 46        ICultureService? cultureService = null)
 1547        : base(dialogService, notificationPublisher, commandFactory, validator, cultureService)
 48    {
 1549        _preferencesService = preferencesService ?? throw new ArgumentNullException(nameof(preferencesService));
 1550        ArgumentNullException.ThrowIfNull(pages);
 51
 1552        _tabs = new(commandFactory, cultureService);
 1553        _tabs.AddPages(pages);
 1554    }
 55
 56    /// <inheritdoc />
 5457    public ReadOnlyObservableCollection<IWorkspaceViewModel> Workspaces => _tabs.Workspaces;
 58
 59    /// <inheritdoc />
 1560    public IWorkspaceViewModel? SelectedWorkspace => _tabs.SelectedWorkspace;
 61
 62    /// <inheritdoc />
 1563    public int SelectedIndex => _tabs.SelectedIndex;
 64
 65    /// <summary>
 66    /// Gets the command to navigate to a specific tab.
 67    /// </summary>
 1568    public ICommand GoToTabCommand => _tabs.GoToTabCommand;
 69
 70    /// <summary>
 71    /// Gets the command to navigate to the next tab.
 72    /// </summary>
 1573    public ICommand GoToNextTabCommand => _tabs.GoToNextTabCommand;
 74
 75    /// <summary>
 76    /// Gets the command to navigate to the previous tab.
 77    /// </summary>
 1578    public ICommand GoToPreviousTabCommand => _tabs.GoToPreviousTabCommand;
 79
 80    /// <inheritdoc />
 081    public void Select(IWorkspaceViewModel workspace) => _tabs.Select(workspace);
 82
 83    /// <inheritdoc />
 084    public void Select(int index) => _tabs.Select(index);
 85
 86    /// <inheritdoc />
 1587    protected override string? CreateTitle(CultureInfo culture) => UiResources.Preferences;
 88
 89    /// <inheritdoc />
 390    protected override void SaveCore() => _preferencesService.Save();
 91
 92    /// <inheritdoc />
 93    protected override async Task OnResetAsync(CancellationToken cancellationToken = default)
 94    {
 395        _preferencesService.Reset();
 96
 1297        foreach (var workspace in Workspaces)
 398            await workspace.ResetAsync(cancellationToken).ConfigureAwait(false);
 399    }
 100
 101    /// <inheritdoc />
 102    protected override async Task OnRefreshAsync(CancellationToken cancellationToken = default)
 103    {
 3104        _preferencesService.Reload();
 105
 12106        foreach (var workspace in Workspaces)
 3107            await workspace.RefreshAsync(cancellationToken).ConfigureAwait(false);
 3108    }
 109
 110    /// <inheritdoc />
 111    protected override void DisposeManagedResources()
 112    {
 3113        _tabs.Dispose();
 3114        base.DisposeManagedResources();
 3115    }
 116}
 117