< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Configuration.ExtensionsSection
Assembly: CoreWCF.ConfigurationManager
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.ConfigurationManager/src/CoreWCF/Configuration/ExtensionsSection.cs
Line coverage
73%
Covered lines: 33
Uncovered lines: 12
Coverable lines: 45
Total lines: 124
Line coverage: 73.3%
Branch coverage
12%
Covered branches: 1
Total branches: 8
Branch coverage: 12.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%11100%
InitializeBindingElementExtensions()100%11100%
InitializeBindingExtensions()100%11100%
.ctor()100%11100%
InitializeDefault()100%11100%
LookupAssociatedCollection(...)100%110%
GetExtensionType(...)0%440%
LookupCollection(...)25%4462.5%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.ConfigurationManager/src/CoreWCF/Configuration/ExtensionsSection.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.Configuration;
 6using System.Globalization;
 7using System.Threading;
 8using CoreWCF.Runtime;
 9
 10namespace CoreWCF.Configuration
 11{
 12    internal sealed class ExtensionsSection : ConfigurationSection
 13    {
 114        private static readonly Lazy<ExtensionsSection> s_extensionsSection = new Lazy<ExtensionsSection>(LazyThreadSafe
 15
 1716        private static ExtensionsSection ExtensionSection => s_extensionsSection.Value;
 17
 18        [ConfigurationProperty(ConfigurationStrings.BindingElementExtensions)]
 19        public ExtensionElementCollection BindingElementExtensions
 20        {
 2621            get { return (ExtensionElementCollection)base[ConfigurationStrings.BindingElementExtensions]; }
 22        }
 23
 24        [ConfigurationProperty(ConfigurationStrings.BindingExtensions)]
 25        public ExtensionElementCollection BindingExtensions
 26        {
 727            get { return (ExtensionElementCollection)base[ConfigurationStrings.BindingExtensions]; }
 28        }
 29
 30        private void InitializeBindingElementExtensions()
 31        {
 132            BindingElementExtensions.Add(new ExtensionElement(ConfigurationStrings.BinaryMessageEncodingSectionName, typ
 133            BindingElementExtensions.Add(new ExtensionElement(ConfigurationStrings.HttpsTransportSectionName, typeof(Htt
 134            BindingElementExtensions.Add(new ExtensionElement(ConfigurationStrings.HttpTransportSectionName, typeof(Http
 135            BindingElementExtensions.Add(new ExtensionElement(ConfigurationStrings.MtomMessageEncodingSectionName, typeo
 136            BindingElementExtensions.Add(new ExtensionElement(ConfigurationStrings.SecuritySectionName, typeof(SecurityE
 137            BindingElementExtensions.Add(new ExtensionElement(ConfigurationStrings.SslStreamSecuritySectionName, typeof(
 138            BindingElementExtensions.Add(new ExtensionElement(ConfigurationStrings.TcpTransportSectionName, typeof(TcpTr
 139            BindingElementExtensions.Add(new ExtensionElement(ConfigurationStrings.TextMessageEncodingSectionName, typeo
 140            BindingElementExtensions.Add(new ExtensionElement(ConfigurationStrings.WindowsStreamSecuritySectionName, typ
 141        }
 42
 43        private void InitializeBindingExtensions()
 44        {
 145            BindingExtensions.Add(new ExtensionElement(ConfigurationStrings.BasicHttpBindingCollectionElementName, typeo
 146            BindingExtensions.Add(new ExtensionElement(ConfigurationStrings.CustomBindingCollectionElementName, typeof(C
 147            BindingExtensions.Add(new ExtensionElement(ConfigurationStrings.NetTcpBindingCollectionElementName, typeof(N
 148            BindingExtensions.Add(new ExtensionElement(ConfigurationStrings.WSHttpBindingCollectionElementName, typeof(W
 149            BindingExtensions.Add(new ExtensionElement(ConfigurationStrings.UdpBindingCollectionElementName, Configurati
 150            BindingExtensions.Add(new ExtensionElement(ConfigurationStrings.NetHttpBindingCollectionElementName, typeof(
 151            BindingExtensions.Add(new ExtensionElement(ConfigurationStrings.WebHttpBindingCollectionElementName, typeof(
 152        }
 53
 154        public ExtensionsSection()
 55        {
 156            InitializeDefault();
 157        }
 58
 59        protected override void InitializeDefault()
 60        {
 161            InitializeBindingElementExtensions();
 162            InitializeBindingExtensions();
 163        }
 64
 65
 66        internal static ExtensionElementCollection LookupAssociatedCollection(Type extensionType, ContextInformation eva
 67        {
 068            collectionName = GetExtensionType(extensionType);
 069            return ExtensionsSection.LookupCollection(collectionName, evaluationContext);
 70        }
 71
 72        private static string GetExtensionType(Type extensionType)
 73        {
 074            string collectionName = string.Empty;
 75
 076            if (extensionType.IsSubclassOf(typeof(BindingElementExtensionElement)))
 77            {
 078                collectionName = ConfigurationStrings.BindingElementExtensions;
 79            }
 080            else if (extensionType.IsSubclassOf(typeof(BindingCollectionElement)))
 81            {
 082                collectionName = ConfigurationStrings.BindingExtensions;
 83            }
 84            else
 85            {
 86                // LookupAssociatedCollection built on assumption that extensionType is valid.
 87                // This should be protected at the callers site.  If assumption is invalid, then
 88                // configuration system is in an indeterminate state.  Need to stop in a manner that
 89                // user code can not capture.
 90                Fx.Assert(string.Format(CultureInfo.InvariantCulture, "{0} is not a type supported by the ServiceModelEx
 091                DiagnosticUtility.FailFast(string.Format(CultureInfo.InvariantCulture, "{0} is not a type supported by t
 92            }
 93
 094            return collectionName;
 95        }
 96
 97
 98        internal static ExtensionElementCollection LookupCollection(string collectionName, ContextInformation evaluation
 99        {
 17100            ExtensionElementCollection collection = null;
 17101            ExtensionsSection extensionsSection = ExtensionSection;
 102
 103            switch (collectionName)
 104            {
 105                case (ConfigurationStrings.BindingElementExtensions):
 17106                    collection = extensionsSection.BindingElementExtensions;
 17107                    break;
 108                case (ConfigurationStrings.BindingExtensions):
 0109                    collection = extensionsSection.BindingExtensions;
 0110                    break;
 111                default:
 112                    // LookupCollection built on assumption that collectionName is valid.
 113                    // This should be protected at the callers site.  If assumption is invalid, then
 114                    // configuration system is in an indeterminate state.  Need to stop in a manner that
 115                    // user code can not capture.
 116                    Fx.Assert(string.Format(CultureInfo.InvariantCulture, "{0} is not a valid ServiceModelExtensionsSect
 0117                    DiagnosticUtility.FailFast(string.Format(CultureInfo.InvariantCulture, "{0} is not a valid ServiceMo
 118                    break;
 119            }
 120
 17121            return collection;
 122        }
 123    }
 124}