< Summary

Information
Class: Elsa.Api.Client.Shared.Models.VersionOptions
Assembly: Elsa.Api.Client
File(s): /home/runner/work/elsa-core/elsa-core/src/clients/Elsa.Api.Client/Shared/Models/VersionOptions.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 27
Coverable lines: 27
Total lines: 118
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 24
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%210%
SpecificVersion(...)100%210%
FromString(...)0%156120%
TryParse(...)100%210%
get_IsLatest()100%210%
get_IsLatestOrPublished()100%210%
get_IsLatestAndPublished()100%210%
get_IsPublished()100%210%
get_IsDraft()100%210%
get_AllVersions()100%210%
get_Version()100%210%
ToString()0%156120%

File(s)

/home/runner/work/elsa-core/elsa-core/src/clients/Elsa.Api.Client/Shared/Models/VersionOptions.cs

#LineLine coverage
 1using System.ComponentModel;
 2using System.Globalization;
 3using System.Text.Json.Serialization;
 4using Elsa.Api.Client.Converters;
 5using JetBrains.Annotations;
 6
 7namespace Elsa.Api.Client.Shared.Models;
 8
 9/// <summary>
 10/// Represents the version to get.
 11/// </summary>
 12[PublicAPI]
 13[TypeConverter(typeof(VersionOptionsTypeConverter))]
 14[JsonConverter(typeof(VersionOptionsJsonConverter))]
 15public struct VersionOptions
 16{
 17    /// <summary>
 18    /// Gets the latest version.
 19    /// </summary>
 020    public static readonly VersionOptions Latest = new() { IsLatest = true };
 21
 22    /// <summary>
 23    /// Gets the published version.
 24    /// </summary>
 025    public static readonly VersionOptions Published = new() { IsPublished = true };
 26
 27    /// <summary>
 28    /// Gets the published version if available, and if not, the latest version.
 29    /// </summary>
 030    public static readonly VersionOptions LatestOrPublished = new() { IsLatestOrPublished = true };
 31
 32    /// <summary>
 33    /// Gets the latest, published version.
 34    /// </summary>
 035    public static readonly VersionOptions LatestAndPublished = new() { IsLatestAndPublished = true };
 36
 37    /// <summary>
 38    /// Gets the draft version.
 39    /// </summary>
 040    public static readonly VersionOptions Draft = new() { IsDraft = true };
 41
 42    /// <summary>
 43    /// Gets all versions.
 44    /// </summary>
 045    public static readonly VersionOptions All = new() { AllVersions = true };
 46
 47    /// <summary>
 48    /// Gets a specific version.
 49    /// </summary>
 050    public static VersionOptions SpecificVersion(int version) => new() { Version = version };
 51
 52    /// <summary>
 53    /// Parses a string into a <see cref="VersionOptions"/>.
 54    /// </summary>
 55    public static VersionOptions FromString(string value) =>
 056        value switch
 057        {
 058            "AllVersions" => All,
 059            "Draft" => Draft,
 060            "Latest" => Latest,
 061            "Published" => Published,
 062            "LatestOrPublished" => LatestOrPublished,
 063            "LatestAndPublished" => LatestAndPublished,
 064            _ => SpecificVersion(int.Parse(value, CultureInfo.InvariantCulture))
 065        };
 66
 67    /// <summary>
 68    /// Tries to parse a string into a <see cref="VersionOptions"/>.
 69    /// </summary>
 70    /// <param name="value">The value to parse.</param>
 71    /// <param name="versionOptions">The parsed value.</param>
 72    /// <returns><c>true</c> if the value was parsed successfully, otherwise <c>false</c>.</returns>
 73    public static bool TryParse(string value, out VersionOptions versionOptions)
 74    {
 075        versionOptions = FromString(value);
 076        return true;
 77    }
 78
 79    /// <summary>
 80    /// Gets the latest version.
 81    /// </summary>
 082    public bool IsLatest { get; private set; }
 83
 84    /// <summary>
 85    /// Gets the published version if available, and if not, the latest version.
 86    /// </summary>
 087    public bool IsLatestOrPublished { get; private set; }
 88
 89    /// <summary>
 90    /// Gets the latest, published version.
 91    /// </summary>
 092    public bool IsLatestAndPublished { get; private set; }
 93
 94    /// <summary>
 95    /// Gets the published version.
 96    /// </summary>
 097    public bool IsPublished { get; private set; }
 98
 99    /// <summary>
 100    /// Gets the draft version.
 101    /// </summary>
 0102    public bool IsDraft { get; private set; }
 103
 104    /// <summary>
 105    /// Gets all versions.
 106    /// </summary>
 0107    public bool AllVersions { get; private set; }
 108
 109    /// <summary>
 110    /// Gets a specific version.
 111    /// </summary>
 0112    public int Version { get; private set; }
 113
 114    /// <summary>
 115    /// Returns a simple string representation of this <see cref="VersionOptions"/>.
 116    /// </summary>
 0117    public override string ToString() => AllVersions ? "AllVersions" : IsDraft ? "Draft" : IsLatest ? "Latest" : IsPubli
 118}