< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Description.MetadataSection
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Description/MetadataSection.cs
Line coverage
55%
Covered lines: 24
Uncovered lines: 19
Coverable lines: 43
Total lines: 118
Line coverage: 55.8%
Branch coverage
16%
Covered branches: 2
Total branches: 12
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
.ctor(...)100%11100%
.ctor()100%11100%
CreateFromPolicy(...)0%440%
CreateFromSchema(...)50%2285.71%
CreateFromServiceDescription(...)50%2285.71%
IsPolicyElement(...)0%440%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Description/MetadataSection.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.Collections.Generic;
 6using System.Collections.ObjectModel;
 7using System.Text;
 8using System.Xml;
 9using WsdlNS = System.Web.Services.Description;
 10using XsdNS = System.Xml.Schema;
 11using System.Reflection;
 12using System.Xml.Serialization;
 13
 14namespace CoreWCF.Description
 15{
 16    [XmlRoot(ElementName = MetadataStrings.MetadataExchangeStrings.MetadataSection, Namespace = MetadataStrings.Metadata
 17    public class MetadataSection
 18    {
 9519        private readonly Collection<XmlAttribute> _attributes = new Collection<XmlAttribute>();
 20
 19021        public MetadataSection() : this(null, null, null) { }
 22
 9523        public MetadataSection(string dialect, string identifier, object metadata)
 24        {
 9525            Dialect = dialect;
 9526            Identifier = identifier;
 9527            Metadata = metadata;
 9528        }
 29
 2430        public static string ServiceDescriptionDialect { get { return WsdlNS.ServiceDescription.Namespace; } }
 7131        public static string XmlSchemaDialect { get { return XsdNS.XmlSchema.Namespace; } }
 032        public static string PolicyDialect { get { return MetadataStrings.WSPolicy.NamespaceUri; } }
 033        public static string MetadataExchangeDialect { get { return MetadataStrings.MetadataExchangeStrings.Namespace; }
 34
 35        [XmlAnyAttribute]
 036        public Collection<XmlAttribute> Attributes => _attributes;
 37
 38        [XmlAttribute]
 19039        public string Dialect { get; set; }
 40
 41        [XmlAttribute]
 19042        public string Identifier { get; set; }
 43
 44        [XmlAnyElement]
 45        [XmlElement(MetadataStrings.XmlSchema.Schema, typeof(XsdNS.XmlSchema), Namespace = XsdNS.XmlSchema.Namespace)]
 46        //typeof(WsdlNS.ServiceDescription) produces an XmlSerializer which can't export / import the Extensions in the 
 47        //We use change this to typeof(string) and then fix the generated serializer to use the Read/Write
 48        //methods provided by WsdlNS.ServiceDesciption which use a pregenerated serializer which can export / import the
 49        [XmlElement(MetadataStrings.ServiceDescription.Definitions, typeof(WsdlNS.ServiceDescription), Namespace = WsdlN
 50        [XmlElement(MetadataStrings.MetadataExchangeStrings.MetadataReference, typeof(MetadataReference), Namespace = Me
 51        [XmlElement(MetadataStrings.MetadataExchangeStrings.Location, typeof(MetadataLocation), Namespace = MetadataStri
 52        [XmlElement(MetadataStrings.MetadataExchangeStrings.Metadata, typeof(MetadataSet), Namespace = MetadataStrings.M
 61353        public object Metadata { get; set; }
 54
 055        internal string SourceUrl { get; set; }
 56
 57        public static MetadataSection CreateFromPolicy(XmlElement policy, string identifier)
 58        {
 059            if (policy == null)
 60            {
 061                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(policy));
 62            }
 63
 064            if (!IsPolicyElement(policy))
 65            {
 066                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(policy),
 067                    SR.Format(SR.SFxBadMetadataMustBePolicy, MetadataStrings.WSPolicy.NamespaceUri, MetadataStrings.WSPo
 68            }
 69
 070            MetadataSection section = new MetadataSection();
 71
 072            section.Dialect = policy.NamespaceURI;
 073            section.Identifier = identifier;
 074            section.Metadata = policy;
 75
 076            return section;
 77        }
 78
 79        public static MetadataSection CreateFromSchema(XsdNS.XmlSchema schema)
 80        {
 7181            if (schema == null)
 82            {
 083                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(schema));
 84            }
 85
 7186            MetadataSection section = new MetadataSection();
 87
 7188            section.Dialect = XmlSchemaDialect;
 7189            section.Identifier = schema.TargetNamespace;
 7190            section.Metadata = schema;
 91
 7192            return section;
 93        }
 94
 95        public static MetadataSection CreateFromServiceDescription(WsdlNS.ServiceDescription serviceDescription)
 96        {
 2497            if (serviceDescription == null)
 98            {
 099                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(serviceDescription));
 100            }
 101
 24102            MetadataSection section = new MetadataSection();
 103
 24104            section.Dialect = ServiceDescriptionDialect;
 24105            section.Identifier = serviceDescription.TargetNamespace;
 24106            section.Metadata = serviceDescription;
 107
 24108            return section;
 109        }
 110
 111        internal static bool IsPolicyElement(XmlElement policy)
 112        {
 0113            return (policy.NamespaceURI == MetadataStrings.WSPolicy.NamespaceUri
 0114                || policy.NamespaceURI == MetadataStrings.WSPolicy.NamespaceUri15)
 0115                && policy.LocalName == MetadataStrings.WSPolicy.Elements.Policy;
 116        }
 117    }
 118}