< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Description.MetadataExporter
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Description/MetadataExporter.cs
Line coverage
75%
Covered lines: 34
Uncovered lines: 11
Coverable lines: 45
Total lines: 134
Line coverage: 75.5%
Branch coverage
58%
Covered branches: 7
Total branches: 12
Branch coverage: 58.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%
ExportPolicy(...)50%4455.55%
ExportPolicy(...)100%11100%
.ctor(...)100%11100%
GetBindingAssertions()100%11100%
GetOperationBindingAssertions(...)100%22100%
GetMessageBindingAssertions(...)100%22100%
GetFaultBindingAssertions(...)0%220%
CreateExtensionException(...)100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Description/MetadataExporter.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 CoreWCF.Channels;
 8using CoreWCF.Runtime;
 9
 10namespace CoreWCF.Description
 11{
 12    //For export we provide a builder that allows the gradual construction of a set of MetadataDocuments
 13    public abstract class MetadataExporter
 14    {
 4715        private PolicyVersion _policyVersion = PolicyVersion.Policy12;
 16
 17        //prevent inheritance until we are ready to allow it.
 4718        internal MetadataExporter()
 19        {
 4720        }
 21
 22        public PolicyVersion PolicyVersion
 23        {
 51124            get => _policyVersion;
 2425            set => _policyVersion = value ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(val
 26        }
 27
 32228        public Collection<MetadataConversionError> Errors { get; } = new Collection<MetadataConversionError>();
 289229        public Dictionary<object, object> State { get; } = new Dictionary<object, object>();
 30
 31        public abstract void ExportContract(ContractDescription contract);
 32        public abstract void ExportEndpoint(ServiceEndpoint endpoint);
 33
 34        public abstract MetadataSet GetGeneratedMetadata();
 35
 36        internal PolicyConversionContext ExportPolicy(ServiceEndpoint endpoint, BindingParameterCollection bindingParame
 37        {
 4138            PolicyConversionContext policyContext = new ExportedPolicyConversionContext(endpoint, bindingParameters);
 39
 24640            foreach (IPolicyExportExtension exporter in policyContext.BindingElements.FindAll<IPolicyExportExtension>())
 41            {
 42                try
 43                {
 8244                    exporter.ExportPolicy(this, policyContext);
 8245                }
 046                catch (Exception e)
 47                {
 048                    if (Fx.IsFatal(e))
 49                    {
 050                        throw;
 51                    }
 52
 053                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateExtensionException(exporter, e));
 54                }
 55            }
 56
 4157            return policyContext;
 58        }
 59
 60        protected internal PolicyConversionContext ExportPolicy(ServiceEndpoint endpoint)
 61        {
 962            return ExportPolicy(endpoint, null);
 63        }
 64
 65        private sealed class ExportedPolicyConversionContext : PolicyConversionContext
 66        {
 67            private readonly PolicyAssertionCollection _bindingAssertions;
 68            private readonly Dictionary<OperationDescription, PolicyAssertionCollection> _operationBindingAssertions;
 69            private readonly Dictionary<MessageDescription, PolicyAssertionCollection> _messageBindingAssertions;
 70            private readonly Dictionary<FaultDescription, PolicyAssertionCollection> _faultBindingAssertions;
 71
 72            internal ExportedPolicyConversionContext(ServiceEndpoint endpoint, BindingParameterCollection bindingParamet
 4173                : base(endpoint)
 74            {
 4175                BindingElements = endpoint.Binding.CreateBindingElements();
 4176                _bindingAssertions = new PolicyAssertionCollection();
 4177                _operationBindingAssertions = new Dictionary<OperationDescription, PolicyAssertionCollection>();
 4178                _messageBindingAssertions = new Dictionary<MessageDescription, PolicyAssertionCollection>();
 4179                _faultBindingAssertions = new Dictionary<FaultDescription, PolicyAssertionCollection>();
 4180                BindingParameters = bindingParameters;
 4181            }
 82
 16783            public override BindingElementCollection BindingElements { get; }
 84
 4085            public override BindingParameterCollection BindingParameters { get; }
 86
 14587            public override PolicyAssertionCollection GetBindingAssertions() => _bindingAssertions;
 88
 89            public override PolicyAssertionCollection GetOperationBindingAssertions(OperationDescription operation)
 90            {
 15991                lock (_operationBindingAssertions)
 92                {
 15993                    if (!_operationBindingAssertions.ContainsKey(operation))
 94                    {
 15995                        _operationBindingAssertions.Add(operation, new PolicyAssertionCollection());
 96                    }
 15997                }
 98
 15999                return _operationBindingAssertions[operation];
 100            }
 101
 102            public override PolicyAssertionCollection GetMessageBindingAssertions(MessageDescription message)
 103            {
 318104                lock (_messageBindingAssertions)
 105                {
 318106                    if (!_messageBindingAssertions.ContainsKey(message))
 107                    {
 318108                        _messageBindingAssertions.Add(message, new PolicyAssertionCollection());
 109                    }
 318110                }
 318111                return _messageBindingAssertions[message];
 112            }
 113
 114            public override PolicyAssertionCollection GetFaultBindingAssertions(FaultDescription fault)
 115            {
 0116                lock (_faultBindingAssertions)
 117                {
 0118                    if (!_faultBindingAssertions.ContainsKey(fault))
 119                    {
 0120                        _faultBindingAssertions.Add(fault, new PolicyAssertionCollection());
 121                    }
 0122                }
 0123                return _faultBindingAssertions[fault];
 124            }
 125
 126        }
 127
 128        private Exception CreateExtensionException(IPolicyExportExtension exporter, Exception e)
 129        {
 0130            string errorMessage = SR.Format(SR.PolicyExtensionExportError, exporter.GetType(), e.Message);
 0131            return new InvalidOperationException(errorMessage, e);
 132        }
 133    }
 134}