< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Description.ServiceEndpoint
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Description/ServiceEndpoint.cs
Line coverage
69%
Covered lines: 52
Uncovered lines: 23
Coverable lines: 75
Total lines: 232
Line coverage: 69.3%
Branch coverage
60%
Covered branches: 23
Total branches: 38
Branch coverage: 60.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)50%22100%
.ctor(...)50%22100%
EnsureInvariants()50%4471.42%
ValidateForClient()100%110%
ValidateForService(...)100%11100%
InternalIsSystemEndpoint(...)100%11100%
Validate(...)100%1010100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Description/ServiceEndpoint.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.ObjectModel;
 6using System.Globalization;
 7using CoreWCF.Channels;
 8using CoreWCF.Collections.Generic;
 9
 10namespace CoreWCF.Description
 11{
 12    public class ServiceEndpoint
 13    {
 14        private ContractDescription _contract;
 15        private Uri _listenUri;
 16        private ListenUriMode _listenUriMode = ListenUriMode.Explicit;
 17        private KeyedByTypeCollection<IEndpointBehavior> _behaviors;
 18        private string _id;
 19        private XmlName _name;
 20
 4221        public ServiceEndpoint(ContractDescription contract)
 22        {
 4223            _contract = contract ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(contract));
 4224        }
 25
 64126        public ServiceEndpoint(ContractDescription contract, Binding binding, EndpointAddress address)
 27        {
 64128            _contract = contract ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(contract));
 64129            Binding = binding;
 64130            Address = address;
 64131        }
 32
 712933        public EndpointAddress Address { get; set; }
 34
 35        public KeyedCollection<Type, IEndpointBehavior> EndpointBehaviors
 36        {
 296937            get { return Behaviors; }
 38        }
 39
 40        internal KeyedByTypeCollection<IEndpointBehavior> Behaviors
 41        {
 42            get
 43            {
 572644                if (_behaviors == null)
 45                {
 67346                    _behaviors = new KeyedByTypeCollection<IEndpointBehavior>();
 47                }
 48
 572649                return _behaviors;
 50            }
 51        }
 52
 821953        public Binding Binding { get; set; }
 54
 55        public ContractDescription Contract
 56        {
 1475957            get { return _contract; }
 58            set
 59            {
 060                _contract = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value));
 061            }
 62        }
 63
 64        public bool IsSystemEndpoint
 65        {
 189066            get;
 067            set;
 68        }
 69
 70        public string Name
 71        {
 72            get
 73            {
 9674                if (!XmlName.IsNullOrEmpty(_name))
 75                {
 6476                    return _name.EncodedName;
 77                }
 3278                else if (Binding != null)
 79                {
 3280                    return string.Format(CultureInfo.InvariantCulture, "{0}_{1}", new XmlName(Binding.Name).EncodedName,
 81                }
 82                else
 83                {
 084                    return Contract.Name;
 85                }
 86            }
 87            set
 88            {
 3289                _name = new XmlName(value, true /*isEncoded*/);
 3290            }
 91        }
 92
 93        public Uri ListenUri
 94        {
 95            get
 96            {
 64197                if (_listenUri == null)
 98                {
 64199                    if (Address == null)
 100                    {
 0101                        return null;
 102                    }
 103                    else
 104                    {
 641105                        return Address.Uri;
 106                    }
 107                }
 108                else
 109                {
 0110                    return _listenUri;
 111                }
 112            }
 113            set
 114            {
 0115                if (value != null && !value.IsAbsoluteUri)
 116                {
 0117                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(value), SR.UriMustBeAbsolute);
 118                }
 0119                _listenUri = value;
 0120            }
 121        }
 122
 123        internal ListenUriMode ListenUriMode
 124        {
 641125            get { return _listenUriMode; }
 126            set
 127            {
 0128                if (!ListenUriModeHelper.IsDefined(value))
 129                {
 0130                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 131                }
 0132                _listenUriMode = value;
 0133            }
 134        }
 135
 136        public string Id
 137        {
 138            get
 139            {
 673140                if (_id == null)
 141                {
 641142                    _id = Guid.NewGuid().ToString();
 143                }
 144
 673145                return _id;
 146            }
 147        }
 148
 149        internal Uri UnresolvedAddress
 150        {
 0151            get;
 0152            set;
 153        }
 154
 155        internal Uri UnresolvedListenUri
 156        {
 0157            get;
 0158            set;
 159        }
 160
 161        // This method ensures that the description object graph is structurally sound and that none
 162        // of the fundamental SFx framework assumptions have been violated.
 163        internal void EnsureInvariants()
 164        {
 641165            if (Binding == null)
 166            {
 0167                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.AChannelServi
 168            }
 641169            if (Contract == null)
 170            {
 0171                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.AChannelServi
 172            }
 641173            Contract.EnsureInvariants();
 641174            Binding.EnsureInvariants(Contract.Name);
 641175        }
 176
 177        internal void ValidateForClient()
 178        {
 0179            Validate(true, false);
 0180        }
 181
 182        internal void ValidateForService(bool runOperationValidators)
 183        {
 641184            Validate(runOperationValidators, true);
 641185        }
 186
 0187        internal bool IsFullyConfigured { get; set; } = false;
 188
 189        // for V1 legacy reasons, a mex endpoint is considered a system endpoint even if IsSystemEndpoint = false
 190        internal bool InternalIsSystemEndpoint(ServiceDescription description)
 191        {
 192            //if (ServiceMetadataBehavior.IsMetadataEndpoint(description, this))
 193            //{
 194            //    return true;
 195            //}
 1858196            return IsSystemEndpoint;
 197        }
 198
 199        // This method runs validators (both builtin and ones in description).
 200        // Precondition: EnsureInvariants() should already have been called.
 201        private void Validate(bool runOperationValidators, bool isForService)
 202        {
 203            // contract behaviors
 641204            ContractDescription contract = Contract;
 2576205            for (int j = 0; j < contract.ContractBehaviors.Count; j++)
 206            {
 647207                IContractBehavior iContractBehavior = contract.ContractBehaviors[j];
 647208                iContractBehavior.Validate(contract, this);
 209            }
 210            // endpoint behaviors
 2720211            for (int j = 0; j < EndpointBehaviors.Count; j++)
 212            {
 719213                IEndpointBehavior ieb = EndpointBehaviors[j];
 719214                ieb.Validate(this);
 215            }
 216            // operation behaviors
 641217            if (runOperationValidators)
 218            {
 6444219                for (int j = 0; j < contract.Operations.Count; j++)
 220                {
 2645221                    OperationDescription op = contract.Operations[j];
 2645222                    TaskOperationDescriptionValidator.Validate(op, isForService);
 21500223                    for (int k = 0; k < op.OperationBehaviors.Count; k++)
 224                    {
 8105225                        IOperationBehavior iob = op.OperationBehaviors[k];
 8105226                        iob.Validate(op);
 227                    }
 228                }
 229            }
 641230        }
 231    }
 232}