< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Configuration.WebHttpBindingElement
Assembly: CoreWCF.ConfigurationManager
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.ConfigurationManager/src/CoreWCF/Configuration/WebHttpBindingElement.cs
Line coverage
56%
Covered lines: 34
Uncovered lines: 26
Coverable lines: 60
Total lines: 174
Line coverage: 56.6%
Branch coverage
16%
Covered branches: 1
Total branches: 6
Branch coverage: 16.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%110%
.ctor(...)100%11100%
.ctor()100%11100%
CreateBinding()100%11100%
GetContentTypeMapper(...)25%4442.85%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.ConfigurationManager/src/CoreWCF/Configuration/WebHttpBindingElement.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.ComponentModel;
 6using System.Configuration;
 7using System.Text;
 8using CoreWCF.Channels;
 9
 10namespace CoreWCF.Configuration
 11{
 12    public class WebHttpBindingElement : StandardBindingElement
 13    {
 014        private static readonly Type WebContentTypeMapperType = typeof(WebContentTypeMapper);
 15
 16        public WebHttpBindingElement(string name)
 317            : base(name)
 18        {
 319        }
 20
 21        public WebHttpBindingElement()
 322            : this(null)
 23        {
 324        }
 25
 26        [ConfigurationProperty(ConfigurationStrings.AllowCookies, DefaultValue = HttpTransportDefaults.AllowCookies)]
 27        public bool AllowCookies
 28        {
 029            get { return (bool)base[ConfigurationStrings.AllowCookies]; }
 030            set { base[ConfigurationStrings.AllowCookies] = value; }
 31
 32        }
 33
 34        [ConfigurationProperty(ConfigurationStrings.BypassProxyOnLocal, DefaultValue = HttpTransportDefaults.BypassProxy
 35        public bool BypassProxyOnLocal
 36        {
 037            get { return (bool)base[ConfigurationStrings.BypassProxyOnLocal]; }
 038            set { base[ConfigurationStrings.BypassProxyOnLocal] = value; }
 39        }
 40
 41        [ConfigurationProperty(ConfigurationStrings.HostNameComparisonMode, DefaultValue = HttpTransportDefaults.HostNam
 42        public HostNameComparisonMode HostNameComparisonMode
 43        {
 044            get { return (HostNameComparisonMode)base[ConfigurationStrings.HostNameComparisonMode]; }
 045            set { base[ConfigurationStrings.HostNameComparisonMode] = value; }
 46        }
 47
 48        [ConfigurationProperty(ConfigurationStrings.MaxBufferPoolSize, DefaultValue = TransportDefaults.MaxBufferPoolSiz
 49        [LongValidator(MinValue = 0)]
 50        public long MaxBufferPoolSize
 51        {
 252            get { return (long)base[ConfigurationStrings.MaxBufferPoolSize]; }
 053            set { base[ConfigurationStrings.MaxBufferPoolSize] = value; }
 54        }
 55
 56        [ConfigurationProperty(ConfigurationStrings.MaxBufferSize, DefaultValue = TransportDefaults.MaxBufferSize)]
 57        [IntegerValidator(MinValue = 1)]
 58        public int MaxBufferSize
 59        {
 360            get { return (int)base[ConfigurationStrings.MaxBufferSize]; }
 061            set { base[ConfigurationStrings.MaxBufferSize] = value; }
 62        }
 63
 64        [ConfigurationProperty(ConfigurationStrings.MaxReceivedMessageSize, DefaultValue = TransportDefaults.MaxReceived
 65        [LongValidator(MinValue = 1)]
 66        public long MaxReceivedMessageSize
 67        {
 368            get { return (long)base[ConfigurationStrings.MaxReceivedMessageSize]; }
 069            set { base[ConfigurationStrings.MaxReceivedMessageSize] = value; }
 70        }
 71
 72        [ConfigurationProperty(ConfigurationStrings.ProxyAddress, DefaultValue = HttpTransportDefaults.ProxyAddress)]
 73        public Uri ProxyAddress
 74        {
 075            get { return (Uri)base[ConfigurationStrings.ProxyAddress]; }
 076            set { base[ConfigurationStrings.ProxyAddress] = value; }
 77        }
 78
 79        [ConfigurationProperty(ConfigurationStrings.ReaderQuotas)]
 80        public XmlDictionaryReaderQuotasElement ReaderQuotas
 81        {
 382            get { return (XmlDictionaryReaderQuotasElement)base[ConfigurationStrings.ReaderQuotas]; }
 83        }
 84
 85        [ConfigurationProperty(ConfigurationStrings.Security)]
 86        public WebHttpSecurityElement Security
 87        {
 388            get { return (WebHttpSecurityElement)base[ConfigurationStrings.Security]; }
 89        }
 90
 91        [ConfigurationProperty(ConfigurationStrings.TransferMode, DefaultValue = HttpTransportDefaults.TransferMode)]
 92        public TransferMode TransferMode
 93        {
 294            get { return (TransferMode)base[ConfigurationStrings.TransferMode]; }
 095            set { base[ConfigurationStrings.TransferMode] = value; }
 96        }
 97
 98        [ConfigurationProperty(ConfigurationStrings.UseDefaultWebProxy, DefaultValue = HttpTransportDefaults.UseDefaultW
 99        public bool UseDefaultWebProxy
 100        {
 0101            get { return (bool)base[ConfigurationStrings.UseDefaultWebProxy]; }
 0102            set { base[ConfigurationStrings.UseDefaultWebProxy] = value; }
 103        }
 104
 105        [ConfigurationProperty(ConfigurationStrings.WriteEncoding, DefaultValue = TextEncoderDefaults.EncodingString)]
 106        [TypeConverter(typeof(EncodingConverter))]
 107        public Encoding WriteEncoding
 108        {
 2109            get { return (Encoding)base[ConfigurationStrings.WriteEncoding]; }
 0110            set { base[ConfigurationStrings.WriteEncoding] = value; }
 111        }
 112
 113        [ConfigurationProperty(ConfigurationStrings.ContentTypeMapper, DefaultValue = "")]
 114        [StringValidator(MinLength = 0)]
 115        public string ContentTypeMapper
 116        {
 2117            get { return (string)base[ConfigurationStrings.ContentTypeMapper]; }
 118            set
 119            {
 0120                if (String.IsNullOrEmpty(value))
 121                {
 0122                    value = String.Empty;
 123                }
 0124                base[ConfigurationStrings.ContentTypeMapper] = value;
 0125            }
 126        }
 127
 128        [ConfigurationProperty(ConfigurationStrings.CrossDomainScriptAccessEnabled, DefaultValue = false)]
 129        public bool CrossDomainScriptAccessEnabled
 130        {
 0131            get { return (bool)base[ConfigurationStrings.CrossDomainScriptAccessEnabled]; }
 0132            set { base[ConfigurationStrings.CrossDomainScriptAccessEnabled] = value; }
 133        }
 134
 135        public override Binding CreateBinding()
 136        {
 2137            var binding = new WebHttpBinding(WebHttpSecurityMode.None)
 2138            {
 2139                Name = Name,
 2140                MaxBufferPoolSize = MaxBufferPoolSize,
 2141                MaxBufferSize = MaxBufferSize,
 2142                MaxReceivedMessageSize = MaxReceivedMessageSize,
 2143                TransferMode = TransferMode,
 2144                // commented due to null reference exception
 2145                //CrossDomainScriptAccessEnabled = CrossDomainScriptAccessEnabled,
 2146                ContentTypeMapper = GetContentTypeMapper(this.ContentTypeMapper),
 2147                ReaderQuotas = ReaderQuotas.Clone(),
 2148                ReceiveTimeout = ReceiveTimeout,
 2149                OpenTimeout = OpenTimeout,
 2150                CloseTimeout = CloseTimeout,
 2151                SendTimeout = SendTimeout,
 2152                WriteEncoding = WriteEncoding,
 2153            };
 154
 2155            Security.ApplyConfiguration(binding.Security);
 2156            return binding;
 157        }
 158
 159        internal static WebContentTypeMapper GetContentTypeMapper(string contentTypeMapperType)
 160        {
 2161            WebContentTypeMapper contentTypeMapper = null;
 2162            if (!string.IsNullOrEmpty(contentTypeMapperType))
 163            {
 0164                Type type = System.Type.GetType(contentTypeMapperType, true);
 0165                if (!WebContentTypeMapperType.IsAssignableFrom(type))
 166                {
 0167                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.Config
 168                }
 0169                contentTypeMapper = (WebContentTypeMapper)Activator.CreateInstance(type);
 170            }
 2171            return contentTypeMapper;
 172        }
 173    }
 174}