< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.NetMsmqBinding
Assembly: CoreWCF.MSMQ
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.MSMQ/src/CoreWCF/Channels/NetMsmqBinding.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 51
Coverable lines: 51
Total lines: 143
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 18
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%110%
.ctor(...)100%110%
.ctor(...)100%110%
.ctor(...)100%110%
ShouldSerializeSecurity()0%10100%
Initialize()100%110%
CreateBindingElements()0%220%
CreateMessageSecurity()0%440%
GetTransport()100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.MSMQ/src/CoreWCF/Channels/NetMsmqBinding.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.ComponentModel;
 5using System.Xml;
 6using CoreWCF.Runtime;
 7
 8namespace CoreWCF.Channels
 9{
 10    public class NetMsmqBinding : MsmqBindingBase
 11    {
 12        // private BindingElements
 13        private BinaryMessageEncodingBindingElement _encoding;
 14        private NetMsmqSecurity _security;
 15
 016        public NetMsmqBinding()
 17        {
 018            Initialize();
 019            _security = new NetMsmqSecurity();
 020        }
 21
 022        public NetMsmqBinding(string configurationName)
 23        {
 024            Initialize();
 025            _security = new NetMsmqSecurity();
 026        }
 27
 028        public NetMsmqBinding(NetMsmqSecurityMode securityMode)
 29        {
 030            Initialize();
 031            _security = new NetMsmqSecurity(securityMode);
 032        }
 33
 034        private NetMsmqBinding(NetMsmqSecurity security)
 35        {
 036            Initialize();
 37            Fx.Assert(security != null, "Invalid (null) NetMsmqSecurity value");
 038            _security = security;
 039        }
 40
 41        public XmlDictionaryReaderQuotas ReaderQuotas
 42        {
 043            get { return _encoding.ReaderQuotas; }
 44            set
 45            {
 046                if (value == null)
 047                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value));
 048                value.CopyTo(_encoding.ReaderQuotas);
 049            }
 50        }
 51
 52        public NetMsmqSecurity Security
 53        {
 054            get { return _security; }
 055            set { _security = value; }
 56        }
 57
 58        public EnvelopeVersion EnvelopeVersion
 59        {
 060            get { return EnvelopeVersion.Soap12; }
 61        }
 62
 63        // [DefaultValue(TransportDefaults.MaxBufferPoolSize)]
 64        public long MaxBufferPoolSize
 65        {
 066            get { return _transport.MaxBufferPoolSize; }
 067            set { _transport.MaxBufferPoolSize = value; }
 68        }
 69
 70        [DefaultValue(MsmqDefaults.UseActiveDirectory)]
 71        public bool UseActiveDirectory
 72        {
 073            get { return (_transport as MsmqTransportBindingElement).UseActiveDirectory; }
 074            set { (_transport as MsmqTransportBindingElement).UseActiveDirectory = value; }
 75        }
 76
 77        [EditorBrowsable(EditorBrowsableState.Never)]
 78        public bool ShouldSerializeSecurity()
 79        {
 080            if (_security.Mode != NetMsmqSecurity.DefaultMode)
 81            {
 082                return true;
 83            }
 84
 085            if (_security.Transport.MsmqAuthenticationMode != MsmqDefaults.MsmqAuthenticationMode1 ||
 086                _security.Transport.MsmqEncryptionAlgorithm != MsmqDefaults.MsmqEncryptionAlgorithm1 ||
 087                _security.Transport.MsmqSecureHashAlgorithm != MsmqDefaults.MsmqSecureHashAlgorithm ||
 088                _security.Transport.MsmqProtectionLevel != MsmqDefaults.MsmqProtectionLevel)
 89            {
 090                return true;
 91            }
 92
 93            //if (this.security.Message.AlgorithmSuite != MsmqDefaults.MessageSecurityAlgorithmSuite ||
 94            //this.security.Message.ClientCredentialType != MsmqDefaults.DefaultClientCredentialType)
 95            //{
 96            //    return true;
 97            //}
 098            return false;
 99        }
 100
 101        private void Initialize()
 102        {
 0103            _transport = new MsmqTransportBindingElement();
 0104            _encoding = new BinaryMessageEncodingBindingElement();
 0105        }
 106
 107        public override BindingElementCollection CreateBindingElements()
 108        {
 109            // return collection of BindingElements
 0110            BindingElementCollection bindingElements = new BindingElementCollection();
 111            // order of BindingElements is important
 112            // add security
 0113            SecurityBindingElement wsSecurity = CreateMessageSecurity();
 0114            if (wsSecurity != null)
 115            {
 0116                bindingElements.Add(wsSecurity);
 117            }
 118
 119            // add encoding (text or mtom)
 0120            bindingElements.Add(_encoding);
 121            // add transport
 0122            bindingElements.Add(GetTransport());
 123
 0124            return bindingElements.Clone();
 125        }
 126
 127        private SecurityBindingElement CreateMessageSecurity()
 128        {
 0129            if (_security.Mode == NetMsmqSecurityMode.Message || _security.Mode == NetMsmqSecurityMode.Both)
 130            {
 0131                return _security.CreateMessageSecurity();
 132            }
 133
 0134            return null;
 135        }
 136
 137        private MsmqBindingElementBase GetTransport()
 138        {
 0139            _security.ConfigureTransportSecurity(_transport);
 0140            return _transport;
 141        }
 142    }
 143}