< Summary

Information
Class: Elsa.Mediator.Middleware.MiddlewareHelpers
Assembly: Elsa.Mediator
File(s): /home/runner/work/elsa-core/elsa-core/src/common/Elsa.Mediator/Middleware/MiddlewareHelpers.cs
Line coverage
66%
Covered lines: 6
Uncovered lines: 3
Coverable lines: 9
Total lines: 38
Line coverage: 66.6%
Branch coverage
60%
Covered branches: 6
Total branches: 10
Branch coverage: 60%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetInvokeMethod(...)60%141066.66%

File(s)

/home/runner/work/elsa-core/elsa-core/src/common/Elsa.Mediator/Middleware/MiddlewareHelpers.cs

#LineLine coverage
 1using System.Reflection;
 2
 3namespace Elsa.Mediator.Middleware;
 4
 5/// <summary>
 6/// Provides a set of static methods for working with middleware.
 7/// </summary>
 8public static class MiddlewareHelpers
 9{
 10    /// <summary>
 11    /// Gets the Invoke or InvokeAsync method from the middleware type.
 12    /// </summary>
 13    /// <param name="middleware">The middleware type.</param>
 14    /// <returns>The Invoke or InvokeAsync method.</returns>
 15    /// <exception cref="InvalidOperationException">Thrown when the Invoke or InvokeAsync method cannot be found or the 
 16    public static MethodInfo GetInvokeMethod(Type middleware)
 17    {
 18        const string invokeMethodName = "Invoke";
 19        const string invokeAsyncMethodName = "InvokeAsync";
 320        var methods = middleware.GetMethods(BindingFlags.Instance | BindingFlags.Public);
 1821        var invokeMethods = methods.Where(m => string.Equals(m.Name, invokeMethodName, StringComparison.Ordinal) || stri
 22
 323        switch (invokeMethods.Length)
 24        {
 25            case > 1:
 026                throw new InvalidOperationException("Multiple Invoke methods were found. Use either Invoke or InvokeAsyn
 27            case 0:
 028                throw new InvalidOperationException("No Invoke methods were found. Use either Invoke or InvokeAsync");
 29        }
 30
 331        var methodInfo = invokeMethods[0];
 32
 333        if (!typeof(Task).IsAssignableFrom(methodInfo.ReturnType) && !typeof(ValueTask).IsAssignableFrom(methodInfo.Retu
 034            throw new InvalidOperationException($"The {methodInfo.Name} method must return Task or ValueTask");
 35
 336        return methodInfo;
 37    }
 38}

Methods/Properties

GetInvokeMethod(System.Type)