< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.UriSchemeKeyedCollection
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/UriSchemeKeyedCollection.cs
Line coverage
58%
Covered lines: 18
Uncovered lines: 13
Coverable lines: 31
Total lines: 86
Line coverage: 58%
Branch coverage
45%
Covered branches: 9
Total branches: 20
Branch coverage: 45%
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(...)75%4483.33%
GetKeyForItem(...)100%11100%
InsertItem(...)50%2280%
SetItem(...)0%440%
ValidateBaseAddress(...)50%101054.54%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/UriSchemeKeyedCollection.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 CoreWCF.Collections.Generic;
 6
 7namespace CoreWCF
 8{
 9    public class UriSchemeKeyedCollection : SynchronizedKeyedCollection<string, Uri>
 10    {
 11        internal UriSchemeKeyedCollection(object syncRoot)
 59112            : base(syncRoot)
 13        {
 59114        }
 15
 58716        public UriSchemeKeyedCollection(params Uri[] addresses)
 17        {
 58718            if (addresses == null)
 19            {
 020                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(addresses));
 21            }
 22
 135423            for (int i = 0; i < addresses.Length; i++)
 24            {
 9025                Add(addresses[i]);
 26            }
 58727        }
 28
 29        protected override string GetKeyForItem(Uri item)
 30        {
 77731            return item.Scheme + ":" + item.Port;
 32        }
 33
 34        protected override void InsertItem(int index, Uri item)
 35        {
 69136            ValidateBaseAddress(item, "item");
 69137            if (Contains(item.Scheme))
 38            {
 039                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(item), SR.Format(SR.BaseAddressDupli
 40            }
 41
 69142            base.InsertItem(index, item);
 69143        }
 44
 45        protected override void SetItem(int index, Uri item)
 46        {
 047            ValidateBaseAddress(item, "item");
 048            if (this[index].Scheme != item.Scheme)
 49            {
 050                if (Contains(item.Scheme))
 51                {
 052                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(item), SR.Format(SR.BaseAddressD
 53                }
 54            }
 055            base.SetItem(index, item);
 056        }
 57
 58        internal static void ValidateBaseAddress(Uri uri, string argumentName)
 59        {
 69160            if (uri == null)
 61            {
 062                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(argumentName);
 63            }
 64
 69165            if (!uri.IsAbsoluteUri)
 66            {
 067                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(argumentName, SR.BaseAddressMustBeAbsolute)
 68            }
 69
 69170            if (!string.IsNullOrEmpty(uri.UserInfo))
 71            {
 072                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(argumentName, SR.BaseAddressCannotHaveUserI
 73            }
 74
 69175            if (!string.IsNullOrEmpty(uri.Query))
 76            {
 077                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(argumentName, SR.BaseAddressCannotHaveQuery
 78            }
 79
 69180            if (!string.IsNullOrEmpty(uri.Fragment))
 81            {
 082                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(argumentName, SR.BaseAddressCannotHaveFragm
 83            }
 69184        }
 85    }
 86}