< Summary

Information
Class: Fluorite.Strainer.Services.Sorting.DescendingPrefixSortingWayFormatter
Assembly: Fluorite.Strainer
File(s): /builds/fluorite/strainer/src/Strainer/Services/Sorting/DescendingPrefixSortingWayFormatter.cs
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 81
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
Format(...)100%44100%
GetSortingWay(...)100%44100%
Unformat(...)100%22100%

File(s)

/builds/fluorite/strainer/src/Strainer/Services/Sorting/DescendingPrefixSortingWayFormatter.cs

#LineLine coverage
 1using Fluorite.Extensions;
 2using Fluorite.Strainer.Models.Sorting;
 3
 4namespace Fluorite.Strainer.Services.Sorting;
 5
 6/// <summary>
 7/// Provides sorting way formatter based on presence of descending prefix.
 8/// </summary>
 9public class DescendingPrefixSortingWayFormatter : ISortingWayFormatter
 10{
 11    /// <summary>
 12    /// The prefix used to mark a descending sorting term by this formatter.
 13    /// <para/>
 14    /// This field is readonly.
 15    /// </summary>
 16    public const string DescendingPrefix = "-";
 17
 18    /// <summary>
 19    /// Initializes a new instance of the <see cref="DescendingPrefixSortingWayFormatter"/>
 20    /// class.
 21    /// </summary>
 1922    public DescendingPrefixSortingWayFormatter()
 23    {
 24
 1925    }
 26
 27    /// <inheritdoc/>
 28    /// <exception cref="ArgumentNullException">
 29    /// <paramref name="input"/> is <see langword="null" />.
 30    /// </exception>
 31    public string Format(string input, SortingWay sortingWay)
 32    {
 733        Guard.Against.Null(input);
 34
 635        if (string.IsNullOrWhiteSpace(input))
 36        {
 437            return input;
 38        }
 39
 240        return sortingWay == SortingWay.Descending
 241            ? DescendingPrefix + input
 242            : input;
 43    }
 44
 45    /// <inheritdoc/>
 46    /// <exception cref="ArgumentNullException">
 47    /// <paramref name="input"/> is <see langword="null" />.
 48    /// </exception>
 49    public SortingWay? GetSortingWay(string input)
 50    {
 551        Guard.Against.Null(input);
 52
 453        if (string.IsNullOrWhiteSpace(input))
 54        {
 255            return null;
 56        }
 57
 258        if (input.StartsWith(DescendingPrefix))
 59        {
 160            return SortingWay.Descending;
 61        }
 62
 163        return SortingWay.Ascending;
 64    }
 65
 66    /// <inheritdoc/>
 67    /// <exception cref="ArgumentNullException">
 68    /// <paramref name="input"/> is <see langword="null"/>.
 69    /// </exception>
 70    public string Unformat(string input, SortingWay sortingWay)
 71    {
 672        Guard.Against.Null(input);
 73
 574        if (string.IsNullOrEmpty(input))
 75        {
 176            return input;
 77        }
 78
 479        return input.TrimStartOnce(DescendingPrefix);
 80    }
 81}