< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.TransportOutputChannel
Assembly: CoreWCF.Http
File(s): /home/runner/work/CoreWCF/CoreWCF/src/Common/src/DuplexChannels/CoreWCF/Channels/TransportOutputChannel.cs
Line coverage
48%
Covered lines: 24
Uncovered lines: 25
Coverable lines: 49
Total lines: 147
Line coverage: 48.9%
Branch coverage
41%
Covered branches: 10
Total branches: 24
Branch coverage: 41.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)70%101081.25%
AddHeadersTo(...)75%4483.33%
.ctor(...)100%11100%
TryLookup(...)0%440%
TryLookup(...)0%220%
TryLookup(...)0%440%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/Common/src/DuplexChannels/CoreWCF/Channels/TransportOutputChannel.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.Xml;
 6
 7namespace CoreWCF.Channels
 8{
 9    internal abstract class TransportOutputChannel : OutputChannel
 10    {
 11        private readonly bool _anyHeadersToAdd;
 12        private readonly EndpointAddress _to;
 13        private readonly Uri _via;
 14        private readonly ToHeader _toHeader;
 15
 16        protected TransportOutputChannel(IDefaultCommunicationTimeouts timeouts, EndpointAddress to, Uri via, bool manua
 1117            : base(timeouts)
 18        {
 1119            ManualAddressing = manualAddressing;
 1120            MessageVersion = messageVersion;
 1121            _to = to;
 1122            _via = via;
 23
 1124            if (!manualAddressing && _to != null)
 25            {
 26                Uri toUri;
 1127                if (_to.IsAnonymous)
 28                {
 1129                    toUri = MessageVersion.Addressing.AnonymousUri;
 30                }
 031                else if (_to.IsNone)
 32                {
 033                    toUri = MessageVersion.Addressing.NoneUri;
 34                }
 35                else
 36                {
 037                    toUri = _to.Uri;
 38                }
 39
 1140                if (toUri != null)
 41                {
 1142                    XmlDictionaryString dictionaryTo = new ToDictionary(toUri.AbsoluteUri).To;
 1143                    _toHeader = ToHeader.Create(toUri, dictionaryTo, messageVersion.Addressing);
 44                }
 45
 1146                _anyHeadersToAdd = _to.Headers.Count > 0;
 47            }
 1148        }
 49
 050        protected bool ManualAddressing { get; }
 51
 1152        public MessageVersion MessageVersion { get; }
 53
 54        public override EndpointAddress RemoteAddress
 55        {
 56            get
 57            {
 1558                return _to;
 59            }
 60        }
 61
 62        public override Uri Via
 63        {
 64            get
 65            {
 066                return _via;
 67            }
 68        }
 69
 70        protected override void AddHeadersTo(Message message)
 71        {
 1572            base.AddHeadersTo(message);
 73
 1574            if (_toHeader != null)
 75            {
 76                // TODO: Removed performance enhancement to avoid exposing another internal method.
 77                // Evaluate whether we should do something to bring this back. My thoughts are we
 78                // remove the SetToHeader method as we should be using the same mechanism as third
 79                // parties transports have to use.
 1580                message.Headers.To = _toHeader.To;
 81
 82                // Original comment and code:
 83                // we don't use to.ApplyTo(message) since it's faster to cache and
 84                // use the actual <To> header then to call message.Headers.To = Uri...
 85                //message.Headers.SetToHeader(toHeader);
 86
 1587                if (_anyHeadersToAdd)
 88                {
 089                    _to.Headers.AddHeadersTo(message);
 90                }
 91            }
 1592        }
 93
 94        private class ToDictionary : IXmlDictionary
 95        {
 1196            public ToDictionary(string to)
 97            {
 1198                To = new XmlDictionaryString(this, to, 0);
 1199            }
 100
 22101            public XmlDictionaryString To { get; private set; }
 102
 103            public bool TryLookup(string value, out XmlDictionaryString result)
 104            {
 0105                if (value == null)
 106                {
 0107                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value));
 108                }
 109
 0110                if (value == To.Value)
 111                {
 0112                    result = To;
 0113                    return true;
 114                }
 0115                result = null;
 0116                return false;
 117            }
 118
 119            public bool TryLookup(int key, out XmlDictionaryString result)
 120            {
 0121                if (key == 0)
 122                {
 0123                    result = To;
 0124                    return true;
 125                }
 0126                result = null;
 0127                return false;
 128            }
 129
 130            public bool TryLookup(XmlDictionaryString value, out XmlDictionaryString result)
 131            {
 0132                if (value == null)
 133                {
 0134                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value));
 135                }
 136
 0137                if (value == To)
 138                {
 0139                    result = To;
 0140                    return true;
 141                }
 0142                result = null;
 0143                return false;
 144            }
 145        }
 146    }
 147}