< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Dispatcher.EndpointDispatcher
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Dispatcher/EndpointDispatcher.cs
Line coverage
57%
Covered lines: 56
Uncovered lines: 41
Coverable lines: 97
Total lines: 292
Line coverage: 57.7%
Branch coverage
52%
Covered branches: 21
Total branches: 40
Branch coverage: 52.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)50%2291.66%
.ctor(...)0%220%
AddEndpointDispatcher(...)100%110%
Attach(...)50%4460%
Detach(...)0%440%
ThrowIfDisposedOrImmutable()100%22100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Dispatcher/EndpointDispatcher.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 CoreWCF.Channels;
 7
 8namespace CoreWCF.Dispatcher
 9{
 10    public class EndpointDispatcher
 11    {
 12        private MessageFilter _addressFilter;
 13        private MessageFilter _contractFilter;
 14        private MessageFilter _endpointFilter;
 15        private EndpointIdentity _identity;
 16
 17        internal EndpointDispatcher(EndpointAddress address, string contractName, string contractNamespace, string id, b
 64118            : this(address, contractName, contractNamespace)
 19        {
 64120            Id = id;
 64121            IsSystemEndpoint = isSystemEndpoint;
 64122        }
 23
 24        public EndpointDispatcher(EndpointAddress address, string contractName, string contractNamespace)
 64125            : this(address, contractName, contractNamespace, false)
 26        {
 64127        }
 28
 66429        public EndpointDispatcher(EndpointAddress address, string contractName, string contractNamespace, bool isSystemE
 30        {
 66431            OriginalAddress = address;
 66432            ContractName = contractName;
 66433            ContractNamespace = contractNamespace;
 34
 66435            if (address != null)
 36            {
 66437                _addressFilter = new EndpointAddressMessageFilter(address);
 38            }
 39            else
 40            {
 041                _addressFilter = new MatchAllMessageFilter();
 42            }
 43
 66444            _contractFilter = new MatchAllMessageFilter();
 66445            DispatchRuntime = new DispatchRuntime(this);
 66446            FilterPriority = 0;
 66447            IsSystemEndpoint = isSystemEndpoint;
 66448        }
 49
 050        private EndpointDispatcher(EndpointDispatcher baseEndpoint, IEnumerable<AddressHeader> headers)
 51        {
 052            EndpointAddressBuilder builder = new EndpointAddressBuilder(baseEndpoint.EndpointAddress);
 053            foreach (AddressHeader h in headers)
 54            {
 055                builder.Headers.Add(h);
 56            }
 057            EndpointAddress address = builder.ToEndpointAddress();
 58
 059            _addressFilter = new EndpointAddressMessageFilter(address);
 60            // channelDispatcher is Attached
 061            _contractFilter = baseEndpoint.ContractFilter;
 062            ContractName = baseEndpoint.ContractName;
 063            ContractNamespace = baseEndpoint.ContractNamespace;
 064            DispatchRuntime = baseEndpoint.DispatchRuntime;
 65            // endpointFilter is lazy
 066            FilterPriority = baseEndpoint.FilterPriority + 1;
 067            OriginalAddress = address;
 68            //if (PerformanceCounters.PerformanceCountersEnabled)
 69            //{
 70            //    this.perfCounterId = baseEndpoint.perfCounterId;
 71            //    this.perfCounterBaseId = baseEndpoint.perfCounterBaseId;
 72            //}
 073            Id = baseEndpoint.Id;
 074        }
 75
 76        public MessageFilter AddressFilter
 77        {
 078            get { return _addressFilter; }
 79            set
 80            {
 70181                ThrowIfDisposedOrImmutable();
 70182                _addressFilter = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value)
 70183                AddressFilterSetExplicit = true;
 70184            }
 85        }
 86
 134287        internal bool AddressFilterSetExplicit { get; private set; }
 88
 738989        public ChannelDispatcher ChannelDispatcher { get; private set; }
 90
 91        public MessageFilter ContractFilter
 92        {
 093            get { return _contractFilter; }
 94            set
 95            {
 70196                ThrowIfDisposedOrImmutable();
 70197                _contractFilter = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value
 70198            }
 99        }
 100
 538101        public string ContractName { get; }
 102
 505103        public string ContractNamespace { get; }
 104
 6165105        internal ServiceChannel DatagramChannel { get; set; }
 106
 18289107        public DispatchRuntime DispatchRuntime { get; }
 108
 0109        internal Uri ListenUri { get; }
 110
 781111        internal EndpointAddress OriginalAddress { get; }
 112
 113        public EndpointAddress EndpointAddress
 114        {
 115            get
 116            {
 35117                if (ChannelDispatcher == null)
 118                {
 0119                    return OriginalAddress;
 120                }
 121
 35122                if ((OriginalAddress != null) && (OriginalAddress.Identity != null))
 123                {
 0124                    return OriginalAddress;
 125                }
 126
 35127                if (OriginalAddress != null && _identity == null)
 128                {
 35129                    return OriginalAddress;
 130                }
 131
 132                EndpointAddressBuilder builder;
 0133                if (OriginalAddress != null)
 134                {
 0135                    builder = new EndpointAddressBuilder(OriginalAddress);
 0136                    builder.Identity = _identity;
 0137                    return builder.ToEndpointAddress();
 138                }
 139                else
 140                {
 0141                    return null;
 142                }
 143            }
 144        }
 145
 146        public EndpointIdentity Identity
 147        {
 0148            get { return _identity; }
 149            set
 150            {
 17151                if (value != _identity && _identity != null)
 152                {
 0153                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(value), SR.OnlySetIdentityOnce);
 154                }
 155
 17156                if (value == null)
 157                {
 0158                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value));
 159                }
 160
 17161                _identity = value;
 17162            }
 163        }
 164
 2570165        public bool IsSystemEndpoint { get; }
 166
 167        internal MessageFilter EndpointFilter
 168        {
 169            get
 170            {
 3181171                if (_endpointFilter == null)
 172                {
 661173                    MessageFilter addressFilter = _addressFilter;
 661174                    MessageFilter contractFilter = _contractFilter;
 175
 176                    // Can't optimize addressFilter similarly.
 177                    // AndMessageFilter tracks when the address filter matched so the correct
 178                    // fault can be sent back.
 661179                    if (contractFilter is MatchAllMessageFilter)
 180                    {
 47181                        _endpointFilter = addressFilter;
 182                    }
 183                    else
 184                    {
 614185                        _endpointFilter = new AndMessageFilter(addressFilter, contractFilter);
 186                    }
 187                }
 3181188                return _endpointFilter;
 189            }
 190        }
 191
 4509192        public int FilterPriority { get; set; }
 193
 692194        public string Id { get; set; }
 195
 196        //internal string PerfCounterId
 197        //{
 198        //    get { return this.perfCounterId; }
 199        //}
 200
 201        //internal string PerfCounterBaseId
 202        //{
 203        //    get { return this.perfCounterBaseId; }
 204        //}
 205
 0206        internal int PerfCounterInstanceId { get; set; }
 207
 208        internal static EndpointDispatcher AddEndpointDispatcher(EndpointDispatcher baseEndpoint,
 209                                                                 IEnumerable<AddressHeader> headers)
 210        {
 0211            EndpointDispatcher endpoint = new EndpointDispatcher(baseEndpoint, headers);
 0212            baseEndpoint.ChannelDispatcher.Endpoints.Add(endpoint);
 0213            return endpoint;
 214        }
 215
 216        internal void Attach(ChannelDispatcher channelDispatcher)
 217        {
 664218            if (ChannelDispatcher != null)
 219            {
 0220                Exception error = new InvalidOperationException(SR.SFxEndpointDispatcherMultipleChannelDispatcher0);
 0221                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(error);
 222            }
 223
 664224            ChannelDispatcher = channelDispatcher ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(na
 225            // TODO: Plumb through the listening Uri
 226            //listenUri = channelDispatcher.Listener?.Uri;
 664227        }
 228
 229        internal void Detach(ChannelDispatcher channelDispatcher)
 230        {
 0231            if (channelDispatcher == null)
 232            {
 0233                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(channelDispatcher));
 234            }
 235
 0236            if (ChannelDispatcher != channelDispatcher)
 237            {
 0238                Exception error = new InvalidOperationException(SR.SFxEndpointDispatcherDifferentChannelDispatcher0);
 0239                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(error);
 240            }
 241
 242            //this.ReleasePerformanceCounters();
 0243            ChannelDispatcher = null;
 0244        }
 245
 246        //internal void ReleasePerformanceCounters()
 247        //{
 248        //    if (PerformanceCounters.PerformanceCountersEnabled)
 249        //    {
 250        //        PerformanceCounters.ReleasePerformanceCountersForEndpoint(this.perfCounterId, this.perfCounterBaseId);
 251        //    }
 252        //}
 253
 254        //internal bool SetPerfCounterId()
 255        //{
 256        //    Uri keyUri = null;
 257        //    if (null != this.ListenUri)
 258        //    {
 259        //        keyUri = this.ListenUri;
 260        //    }
 261        //    else
 262        //    {
 263        //        EndpointAddress endpointAddress = this.EndpointAddress;
 264        //        if (null != endpointAddress)
 265        //        {
 266        //            keyUri = endpointAddress.Uri;
 267        //        }
 268        //    }
 269
 270        //    if (null != keyUri)
 271        //    {
 272        //        this.perfCounterBaseId = keyUri.AbsoluteUri.ToUpperInvariant();
 273        //        this.perfCounterId = this.perfCounterBaseId + "/" + contractName.ToUpperInvariant();
 274
 275        //        return true;
 276        //    }
 277        //    else
 278        //    {
 279        //        return false;
 280        //    }
 281        //}
 282
 283        private void ThrowIfDisposedOrImmutable()
 284        {
 1402285            ChannelDispatcher channelDispatcher = ChannelDispatcher;
 1402286            if (channelDispatcher != null)
 287            {
 715288                channelDispatcher.ThrowIfDisposedOrImmutable();
 289            }
 1402290        }
 291    }
 292}