< Summary

Information
Class: Elsa.Extensions.WorkflowExtensions
Assembly: Elsa.Workflows.Management
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Extensions/WorkflowExtensions.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 17
Coverable lines: 17
Total lines: 61
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
WithVersion(...)0%156120%
WithVersion(...)100%210%
WithVersion(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Management/Extensions/WorkflowExtensions.cs

#LineLine coverage
 1using Elsa.Common.Models;
 2using Elsa.Workflows.Activities;
 3using JetBrains.Annotations;
 4
 5// ReSharper disable once CheckNamespace
 6namespace Elsa.Extensions;
 7
 8/// <summary>
 9/// Provides a set of extension methods for <see cref="Workflow"/>.
 10/// </summary>
 11[PublicAPI]
 12public static class WorkflowExtensions
 13{
 14    /// <summary>
 15    /// Returns true if the specified workflow matches the specified version options.
 16    /// </summary>
 17    /// <param name="workflow">The workflow to check.</param>
 18    /// <param name="version">The version options.</param>
 19    /// <returns>True if the workflow matches the version options; otherwise, false.</returns>
 20    public static bool WithVersion(this Workflow workflow, VersionOptions version)
 21    {
 022        var identity = workflow.Identity;
 023        var (isLatest, isPublished) = workflow.Publication;
 24
 025        if (version.IsDraft)
 026            return !isPublished;
 027        if (version.IsLatest)
 028            return isLatest;
 029        if (version.IsPublished)
 030            return isPublished;
 031        if (version.IsLatestOrPublished)
 032            return isPublished || isLatest;
 033        if (version.AllVersions)
 034            return true;
 035        if (version.Version > 0)
 036            return identity.Version == version.Version;
 037        return true;
 38    }
 39
 40    /// <summary>
 41    /// Applies the specified version options to the query.
 42    /// </summary>
 43    /// <param name="query">The query to apply the version options to.</param>
 44    /// <param name="version">The version options.</param>
 45    /// <returns>The query.</returns>
 46    public static IEnumerable<Workflow> WithVersion(
 47        this IEnumerable<Workflow> query,
 48        VersionOptions version) =>
 049        query.Where(x => x.WithVersion(version)).OrderByDescending(x => x.Identity.Version);
 50
 51    /// <summary>
 52    /// Applies the specified version options to the query.
 53    /// </summary>
 54    /// <param name="query">The query to apply the version options to.</param>
 55    /// <param name="version">The version options.</param>
 56    /// <returns>The query.</returns>
 57    public static IQueryable<Workflow> WithVersion(
 58        this IQueryable<Workflow> query,
 59        VersionOptions version) =>
 060        query.Where(x => x.WithVersion(version)).OrderByDescending(x => x.Identity.Version);
 61}