< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.WebHttpBinding
Assembly: CoreWCF.WebHttp
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/WebHttpBinding.cs
Line coverage
87%
Covered lines: 64
Uncovered lines: 9
Coverable lines: 73
Total lines: 199
Line coverage: 87.6%
Branch coverage
75%
Covered branches: 6
Total branches: 8
Branch coverage: 75%
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%
CreateBindingElements()100%11100%
GetTransport()100%44100%
Initialize()100%11100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/WebHttpBinding.cs

#LineLine coverage
 1using System.ComponentModel;
 2using System.Text;
 3using System.Xml;
 4using CoreWCF.Channels;
 5
 6namespace CoreWCF
 7{
 8    public class WebHttpBinding : Binding
 9    {
 10        private HttpsTransportBindingElement _httpsTransportBindingElement;
 11        // private BindingElements
 12        private HttpTransportBindingElement _httpTransportBindingElement;
 3913        private WebHttpSecurity _security = new WebHttpSecurity();
 14        private WebMessageEncodingBindingElement _webMessageEncodingBindingElement;
 15
 3616        public WebHttpBinding() : base()
 17        {
 3618            Initialize();
 3619        }
 20
 321        public WebHttpBinding(WebHttpSecurityMode securityMode) : base()
 22        {
 323            Initialize();
 324            _security.Mode = securityMode;
 325        }
 26
 27        // This needs an update in the HttpTransportBindingElement to work.
 28        //[DefaultValue(false)]
 29        //public bool AllowCookies
 30        //{
 31        //    get { throw new PlatformNotSupportedException(); }
 32        //    set { throw new PlatformNotSupportedException(); }
 33        //}
 34
 035        public EnvelopeVersion EnvelopeVersion => EnvelopeVersion.None;
 36
 37        // This needs an update in the HttpTransportBindingElement to work.
 38        //[DefaultValue(HostNameComparisonMode.StrongWildcard)]
 39        //public HostNameComparisonMode HostNameComparisonMode
 40        //{
 41        //    get { throw new PlatformNotSupportedException(); }
 42        //    set { throw new PlatformNotSupportedException(); }
 43        //}
 44
 45        [DefaultValue(TransportDefaults.MaxBufferPoolSize)]
 46        public long MaxBufferPoolSize
 47        {
 048            get { return _httpTransportBindingElement.MaxBufferPoolSize; }
 49            set
 50            {
 251                _httpTransportBindingElement.MaxBufferPoolSize = value;
 252                _httpsTransportBindingElement.MaxBufferPoolSize = value;
 253            }
 54        }
 55
 56        [DefaultValue(TransportDefaults.MaxBufferSize)]
 57        public int MaxBufferSize
 58        {
 259            get { return _httpTransportBindingElement.MaxBufferSize; }
 60            set
 61            {
 262                _httpTransportBindingElement.MaxBufferSize = value;
 263                _httpsTransportBindingElement.MaxBufferSize = value;
 264            }
 65        }
 66
 67        [DefaultValue(TransportDefaults.MaxReceivedMessageSize)]
 68        public long MaxReceivedMessageSize
 69        {
 270            get { return _httpTransportBindingElement.MaxReceivedMessageSize; }
 71            set
 72            {
 273                _httpTransportBindingElement.MaxReceivedMessageSize = value;
 274                _httpsTransportBindingElement.MaxReceivedMessageSize = value;
 275            }
 76        }
 77
 78        public XmlDictionaryReaderQuotas ReaderQuotas
 79        {
 180            get { return _webMessageEncodingBindingElement.ReaderQuotas; }
 81            set
 82            {
 283                if (value == null)
 84                {
 085                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value));
 86                }
 87
 288                value.CopyTo(_webMessageEncodingBindingElement.ReaderQuotas);
 289            }
 90        }
 91
 15092        public override string Scheme => GetTransport().Scheme;
 93
 94        public WebHttpSecurity Security
 95        {
 496            get { return _security; }
 97            set
 98            {
 699                if (value == null)
 0100                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value));
 101
 6102                _security = value;
 6103            }
 104        }
 105
 106        [DefaultValue(HttpTransportDefaults.TransferMode)]
 107        public TransferMode TransferMode
 108        {
 2109            get { return _httpTransportBindingElement.TransferMode; }
 110            set
 111            {
 2112                _httpTransportBindingElement.TransferMode = value;
 2113                _httpsTransportBindingElement.TransferMode = value;
 2114            }
 115        }
 116
 117        [TypeConverter(typeof(EncodingConverter))]
 118        public Encoding WriteEncoding
 119        {
 0120            get { return _webMessageEncodingBindingElement.WriteEncoding; }
 121            set
 122            {
 2123                _webMessageEncodingBindingElement.WriteEncoding = value;
 2124            }
 125        }
 126
 127        public WebContentTypeMapper ContentTypeMapper
 128        {
 0129            get { return _webMessageEncodingBindingElement.ContentTypeMapper; }
 130            set
 131            {
 2132                _webMessageEncodingBindingElement.ContentTypeMapper = value;
 2133            }
 134        }
 135
 136        public bool CrossDomainScriptAccessEnabled
 137        {
 0138            get { return _webMessageEncodingBindingElement.CrossDomainScriptAccessEnabled; }
 139            set
 140            {
 0141                _webMessageEncodingBindingElement.CrossDomainScriptAccessEnabled = value;
 0142            }
 143        }
 144
 145        public override BindingElementCollection CreateBindingElements()
 146        {
 147            // return collection of BindingElements
 627148            BindingElementCollection bindingElements = new BindingElementCollection();
 149            // order of BindingElements is important
 150            // add encoding
 627151            bindingElements.Add(_webMessageEncodingBindingElement);
 152            // add transport (http or https)
 627153            bindingElements.Add(GetTransport());
 154
 627155            return bindingElements.Clone();
 156        }
 157
 158        private TransportBindingElement GetTransport()
 159        {
 777160            if (_security.Mode == WebHttpSecurityMode.Transport)
 161            {
 22162                _security.EnableTransportSecurity(_httpsTransportBindingElement);
 22163                _security.ApplyAuthorizationPolicySupport(_httpsTransportBindingElement);
 22164                return _httpsTransportBindingElement;
 165            }
 755166            else if (_security.Mode == WebHttpSecurityMode.TransportCredentialOnly)
 167            {
 124168                _security.EnableTransportAuthentication(_httpTransportBindingElement);
 124169                _security.ApplyAuthorizationPolicySupport(_httpTransportBindingElement);
 124170                return _httpTransportBindingElement;
 171            }
 172            else
 173            {
 174                // ensure that there is no transport security
 631175                _security.DisableTransportAuthentication(_httpTransportBindingElement);
 631176                _security.ApplyAuthorizationPolicySupport(_httpTransportBindingElement);
 631177                return _httpTransportBindingElement;
 178            }
 179        }
 180
 181        private void Initialize()
 182        {
 39183            _httpTransportBindingElement = new HttpTransportBindingElement
 39184            {
 39185                ManualAddressing = true
 39186            };
 187
 39188            _httpsTransportBindingElement = new HttpsTransportBindingElement
 39189            {
 39190                ManualAddressing = true
 39191            };
 192
 39193            _webMessageEncodingBindingElement = new WebMessageEncodingBindingElement
 39194            {
 39195                MessageVersion = MessageVersion.None
 39196            };
 39197        }
 198    }
 199}