< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.NetHttpBinding
Assembly: CoreWCF.Http
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Http/src/CoreWCF/NetHttpBinding.cs
Line coverage
94%
Covered lines: 32
Uncovered lines: 2
Coverable lines: 34
Total lines: 93
Line coverage: 94.1%
Branch coverage
66%
Covered branches: 4
Total branches: 6
Branch coverage: 66.6%
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%
SetReaderQuotas(...)100%11100%
CreateBindingElements()100%44100%
CheckSettings()100%11100%
Initialize()100%11100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Http/src/CoreWCF/NetHttpBinding.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;
 6using CoreWCF.Channels;
 7using CoreWCF.Runtime;
 8
 9namespace CoreWCF
 10{
 11    public class NetHttpBinding : HttpBindingBase
 12    {
 13        private BinaryMessageEncodingBindingElement _binaryMessageEncodingBindingElement;
 14        private BasicHttpSecurity _basicHttpSecurity;
 15
 16        public NetHttpBinding()
 1017            : this(BasicHttpSecurityMode.None)
 18        {
 1019        }
 20
 21        public NetHttpBinding(BasicHttpSecurityMode securityMode)
 2522            : base()
 23        {
 2524            Initialize();
 2525            _basicHttpSecurity.Mode = securityMode;
 2526        }
 27
 32628        public NetHttpMessageEncoding MessageEncoding { get; set; }
 29
 30        public BasicHttpSecurity Security
 31        {
 432            get => _basicHttpSecurity;
 33
 34            set
 35            {
 036                _basicHttpSecurity = value ?? throw Fx.Exception.ArgumentNull(nameof(value));
 037            }
 38        }
 39
 6240        public WebSocketTransportSettings WebSocketSettings => InternalWebSocketSettings;
 41
 33842        internal override BasicHttpSecurity BasicHttpSecurity => _basicHttpSecurity;
 43
 44        internal override void SetReaderQuotas(XmlDictionaryReaderQuotas readerQuotas)
 45        {
 246            readerQuotas.CopyTo(_binaryMessageEncodingBindingElement.ReaderQuotas);
 247        }
 48
 49        public override BindingElementCollection CreateBindingElements()
 50        {
 27951            CheckSettings();
 52
 53            // return collection of BindingElements
 27954            BindingElementCollection bindingElements = new BindingElementCollection();
 55
 56            // order of BindingElements is important
 57            // add encoding
 27958            switch (MessageEncoding)
 59            {
 60                case NetHttpMessageEncoding.Text:
 8061                    bindingElements.Add(TextMessageEncodingBindingElement);
 8062                    break;
 63                case NetHttpMessageEncoding.Mtom:
 7864                    bindingElements.Add(MtomMessageEncodingBindingElement);
 7865                    break;
 66                default:
 12167                    bindingElements.Add(_binaryMessageEncodingBindingElement);
 68                    break;
 69            }
 70
 71            // add transport (http or https)
 27972            bindingElements.Add(GetTransport());
 73
 27974            return bindingElements.Clone();
 75        }
 76
 77        internal override void CheckSettings()
 78        {
 27979            base.CheckSettings();
 27980        }
 81
 82        private void Initialize()
 83        {
 2584            MessageEncoding = NetHttpBindingDefaults.MessageEncoding;
 2585            _binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement() { MessageVersion = MessageV
 2586            TextMessageEncodingBindingElement.MessageVersion = MessageVersion.Soap12WSAddressing10;
 2587            MtomMessageEncodingBindingElement.MessageVersion = MessageVersion.Soap12WSAddressing10;
 2588            WebSocketSettings.TransportUsage = NetHttpBindingDefaults.TransportUsage;
 2589            WebSocketSettings.SubProtocol = WebSocketTransportSettings.SoapSubProtocol;
 2590            _basicHttpSecurity = new BasicHttpSecurity();
 2591        }
 92    }
 93}