< Summary

Information
Class: Pozitron.QuerySpecification.SpecificationExtensions
Assembly: Pozitron.QuerySpecification
File(s): /home/runner/work/QuerySpecification/QuerySpecification/src/QuerySpecification/SpecificationExtensions.cs
Tag: 67_15587897385
Line coverage
100%
Covered lines: 6
Uncovered lines: 0
Coverable lines: 6
Total lines: 35
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
WithProjectionOf(...)100%66100%

File(s)

/home/runner/work/QuerySpecification/QuerySpecification/src/QuerySpecification/SpecificationExtensions.cs

#LineLine coverage
 1namespace Pozitron.QuerySpecification;
 2
 3/// <summary>
 4/// Extension methods for specifications.
 5/// </summary>
 6public static class SpecificationExtensions
 7{
 8    /// <summary>
 9    /// Creates a new specification by applying a projection specification to the current specification.
 10    /// </summary>
 11    /// <remarks>This method clones the source specification and applies the projection specification's select
 12    /// statements to create a new specification. The input specifications remain unchanged.</remarks>
 13    /// <typeparam name="T">The type of the entity.</typeparam>
 14    /// <typeparam name="TResult">The type of the result.</typeparam>
 15    /// <param name="source">The source specification to which the projection will be applied. Cannot be <see langword="
 16    /// <param name="projectionSpec">The projection specification that defines the transformation to apply to the source
 17    /// <see langword="null"/>.</param>
 18    /// <returns>A new <see cref="Specification{T, TResult}"/> that represents the result of applying the projection to 
 19    /// source specification.</returns>
 20    public static Specification<T, TResult> WithProjectionOf<T, TResult>(this Specification<T> source, Specification<T, 
 21    {
 322        var newSpec = source.Clone<TResult>();
 23
 1124        foreach (var item in projectionSpec.Items)
 25        {
 326            if (item.Type == ItemType.Select && item.Reference is not null)
 27            {
 128                newSpec.AddOrUpdateInternal(item.Type, item.Reference, item.Bag);
 129                return newSpec;
 30            }
 31        }
 32
 233        return newSpec;
 34    }
 35}