< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Dispatcher.OperationInvokerBehavior
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Dispatcher/OperationInvokerBehavior.cs
Line coverage
74%
Covered lines: 41
Uncovered lines: 14
Coverable lines: 55
Total lines: 150
Line coverage: 74.5%
Branch coverage
53%
Covered branches: 16
Total branches: 30
Branch coverage: 53.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Dispatcher/OperationInvokerBehavior.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Linq;
 7using System.Reflection;
 8using CoreWCF.Channels;
 9using CoreWCF.Description;
 10using Microsoft.Extensions.DependencyInjection;
 11
 12namespace CoreWCF.Dispatcher
 13{
 14    public class OperationInvokerBehavior : IOperationBehavior
 15    {
 16        private IServiceProvider _serviceProvider;
 17
 1018        private static readonly Lazy<bool> s_isOperationInvokerGeneratorEnabled = new Lazy<bool>(() =>
 1019        {
 1020            if (AppContext.TryGetSwitch("CoreWCF.Dispatcher.UseGeneratedOperationInvokers", out var value))
 1021            {
 022                return value;
 1023            }
 1024
 1025            Assembly entryAssembly = Assembly.GetEntryAssembly();
 1026            // return null when running UT with Xunit and .NET Framework
 1027            if (entryAssembly != null)
 1028            {
 1029                var assemblyAttributeArgsData = entryAssembly
 1030                    .GetCustomAttributesData()
 18831                    .Where(static data => data.AttributeType == typeof(EnableCoreWCFOperationInvokerGeneratorAttribute))
 032                    .SelectMany(static data => data.ConstructorArguments)
 033                    .Where(static data => data.ArgumentType == typeof(bool))
 1034                    .ToList();
 1035
 1036                if (assemblyAttributeArgsData.Count > 0)
 1037                {
 038                    return assemblyAttributeArgsData[0].Value is true;
 1039                }
 1040            }
 1041
 1042            return true;
 1043        });
 44
 268645        public OperationInvokerBehavior()
 46        {
 47
 268648        }
 49
 50        void IOperationBehavior.Validate(OperationDescription description)
 51        {
 264552        }
 53
 54        void IOperationBehavior.AddBindingParameters(OperationDescription description, BindingParameterCollection parame
 55        {
 318756            _serviceProvider = parameters.Find<IServiceProvider>();
 318757        }
 58
 59        void IOperationBehavior.ApplyDispatchBehavior(OperationDescription description, DispatchOperation dispatch)
 60        {
 302661            if (dispatch == null)
 62            {
 063                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(dispatch));
 64            }
 302665            if (description == null)
 66            {
 067                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(description));
 68            }
 69
 302670            if (description.TaskMethod != null)
 71            {
 40972                if (s_isOperationInvokerGeneratorEnabled.Value)
 73                {
 40974                    if (DispatchOperationRuntimeHelpers.OperationInvokers.TryGetValue(DispatchOperationRuntimeHelpers.Ge
 75                    {
 40176                        dispatch.Invoker = invoker;
 77                    }
 78                    else
 79                    {
 80                        // Fallback to reflection-based invoker if generated invoker not found
 881                        dispatch.Invoker = new TaskMethodInvoker(_serviceProvider, description.TaskMethod, description.T
 82                    }
 83                }
 84                else
 85                {
 086                    dispatch.Invoker = new TaskMethodInvoker(_serviceProvider, description.TaskMethod, description.TaskT
 87                }
 88
 89            }
 261790            else if (description.SyncMethod != null)
 91            {
 261792                if (s_isOperationInvokerGeneratorEnabled.Value)
 93                {
 261794                    if (DispatchOperationRuntimeHelpers.OperationInvokers.TryGetValue(DispatchOperationRuntimeHelpers.Ge
 95                    {
 244296                        dispatch.Invoker = invoker;
 97                    }
 98                    else
 99                    {
 100                        // Fallback to reflection-based invoker if generated invoker not found
 175101                        if (description.BeginMethod != null)
 102                        {
 103                            // both sync and async methods are present on the contract
 0104                            dispatch.Invoker = new SyncMethodInvoker(_serviceProvider, description.SyncMethod);
 105                        }
 106                        else
 107                        {
 108                            // only sync method is present on the contract
 175109                            dispatch.Invoker = new SyncMethodInvoker(_serviceProvider, description.SyncMethod);
 110                        }
 111                    }
 112                }
 113                else
 114                {
 0115                    if (description.BeginMethod != null)
 116                    {
 117                        // both sync and async methods are present on the contract, check the preference
 118                        //OperationBehaviorAttribute operationBehaviorAttribute = description.Behaviors.Find<OperationBe
 119                        //if ((operationBehaviorAttribute != null) && operationBehaviorAttribute.PreferAsyncInvocation)
 120                        //{
 121                        //    dispatch.Invoker = new AsyncMethodInvoker(description.BeginMethod, description.EndMethod);
 122                        //}
 123                        //else
 124                        //{
 0125                        dispatch.Invoker = new SyncMethodInvoker(_serviceProvider, description.SyncMethod);
 126                        //}
 127                    }
 128                    else
 129                    {
 130                        // only sync method is present on the contract
 0131                        dispatch.Invoker = new SyncMethodInvoker(_serviceProvider, description.SyncMethod);
 132                    }
 133                }
 134            }
 135            else
 136            {
 0137                if (description.BeginMethod != null)
 138                {
 139                    // only async method is present on the contract
 0140                    throw new PlatformNotSupportedException();
 141                    //dispatch.Invoker = new AsyncMethodInvoker(description.BeginMethod, description.EndMethod);
 142                }
 143            }
 0144        }
 145
 146        void IOperationBehavior.ApplyClientBehavior(OperationDescription description, ClientOperation proxy)
 147        {
 2148        }
 149    }
 150}