< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Description.SoapHelper
Assembly: CoreWCF.NetNamedPipe
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetNamedPipe/src/CoreWCF/Description/SoapHelper.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 36
Coverable lines: 36
Total lines: 104
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 28
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%110%
GetOrCreateSoapBinding(...)0%440%
GetSoapBinding(...)0%440%
CreateSoapBinding(...)0%440%
GetSoapVersionState(...)0%660%
GetSoapAddressBinding(...)0%440%
GetSoapVersion(...)0%660%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.NetNamedPipe/src/CoreWCF/Description/SoapHelper.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.Collections.Generic;
 5using CoreWCF.Runtime;
 6using WsdlNS = System.Web.Services.Description;
 7
 8namespace CoreWCF.Description
 9{
 10    internal static class SoapHelper
 11    {
 012        private static readonly object s_soapVersionStateKey = typeof(Dictionary<WsdlNS.Binding, EnvelopeVersion>);
 13
 14        internal static WsdlNS.SoapBinding GetOrCreateSoapBinding(WsdlEndpointConversionContext endpointContext, WsdlExp
 15        {
 016            if (GetSoapVersionState(endpointContext.WsdlBinding, exporter) == EnvelopeVersion.None)
 17            {
 018                return null;
 19            }
 20
 021            WsdlNS.SoapBinding existingSoapBinding = GetSoapBinding(endpointContext);
 022            if (existingSoapBinding != null)
 23            {
 024                return existingSoapBinding;
 25            }
 26
 027            EnvelopeVersion version = GetSoapVersion(endpointContext.WsdlBinding);
 028            WsdlNS.SoapBinding soapBinding = CreateSoapBinding(version, endpointContext.WsdlBinding);
 029            return soapBinding;
 30        }
 31
 32        private static WsdlNS.SoapBinding GetSoapBinding(WsdlEndpointConversionContext endpointContext)
 33        {
 034            foreach (object o in endpointContext.WsdlBinding.Extensions)
 35            {
 036                if (o is WsdlNS.SoapBinding binding)
 37                {
 038                    return binding;
 39                }
 40            }
 41
 042            return null;
 043        }
 44
 45        private static WsdlNS.SoapBinding CreateSoapBinding(EnvelopeVersion version, WsdlNS.Binding wsdlBinding)
 46        {
 047            WsdlNS.SoapBinding soapBinding = null;
 48
 049            if (version == EnvelopeVersion.Soap12)
 50            {
 051                soapBinding = new WsdlNS.Soap12Binding();
 52            }
 053            else if (version == EnvelopeVersion.Soap11)
 54            {
 055                soapBinding = new WsdlNS.SoapBinding();
 56            }
 57
 58            Fx.Assert(soapBinding != null, "EnvelopeVersion is not recognized. Please update the SoapHelper class");
 59
 060            wsdlBinding.Extensions.Add(soapBinding);
 061            return soapBinding;
 62        }
 63
 64        private static EnvelopeVersion GetSoapVersionState(WsdlNS.Binding wsdlBinding, WsdlExporter exporter)
 65        {
 066            object versions = null;
 67
 068            if (exporter.State.TryGetValue(s_soapVersionStateKey, out versions))
 69            {
 070                if (versions != null && ((Dictionary<WsdlNS.Binding, EnvelopeVersion>)versions).ContainsKey(wsdlBinding)
 71                {
 072                    return ((Dictionary<WsdlNS.Binding, EnvelopeVersion>)versions)[wsdlBinding];
 73                }
 74            }
 075            return null;
 76        }
 77
 78        private static WsdlNS.SoapAddressBinding GetSoapAddressBinding(WsdlNS.Port wsdlPort)
 79        {
 080            foreach (object o in wsdlPort.Extensions)
 81            {
 082                if (o is WsdlNS.SoapAddressBinding binding)
 83                {
 084                    return binding;
 85                }
 86            }
 087            return null;
 088        }
 89
 90        internal static EnvelopeVersion GetSoapVersion(WsdlNS.Binding wsdlBinding)
 91        {
 092            foreach (object o in wsdlBinding.Extensions)
 93            {
 094                if (o is WsdlNS.SoapBinding)
 95                {
 096                    return o is WsdlNS.Soap12Binding ? EnvelopeVersion.Soap12 : EnvelopeVersion.Soap11;
 97                }
 98            }
 99
 0100            return EnvelopeVersion.Soap12;
 0101        }
 102
 103    }
 104}