< Summary - SonghayCore

Information
Class: Songhay.Extensions.MenuDisplayItemModelExtensions
Assembly: SonghayCore
File(s): /home/rasx/sourceRoot/SonghayCore/SonghayCore/Extensions/MenuDisplayItemModelExtensions.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 22
Coverable lines: 22
Total lines: 65
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 20
Branch coverage: 0%
Method coverage

Method coverage is only available for sponsors.

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
HasGroupId(...)0%40%
DefaultOrFirst(...)0%60%
WithChildItem(...)0%40%
WithChildItems(...)0%60%

File(s)

/home/rasx/sourceRoot/SonghayCore/SonghayCore/Extensions/MenuDisplayItemModelExtensions.cs

#LineLine coverage
 1namespace Songhay.Extensions;
 2
 3/// <summary>
 4/// Extensions of <see cref="MenuDisplayItemModel"/>
 5/// </summary>
 6public static class MenuDisplayItemModelExtensions
 7{
 8    /// <summary>
 9    /// Returns <c>true</c> when the grouping has the specified identifier.
 10    /// </summary>
 11    /// <param name="data"></param>
 12    /// <param name="groupId"></param>
 013    public static bool HasGroupId(this MenuDisplayItemModel? data, string groupId) => data != null &&
 014        (!string.IsNullOrWhiteSpace(groupId) && data.GroupId.EqualsInvariant(groupId));
 15
 16    /// <summary>
 17    /// Returns the Default Selection
 18    /// <c>IsDefaultSelection == true</c>
 19    /// or the First <see cref="MenuDisplayItemModel"/>.
 20    /// </summary>
 21    /// <param name="data">The data.</param>
 22    public static MenuDisplayItemModel? DefaultOrFirst(this IEnumerable<MenuDisplayItemModel>? data)
 023    {
 024        if (data == null) return null;
 25
 026        var snapshot = data as MenuDisplayItemModel[] ?? data.ToArray();
 27
 028        return snapshot.Any(i => i.IsDefaultSelection == true)
 029            ? snapshot.FirstOrDefault(i => i.IsDefaultSelection == true)
 030            : snapshot.FirstOrDefault();
 031    }
 32
 33    /// <summary>
 34    /// Fluently returns <see cref="MenuDisplayItemModel" /> with child item.
 35    /// </summary>
 36    /// <param name="data">The data.</param>
 37    /// <param name="child">The child.</param>
 38    public static MenuDisplayItemModel? WithChildItem(this MenuDisplayItemModel? data, MenuDisplayItemModel? child)
 039    {
 040        if (data == null) return null;
 041        if (child == null) return data;
 42
 043        data.ChildItems = new[] {child};
 44
 045        return data;
 046    }
 47
 48    /// <summary>
 49    /// Fluently returns <see cref="MenuDisplayItemModel" /> with child items.
 50    /// </summary>
 51    /// <param name="data">The data.</param>
 52    /// <param name="items">The items.</param>
 53    public static MenuDisplayItemModel? WithChildItems(this MenuDisplayItemModel? data,
 54        IEnumerable<MenuDisplayItemModel>? items)
 055    {
 056        if (data == null) return null;
 057        if (items == null) return data;
 58
 059        var snapshot = items as MenuDisplayItemModel[] ?? items.ToArray();
 60
 061        data.ChildItems = snapshot.ToArray();
 62
 063        return data;
 064    }
 65}