< Summary

Information
Class: Elsa.Workflows.ItemSourceActivityExecutionContextExtensions
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Extensions/ItemSourceActivityExecutionContextExtensions.cs
Line coverage
55%
Covered lines: 10
Uncovered lines: 8
Coverable lines: 18
Total lines: 50
Line coverage: 55.5%
Branch coverage
46%
Covered branches: 12
Total branches: 26
Branch coverage: 46.1%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetItemSource()46.15%852655.55%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Extensions/ItemSourceActivityExecutionContextExtensions.cs

#LineLine coverage
 1using System.Collections;
 2using Elsa.Workflows.Models;
 3
 4namespace Elsa.Workflows;
 5
 6/// <summary>
 7/// Provides extension methods for the ActivityExecutionContext class.
 8/// </summary>
 9public static class ItemSourceActivityExecutionContextExtensions
 10{
 11    /// <summary>
 12    /// Retrieves the item source and returns it as an asynchronous enumerable.
 13    /// Supported types are <see cref="IEnumerable{T}"/>, <see cref="IAsyncEnumerable{T}"/> and <see> <cref>IAsyncEnumer
 14    /// </summary>
 15    /// <typeparam name="T">The type of the items in the source collection.</typeparam>
 16    /// <param name="context">The activity execution context.</param>
 17    /// <param name="input">The input object.</param>
 18    /// <returns>An asynchronous enumerable of items from the source collection.</returns>
 19    public static async IAsyncEnumerable<T> GetItemSource<T>(this ActivityExecutionContext context, Input<object> input)
 20    {
 2121        var items = context.Get(input);
 22
 2123        if (items == null)
 124            yield break;
 25
 2026        var itemsType = items.GetType();
 2027        if (itemsType.Name == "AsyncEnumerableAdapter`1")
 28        {
 029            var isBatch = itemsType.GenericTypeArguments.Length == 1 && typeof(IEnumerable).IsAssignableFrom(itemsType.G
 30
 031            if (isBatch)
 32            {
 033                if(items is IAsyncEnumerable<IEnumerable<T>> typedItems)
 034                    await foreach (var typedItem in typedItems)
 035                    foreach (T item in typedItem)
 036                        yield return item;
 37            }
 38        }
 2039        else if (items is IAsyncEnumerable<T> asyncEnumerable)
 40        {
 041            await foreach (T item in asyncEnumerable)
 042                yield return item;
 43        }
 2044        else if (items is IEnumerable<T> enumerable)
 45        {
 12846            foreach (T item in enumerable)
 4447                yield return item;
 48        }
 2149    }
 50}

Methods/Properties

GetItemSource()