< Summary

Information
Class: MyNet.UI.ViewModels.Export.ExportFileType
Assembly: MyNet.UI
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/ViewModels/Export/ExportFileType.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 66
Line coverage: 100%
Branch coverage
87%
Covered branches: 7
Total branches: 8
Branch coverage: 87.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%22100%
IsValidPath(...)100%22100%
NormalizeExtension(...)75%44100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/ViewModels/Export/ExportFileType.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="ExportFileType.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.IO;
 10using System.Linq;
 11
 12namespace MyNet.UI.ViewModels.Export;
 13
 14/// <summary>
 15/// Represents export file constraints and dialog filter information.
 16/// </summary>
 17public sealed class ExportFileType
 18{
 19    /// <summary>
 20    /// Initializes a new instance of the <see cref="ExportFileType"/> class.
 21    /// </summary>
 22    /// <param name="defaultExtension">The default extension used for generated file names (for example ".csv").</param>
 23    /// <param name="dialogFilter">The dialog filter string.</param>
 24    /// <param name="allowedExtensions">Optional allowed extensions used for destination validation.</param>
 25    public ExportFileType(string defaultExtension, string dialogFilter, IEnumerable<string>? allowedExtensions = null)
 26    {
 1527        ArgumentException.ThrowIfNullOrWhiteSpace(defaultExtension);
 1528        ArgumentException.ThrowIfNullOrWhiteSpace(dialogFilter);
 29
 1530        DefaultExtension = NormalizeExtension(defaultExtension);
 31        DialogFilter = dialogFilter;
 1532        AllowedExtensions = [.. (allowedExtensions ?? [defaultExtension]).Select(NormalizeExtension).Distinct(StringComp
 1533    }
 34
 35    /// <summary>
 36    /// Gets the default extension.
 37    /// </summary>
 38    public string DefaultExtension { get; }
 39
 40    /// <summary>
 41    /// Gets the dialog filter string.
 42    /// </summary>
 43    public string DialogFilter { get; }
 44
 45    /// <summary>
 46    /// Gets allowed extensions.
 47    /// </summary>
 48    public IReadOnlyCollection<string> AllowedExtensions { get; }
 49
 50    /// <summary>
 51    /// Determines whether the specified file path has an allowed extension.
 52    /// </summary>
 53    /// <param name="path">The file path to validate.</param>
 54    /// <returns><see langword="true"/> when the extension is allowed; otherwise <see langword="false"/>.</returns>
 55    public bool IsValidPath(string path)
 56    {
 1257        if (string.IsNullOrWhiteSpace(path))
 358            return false;
 59
 960        var extension = NormalizeExtension(Path.GetExtension(path));
 961        return AllowedExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase);
 62    }
 63
 4264    private static string NormalizeExtension(string extension) => string.IsNullOrWhiteSpace(extension) ? string.Empty : 
 65}
 66