< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.RemoteEndpointMessageProperty
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/RemoteEndpointMessageProperty.cs
Line coverage
57%
Covered lines: 24
Uncovered lines: 18
Coverable lines: 42
Total lines: 126
Line coverage: 57.1%
Branch coverage
45%
Covered branches: 9
Total branches: 20
Branch coverage: 45%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)50%6670%
.ctor(...)100%110%
.ctor(...)100%11100%
Initialize(...)16.66%6638.46%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/RemoteEndpointMessageProperty.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.Net;
 6
 7namespace CoreWCF.Channels
 8{
 9    public sealed class RemoteEndpointMessageProperty
 10    {
 11        private string _address;
 12        private int _port;
 13        private IPEndPoint _remoteEndPoint;
 14        private IRemoteEndpointProvider _remoteEndpointProvider;
 15        private InitializationState _state;
 16
 1117        public RemoteEndpointMessageProperty(string address, int port)
 18        {
 1119            if (string.IsNullOrEmpty(address))
 20            {
 021                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(address));
 22            }
 23
 1124            if (port < IPEndPoint.MinPort || port > IPEndPoint.MaxPort)
 25            {
 026                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(port),
 027                    SR.Format(SR.ValueMustBeInRange, IPEndPoint.MinPort, IPEndPoint.MaxPort));
 28            }
 29
 1130            _port = port;
 1131            _address = address;
 1132            _state = InitializationState.All;
 1133        }
 34
 035        internal RemoteEndpointMessageProperty(IRemoteEndpointProvider remoteEndpointProvider)
 36        {
 037            _remoteEndpointProvider = remoteEndpointProvider;
 038        }
 39
 73940        public RemoteEndpointMessageProperty(IPEndPoint remoteEndPoint)
 41        {
 73942            _remoteEndPoint = remoteEndPoint;
 73943        }
 44
 45        public const string Name = "CoreWCF.Channels.RemoteEndpointMessageProperty";
 46
 47        public string Address
 48        {
 49            get
 50            {
 3751                if ((_state & InitializationState.Address) != InitializationState.Address)
 52                {
 3553                    lock (ThisLock)
 54                    {
 3555                        if ((_state & InitializationState.Address) != InitializationState.Address)
 56                        {
 3557                            Initialize(false);
 58                        }
 3559                    }
 60                }
 3761                return _address;
 62            }
 63        }
 64
 65        public int Port
 66        {
 67            get
 68            {
 3469                if ((_state & InitializationState.Port) != InitializationState.Port)
 70                {
 071                    lock (ThisLock)
 72                    {
 073                        if ((_state & InitializationState.Port) != InitializationState.Port)
 74                        {
 075                            Initialize(true);
 76                        }
 077                    }
 78                }
 3479                return _port;
 80            }
 81        }
 82
 78583        private object ThisLock { get; } = new object();
 84
 85        private void Initialize(bool getHostedPort)
 86        {
 3587            if (_remoteEndPoint != null)
 88            {
 3589                _address = _remoteEndPoint.Address.ToString();
 3590                _port = _remoteEndPoint.Port;
 3591                _state = InitializationState.All;
 3592                _remoteEndPoint = null;
 93            }
 94            else
 95            {
 096                if ((_state & InitializationState.Address) != InitializationState.Address)
 97                {
 098                    _address = _remoteEndpointProvider.GetAddress();
 099                    _state |= InitializationState.Address;
 100                }
 101
 0102                if (getHostedPort)
 103                {
 0104                    _port = _remoteEndpointProvider.GetPort();
 0105                    _state |= InitializationState.Port;
 0106                    _remoteEndpointProvider = null;
 107                }
 108            }
 0109        }
 110
 111        internal interface IRemoteEndpointProvider
 112        {
 113            string GetAddress();
 114            int GetPort();
 115        }
 116
 117        [Flags]
 118        private enum InitializationState
 119        {
 120            None = 0,
 121            Address = 1,
 122            Port = 2,
 123            All = 3
 124        }
 125    }
 126}