< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Configuration.ServiceOptions
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Configuration/ServiceOptions.cs
Line coverage
100%
Covered lines: 3
Uncovered lines: 0
Coverable lines: 3
Total lines: 63
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Configuration/ServiceOptions.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.Description;
 7
 8namespace CoreWCF.Configuration
 9{
 10    public class ServiceOptions
 11    {
 115212        internal ServiceOptions() { }
 13
 116314        public ServiceDebugBehavior DebugBehavior { get; } = new ServiceDebugBehavior();
 15
 78416        public ICollection<Uri> BaseAddresses { get; } = new List<Uri>();
 17    }
 18
 19    internal class ServiceOptions<TService> : ServiceOptions where TService : class
 20    {
 21        private ServiceHostObjectModel<TService> _serviceHost;
 22        internal ServiceOptions(ServiceHostObjectModel<TService> serviceHost)
 23        {
 24            _serviceHost = serviceHost;
 25        }
 26
 27        internal void ApplyOptions(ServiceConfigurationDelegateHolder configDelegateHolder)
 28        {
 29            bool optionsDelegateProvided = configDelegateHolder.ApplyOptions(this);
 30            if (optionsDelegateProvided)
 31            {
 32                ApplyOptionsToServiceHost();
 33            }
 34            else
 35            {
 36                SetNoOptionsDelegateDefaults();
 37            }
 38        }
 39
 40        private void ApplyOptionsToServiceHost()
 41        {
 42            _serviceHost.Description.Behaviors.Remove<ServiceDebugBehavior>();
 43            _serviceHost.Description.Behaviors.Add(DebugBehavior);
 44            if (BaseAddresses.Count > 0)
 45            {
 46                _serviceHost.InternalBaseAddresses.Clear();
 47                foreach (Uri baseAddress in BaseAddresses)
 48                {
 49                    _serviceHost.InternalBaseAddresses.Add(baseAddress);
 50                }
 51            }
 52        }
 53
 54        private void SetNoOptionsDelegateDefaults()
 55        {
 56            // Enabling the debug page is a change in behavior which might take people by surprise
 57            // This code runs when not using the new options overload of AddService so only apps
 58            // which use the options overload will have the HttpHelpPageEnabled enabled by default.
 59            // That requires a code change so change is expected.
 60            DebugBehavior.HttpHelpPageEnabled = false;
 61        }
 62    }
 63}