< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Dispatcher.ImmutableClientRuntime
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Dispatcher/ImmutableClientRuntime.cs
Line coverage
50%
Covered lines: 41
Uncovered lines: 40
Coverable lines: 81
Total lines: 225
Line coverage: 50.6%
Branch coverage
27%
Covered branches: 10
Total branches: 36
Branch coverage: 27.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%44100%
AfterReceiveReply(...)16.66%6636.36%
BeforeSendRequest(...)16.66%6641.66%
InitializeChannel(...)0%660%
GetOperation(...)33.33%121242.1%
GetOperationByName(...)0%220%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Dispatcher/ImmutableClientRuntime.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.Reflection;
 7using CoreWCF.Runtime;
 8using CoreWCF.Telemetry;
 9
 10namespace CoreWCF.Dispatcher
 11{
 12    internal class ImmutableClientRuntime
 13    {
 14        private readonly IChannelInitializer[] _channelInitializers;
 15        private readonly IClientMessageInspector[] _messageInspectors;
 16        private readonly Dictionary<string, ProxyOperationRuntime> _operations;
 17        private readonly Dictionary<string, ActionMetadata> _actionMappings;
 18
 119        internal ImmutableClientRuntime(ClientRuntime behavior)
 20        {
 121            _channelInitializers = EmptyArray<IChannelInitializer>.ToArray(behavior.ChannelInitializers);
 22            //this.interactiveChannelInitializers = EmptyArray<IInteractiveChannelInitializer>.ToArray(behavior.Interact
 123            _messageInspectors = EmptyArray<IClientMessageInspector>.ToArray(behavior.MessageInspectors);
 24
 125            OperationSelector = behavior.OperationSelector;
 126            UseSynchronizationContext = behavior.UseSynchronizationContext;
 127            ValidateMustUnderstand = behavior.ValidateMustUnderstand;
 28
 129            UnhandledProxyOperation = new ProxyOperationRuntime(behavior.UnhandledClientOperation, this);
 30
 31            //this.addTransactionFlowProperties = behavior.AddTransactionFlowProperties;
 32
 133            _operations = new Dictionary<string, ProxyOperationRuntime>();
 134            _actionMappings = new Dictionary<string, ActionMetadata>();
 435            for (int i = 0; i < behavior.Operations.Count; i++)
 36            {
 137                ClientOperation operation = behavior.Operations[i];
 138                ProxyOperationRuntime operationRuntime = new ProxyOperationRuntime(operation, this);
 139                _operations.Add(operation.Name, operationRuntime);
 40            }
 41
 442            foreach (var clientOperation in behavior.ClientOperations)
 43            {
 144                _actionMappings[clientOperation.Action] = new ActionMetadata(
 145                    contractName: $"{behavior.ContractNamespace}{behavior.ContractName}",
 146                    operationName: clientOperation.Name);
 47            }
 48
 49
 150            CorrelationCount = _messageInspectors.Length + behavior.MaxParameterInspectors;
 151        }
 52
 53        internal int MessageInspectorCorrelationOffset
 54        {
 255            get { return 0; }
 56        }
 57
 58        internal int ParameterInspectorCorrelationOffset
 59        {
 260            get { return _messageInspectors.Length; }
 61        }
 62
 163        internal int CorrelationCount { get; }
 64
 365        internal IClientOperationSelector OperationSelector { get; }
 66
 067        internal ProxyOperationRuntime UnhandledProxyOperation { get; }
 68
 069        internal bool UseSynchronizationContext { get; }
 70
 271        internal bool ValidateMustUnderstand { get; set; }
 72
 73        internal void AfterReceiveReply(ref ProxyRpc rpc)
 74        {
 175            int offset = MessageInspectorCorrelationOffset;
 76            try
 77            {
 278                for (int i = 0; i < _messageInspectors.Length; i++)
 79                {
 080                    _messageInspectors[i].AfterReceiveReply(ref rpc.Reply, rpc.Correlation[offset + i]);
 81                    //if (TD.ClientMessageInspectorAfterReceiveInvokedIsEnabled())
 82                    //{
 83                    //    TD.ClientMessageInspectorAfterReceiveInvoked(rpc.EventTraceActivity, this.messageInspectors[i]
 84                    //}
 85                }
 186            }
 087            catch (Exception e)
 88            {
 089                if (Fx.IsFatal(e))
 90                {
 091                    throw;
 92                }
 093                if (ErrorBehavior.ShouldRethrowClientSideExceptionAsIs(e))
 94                {
 095                    throw;
 96                }
 097                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
 98            }
 199        }
 100
 101        internal void BeforeSendRequest(ref ProxyRpc rpc)
 102        {
 1103            int offset = MessageInspectorCorrelationOffset;
 104            try
 105            {
 1106                rpc.Request.Properties.Add(TelemetryContextMessageProperty.Name, new TelemetryContextMessageProperty(_ac
 107
 2108                for (int i = 0; i < _messageInspectors.Length; i++)
 109                {
 0110                    rpc.Correlation[offset + i] = _messageInspectors[i].BeforeSendRequest(ref rpc.Request, (IClientChann
 111                    //if (TD.ClientMessageInspectorBeforeSendInvokedIsEnabled())
 112                    //{
 113                    //    TD.ClientMessageInspectorBeforeSendInvoked(rpc.EventTraceActivity, this.messageInspectors[i].G
 114                    //}
 115                }
 1116            }
 0117            catch (Exception e)
 118            {
 0119                if (Fx.IsFatal(e))
 120                {
 0121                    throw;
 122                }
 0123                if (ErrorBehavior.ShouldRethrowClientSideExceptionAsIs(e))
 124                {
 0125                    throw;
 126                }
 0127                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
 128            }
 129
 130            //if (this.addTransactionFlowProperties)
 131            //{
 132            //    SendTransaction(ref rpc);
 133            //}
 1134        }
 135
 136        // this should not be inlined, since we want to JIT the reference to System.Transactions
 137        // only if transactions are being flowed.
 138        //[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 139        //static void SendTransaction(ref ProxyRpc rpc)
 140        //{
 141        //    System.ServiceModel.Channels.TransactionFlowProperty.Set(Transaction.Current, rpc.Request);
 142        //}
 143
 144        internal void InitializeChannel(IClientChannel channel)
 145        {
 146            try
 147            {
 0148                for (int i = 0; i < _channelInitializers.Length; ++i)
 149                {
 0150                    _channelInitializers[i].Initialize(channel);
 151                }
 0152            }
 0153            catch (Exception e)
 154            {
 0155                if (Fx.IsFatal(e))
 156                {
 0157                    throw;
 158                }
 0159                if (ErrorBehavior.ShouldRethrowClientSideExceptionAsIs(e))
 160                {
 0161                    throw;
 162                }
 0163                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
 164            }
 0165        }
 166
 167        internal ProxyOperationRuntime GetOperation(MethodBase methodBase, object[] args, out bool canCacheResult)
 168        {
 1169            if (OperationSelector == null)
 170            {
 0171                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException
 0172                                                        (SR.Format(SR.SFxNeedProxyBehaviorOperationSelector2, methodBase
 0173                                                                      methodBase.DeclaringType.Name)));
 174            }
 175
 176            try
 177            {
 1178                if (OperationSelector.AreParametersRequiredForSelection)
 179                {
 0180                    canCacheResult = false;
 181                }
 182                else
 183                {
 1184                    args = null;
 1185                    canCacheResult = true;
 186                }
 1187                string operationName = OperationSelector.SelectOperation(methodBase, args);
 1188                if ((operationName != null) && _operations.TryGetValue(operationName, out ProxyOperationRuntime operatio
 189                {
 1190                    return operation;
 191                }
 192                else
 193                {
 194                    // did not find the right operation, will not know how
 195                    // to invoke the method.
 0196                    return null;
 197                }
 198            }
 0199            catch (Exception e)
 200            {
 0201                if (Fx.IsFatal(e))
 202                {
 0203                    throw;
 204                }
 0205                if (ErrorBehavior.ShouldRethrowClientSideExceptionAsIs(e))
 206                {
 0207                    throw;
 208                }
 0209                throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e);
 210            }
 1211        }
 212
 213        internal ProxyOperationRuntime GetOperationByName(string operationName)
 214        {
 0215            if (_operations.TryGetValue(operationName, out ProxyOperationRuntime operation))
 216            {
 0217                return operation;
 218            }
 219            else
 220            {
 0221                return null;
 222            }
 223        }
 224    }
 225}