< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Configuration.ConfigurationHolder
Assembly: CoreWCF.ConfigurationManager
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.ConfigurationManager/src/CoreWCF/Configuration/ConfigurationHolder.cs
Line coverage
94%
Covered lines: 36
Uncovered lines: 2
Coverable lines: 38
Total lines: 90
Line coverage: 94.7%
Branch coverage
83%
Covered branches: 10
Total branches: 12
Branch coverage: 83.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%
AddBinding(...)100%11100%
ResolveBinding(...)83.33%6687.5%
GetXmlConfigEndpoint(...)50%2283.33%
AddServiceEndpoint(...)100%11100%
SetBindingNamespace(...)100%44100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.ConfigurationManager/src/CoreWCF/Configuration/ConfigurationHolder.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 CoreWCF.Channels;
 7
 8namespace CoreWCF.Configuration
 9{
 10    internal class ConfigurationHolder : IConfigurationHolder
 11    {
 4012        private readonly IDictionary<string, Binding> _bindings = new Dictionary<string, Binding>();
 4013        private readonly ISet<ServiceEndpoint> _endpoints = new HashSet<ServiceEndpoint>();
 14        private readonly IServiceProvider _provider;
 15        private readonly IBindingFactory _factoryBinding;
 16
 5117        public ISet<ServiceEndpoint> Endpoints => _endpoints;
 18
 4019        public ConfigurationHolder(IServiceProvider serviceProvider, IBindingFactory factory)
 20        {
 4021            _provider = serviceProvider;
 4022            _factoryBinding = factory;
 4023        }
 24
 25        public void AddBinding(Binding binding)
 26        {
 3727            _bindings.Add(binding.Name, binding);
 3728        }
 29
 30        public Binding ResolveBinding(string bindingType, string name, string bindingNamespace = null)
 31        {
 5532            if (string.IsNullOrEmpty(bindingType))
 33            {
 034                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(bindingType);
 35            }
 36
 37            Binding binding;
 5538            if (string.IsNullOrEmpty(name))
 39            {
 640                binding = _factoryBinding.Create(bindingType);
 41            }
 4942            else if (!_bindings.TryGetValue(name, out binding))
 43            {
 144                throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new BindingNotFoundException());
 45            }
 46
 5447            SetBindingNamespace(bindingNamespace, binding);
 48
 5449            return binding;
 50
 51        }
 52
 53        public IXmlConfigEndpoint GetXmlConfigEndpoint(ServiceEndpoint endpoint)
 54        {
 2255            if (endpoint == null)
 56            {
 057                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(endpoint));
 58            }
 59
 2260            Type contract = ServiceReflector.ResolveTypeFromName(endpoint.Contract);
 2261            Type service = ServiceReflector.ResolveTypeFromName(endpoint.ServiceName);
 2262            Binding binding = ResolveBinding(endpoint.Binding, endpoint.BindingConfiguration, endpoint.BindingNamespace)
 2263            return new XmlConfigEndpoint(service, contract, binding, endpoint.Address);
 64        }
 65
 66        public void AddServiceEndpoint(string name, string serviceName, Uri address, string contract, string bindingType
 67        {
 1368            var endpoint = new ServiceEndpoint
 1369            {
 1370                ServiceName = serviceName,
 1371                Address = address,
 1372                Binding = bindingType,
 1373                Contract = contract,
 1374                Name = name,
 1375                BindingConfiguration = bindingName,
 1376                BindingNamespace = bindingNamespace
 1377            };
 78
 1379            _endpoints.Add(endpoint);
 1380        }
 81
 82        private static void SetBindingNamespace(string bindingNamespace, Binding binding)
 83        {
 5484            if (binding != null && bindingNamespace != null)
 85            {
 2386                binding.Namespace = bindingNamespace;
 87            }
 5488        }
 89    }
 90}